#include "BatchManager_Local.hxx"
#include "RunTimeException.hxx"
#include "Utils.hxx"
+#include "Log.hxx"
using namespace std;
pthread_mutex_lock(&_threads_mutex);
string state = iter->second.param[STATE];
if (state != FINISHED && state != FAILED) {
- UNDER_LOCK( cout << "Warning: Job " << iter->first <<
- " is not finished, it will now be canceled." << endl );
+ UNDER_LOCK( LOG("Warning: Job " << iter->first <<
+ " is not finished, it will now be canceled."));
pthread_cancel(iter->second.thread_id);
pthread_cond_wait(&_threadSyncCondition, &_threads_mutex);
}
pthread_cancel(_threads[id].thread_id);
pthread_cond_wait(&_threadSyncCondition, &_threads_mutex);
} else {
- cout << "Cannot delete job " << jobid.getReference() <<
- ". Job is already finished." << endl;
+ LOG("Cannot delete job " << jobid.getReference() << ". Job is already finished.");
}
}
pthread_mutex_unlock(&_threads_mutex);
istringstream iss(jobid.getReference());
iss >> id;
- UNDER_LOCK( cout << "BatchManager is sending HOLD command to the thread " << id << endl );
+ UNDER_LOCK( LOG("BatchManager is sending HOLD command to the thread " << id) );
// On introduit une commande dans la queue du thread
// @@@ --------> SECTION CRITIQUE <-------- @@@
istringstream iss(jobid.getReference());
iss >> id;
- UNDER_LOCK( cout << "BatchManager is sending RELEASE command to the thread " << id << endl );
+ UNDER_LOCK( LOG("BatchManager is sending RELEASE command to the thread " << id) );
// On introduit une commande dans la queue du thread
// @@@ --------> SECTION CRITIQUE <-------- @@@
tempOutputFile.flush();
tempOutputFile.close();
- cerr << "Batch script file generated is: " << tmpFileName << endl;
+ LOG("Batch script file generated is: " << tmpFileName);
Utils::chmod(tmpFileName.c_str(), 0x1ED);
int status = _bm._protocol.copyFile(tmpFileName, "", "",
// pscp does not preserve access permissions on files
string subCommand = string("chmod u+x ") + remotePath;
string command = _bm._protocol.getExecCommand(subCommand, _bm._hostname, _bm._username);
- cerr << command.c_str() << endl;
+ LOG(command);
status = system(command.c_str());
if (status) {
std::ostringstream oss;
#else
child = fork();
if (child < 0) { // erreur
- UNDER_LOCK( cerr << "Fork impossible (rc=" << child << ")" << endl );
+ UNDER_LOCK( LOG("Fork impossible (rc=" << child << ")") );
} else if (child > 0) { // pere
p_ta->pere(child);
// On invoque la fonction de nettoyage de la memoire
delete_on_exit(arg);
- UNDER_LOCK( cout << "Father is leaving" << endl );
+ UNDER_LOCK( LOG("Father is leaving") );
pthread_exit(NULL);
return NULL;
}
DWORD exitCode;
GetExitCodeProcess(child, &exitCode);
if (exitCode != STILL_ACTIVE) {
- UNDER_LOCK( cout << "Father sees his child is DONE: exit code = " << exitCode << endl );
+ UNDER_LOCK( LOG("Father sees his child is DONE: exit code = " << exitCode) );
break;
}
#else
int child_rc = 0;
pid_t child_wait_rc = waitpid(child, &child_rc, WNOHANG /* | WUNTRACED */);
if (child_wait_rc > 0) {
- UNDER_LOCK( cout << "Status is: " << WIFEXITED( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WEXITSTATUS( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WIFSIGNALED( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WTERMSIG( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WCOREDUMP( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WIFSTOPPED( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WSTOPSIG( child_rc) << endl);
+ UNDER_LOCK( LOG("Status is: " << WIFEXITED( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WEXITSTATUS( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WIFSIGNALED( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WTERMSIG( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WCOREDUMP( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WIFSTOPPED( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WSTOPSIG( child_rc)) );
#ifdef WIFCONTINUED
- UNDER_LOCK( cout << "Status is: " << WIFCONTINUED( child_rc) << endl); // not compilable on sarge
+ UNDER_LOCK( LOG("Status is: " << WIFCONTINUED( child_rc)) ); // not compilable on sarge
#endif
if (WIFSTOPPED(child_rc)) {
// NOTA : pour rentrer dans cette section, il faut que le flag WUNTRACED
_bm._threads[_id].param[STATE] = Batch::PAUSED;
pthread_mutex_unlock(&_bm._threads_mutex);
// @@@ --------> SECTION CRITIQUE <-------- @@@
- UNDER_LOCK( cout << "Father sees his child is STOPPED : " << child_wait_rc << endl );
+ UNDER_LOCK( LOG("Father sees his child is STOPPED : " << child_wait_rc) );
}
else {
// Le fils est termine, on sort de la boucle et du if englobant
- UNDER_LOCK( cout << "Father sees his child is DONE : " << child_wait_rc << " (child_rc=" << (WIFEXITED(child_rc) ? WEXITSTATUS(child_rc) : -1) << ")" << endl );
+ UNDER_LOCK( LOG("Father sees his child is DONE : " << child_wait_rc << " (child_rc=" << (WIFEXITED(child_rc) ? WEXITSTATUS(child_rc) : -1) << ")") );
break;
}
}
_bm._threads[_id].hasFailed = true;
pthread_mutex_unlock(&_bm._threads_mutex);
// @@@ --------> SECTION CRITIQUE <-------- @@@
- UNDER_LOCK( cout << "Father sees his child is DEAD : " << child_wait_rc << " (Reason : " << strerror(errno) << ")" << endl );
+ UNDER_LOCK( LOG("Father sees his child is DEAD : " << child_wait_rc << " (Reason : " << strerror(errno) << ")") );
break;
}
#endif
// << "maxwalltime = " << maxwalltime << endl
// << "int(maxwalltime * 1.1) = " << int(maxwalltime * 1.1) << endl;
if (child_elapsedtime_minutes > long((float)maxwalltime * 1.1) ) { // On se donne 10% de marge avant le KILL
- UNDER_LOCK( cout << "Father is sending KILL command to the thread " << _id << endl );
+ UNDER_LOCK( LOG("Father is sending KILL command to the thread " << _id) );
// On introduit une commande dans la queue du thread
// @@@ --------> SECTION CRITIQUE <-------- @@@
pthread_mutex_lock(&_bm._threads_mutex);
} else if (child_elapsedtime_minutes > maxwalltime ) {
- UNDER_LOCK( cout << "Father is sending TERM command to the thread " << _id << endl );
+ UNDER_LOCK( LOG("Father is sending TERM command to the thread " << _id) );
// On introduit une commande dans la queue du thread
// @@@ --------> SECTION CRITIQUE <-------- @@@
pthread_mutex_lock(&_bm._threads_mutex);
switch (cmd) {
case NOP:
- UNDER_LOCK( cout << "Father does nothing to his child" << endl );
+ UNDER_LOCK( LOG("Father does nothing to his child") );
break;
#ifndef WIN32
case HOLD:
- UNDER_LOCK( cout << "Father is sending SIGSTOP signal to his child" << endl );
+ UNDER_LOCK( LOG("Father is sending SIGSTOP signal to his child") );
kill(child, SIGSTOP);
break;
case RELEASE:
- UNDER_LOCK( cout << "Father is sending SIGCONT signal to his child" << endl );
+ UNDER_LOCK( LOG("Father is sending SIGCONT signal to his child") );
kill(child, SIGCONT);
break;
case TERM:
- UNDER_LOCK( cout << "Father is sending SIGTERM signal to his child" << endl );
+ UNDER_LOCK( LOG("Father is sending SIGTERM signal to his child") );
kill(child, SIGTERM);
break;
case KILL:
- UNDER_LOCK( cout << "Father is sending SIGKILL signal to his child" << endl );
+ UNDER_LOCK( LOG("Father is sending SIGKILL signal to his child") );
kill(child, SIGKILL);
break;
#endif
comstr += command[i] + " ";
}
argv[command.size()] = NULL;
- UNDER_LOCK( cout << "*** debug_command = " << comstr << endl );
+ UNDER_LOCK( LOG("*** debug_command = " << comstr) );
// On cree une session pour le fils de facon a ce qu'il ne soit pas
// detruit lorsque le shell se termine (le shell ouvre une session et
// On execute la commande du fils
execv(argv[0], argv);
- UNDER_LOCK( cout << "*** debug_command = " << strerror(errno) << endl );
+ UNDER_LOCK( LOG("*** debug_command = " << strerror(errno)) );
// No need to deallocate since nothing happens after a successful exec
// Normalement on ne devrait jamais arriver ici
} catch (GenericException & e) {
- std::cerr << "Caught exception : " << e.type << " : " << e.message << std::endl;
+ LOG("Caught exception : " << e.type << " : " << e.message);
}
exit(99);
comstr += command[i];
}
- UNDER_LOCK( cout << "*** debug_command = " << comstr << endl );
+ UNDER_LOCK( LOG("*** debug_command = " << comstr) );
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
} catch (GenericException & e) {
- std::cerr << "Caught exception : " << e.type << " : " << e.message << std::endl;
+ LOG("Caught exception : " << e.type << " : " << e.message);
}
return pi.hProcess;