X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Fsyscontr.C;h=769d74f2286b47fcdbcf86fd4fce3b8ee2aa26fb;hb=6f8422af71ddb2c40aa7e8f186190dba77a7b228;hp=8c0bc960c9b17196193aded0335203322d732ca3;hpb=0eccdd1c3613e5170deb77b22174dd0afde833e9;p=lyx.git diff --git a/src/support/syscontr.C b/src/support/syscontr.C index 8c0bc960c9..769d74f228 100644 --- a/src/support/syscontr.C +++ b/src/support/syscontr.C @@ -1,62 +1,59 @@ #include -#include +#include +#include #include #include #include "syscontr.h" #include "syscall.h" +#include "debug.h" #ifdef __GNUG__ #pragma implementation #endif -//---------------------------------------------------------------------- -// Controller-Implementation -//---------------------------------------------------------------------- // -// default contstructor +// Default constructor // SystemcallsSingletoncontroller::SystemcallsSingletoncontroller() { - SysCalls = 0; + sysCalls = 0; } // -// destructor +// Destructor // // destroy structs for leaving program -// open question: should we stop here childs? +// open question: should we stop childs here? // Asger says no: I like to have my xdvi open after closing LyX. Maybe // I want to print or something. SystemcallsSingletoncontroller::~SystemcallsSingletoncontroller() { ControlledCalls *next; - while (SysCalls) + while (sysCalls) { - next = SysCalls->next; - delete SysCalls; - SysCalls = next; + next = sysCalls->next; + delete sysCalls; + sysCalls = next; } } // -// Add childprocessinformation into controlled list +// Add child process information into controlled list // void -SystemcallsSingletoncontroller::AddCall(Systemcalls const &newcall) -{ -// not yet implemented - ControlledCalls *newCall = new ControlledCalls; +SystemcallsSingletoncontroller::addCall(Systemcalls const &newcall) { + ControlledCalls * newCall = new ControlledCalls; if (newCall == 0) // sorry, no idea return; - newCall->next = SysCalls; + newCall->next = sysCalls; newCall->call = new Systemcalls(newcall); - SysCalls = newCall; + sysCalls = newCall; } // @@ -66,33 +63,43 @@ SystemcallsSingletoncontroller::AddCall(Systemcalls const &newcall) // void -SystemcallsSingletoncontroller::Timer() -{ +SystemcallsSingletoncontroller::timer() { // check each entry of our list, if it's finished ControlledCalls *prev = 0; - for (ControlledCalls *actCall=SysCalls; actCall; actCall=actCall->next) - { - pid_t pid=actCall->call->Getpid(); - int stat_loc; - waitpid(pid, &stat_loc, WNOHANG); - if (WIFEXITED(stat_loc) || WIFSIGNALED(stat_loc)) { + for (ControlledCalls *actCall= sysCalls; actCall; actCall= actCall->next) + { + pid_t pid= actCall->call->getpid(); + int stat_loc; + int waitrpid = waitpid(pid, &stat_loc, WNOHANG); + if (waitrpid == -1) { + lyxerr << "LyX: Error waiting for child:" + << strerror(errno) << endl; + } else if (WIFEXITED(stat_loc) || WIFSIGNALED(stat_loc)) { + if (WIFEXITED(stat_loc)) { // Ok, the return value goes into retval. - if (WIFEXITED(stat_loc)) { - actCall->call->setRetValue(WEXITSTATUS(stat_loc)); - } else { - // Child died, so pretend it returned 1 - actCall->call->setRetValue(1); - } - // callback and release - actCall->call->Callback(); - if (actCall == SysCalls) { - SysCalls = actCall->next; - } else { - prev->next = actCall->next; - } - delete actCall; - actCall = prev; + actCall->call->setRetValue(WEXITSTATUS(stat_loc)); + } else { + // Child died, so pretend it returned 1 + actCall->call->setRetValue(1); + } + // Callback and release + actCall->call->callback(); + if (actCall == sysCalls) { + sysCalls = actCall->next; + } else { + prev->next = actCall->next; } - prev = actCall; + delete actCall; + actCall = prev; + } else if (WIFSTOPPED(stat_loc)) { + lyxerr << "LyX: Child (pid: " << pid + << ") stopped on signal " + << WSTOPSIG(stat_loc) + << ". Waiting for child to finish." << endl; + } else { + lyxerr << "LyX: Something rotten happened while " + "waiting for child " << pid << endl; } + prev = actCall; + } }