12 #pragma implementation
17 // Default constructor
20 SystemcallsSingletoncontroller::SystemcallsSingletoncontroller()
28 // destroy structs for leaving program
29 // open question: should we stop childs here?
30 // Asger says no: I like to have my xdvi open after closing LyX. Maybe
31 // I want to print or something.
33 SystemcallsSingletoncontroller::~SystemcallsSingletoncontroller()
35 ControlledCalls *next;
38 next = sysCalls->next;
46 // Add child process information into controlled list
50 SystemcallsSingletoncontroller::addCall(Systemcalls const &newcall) {
51 ControlledCalls * newCall = new ControlledCalls;
52 if (newCall == 0) // sorry, no idea
54 newCall->next = sysCalls;
55 newCall->call = new Systemcalls(newcall);
62 // Check list, if there is a stopped child. If yes, call-back.
66 SystemcallsSingletoncontroller::timer() {
67 // check each entry of our list, if it's finished
68 ControlledCalls *prev = 0;
69 for (ControlledCalls *actCall=sysCalls; actCall; actCall=actCall->next)
71 pid_t pid=actCall->call->getpid();
73 int waitrpid = waitpid(pid, &stat_loc, WNOHANG);
75 lyxerr << "LyX: Error waiting for child:"
76 << strerror(errno) << endl;
77 } else if (WIFEXITED(stat_loc) || WIFSIGNALED(stat_loc)) {
78 if (WIFEXITED(stat_loc)) {
79 // Ok, the return value goes into retval.
80 actCall->call->setRetValue(WEXITSTATUS(stat_loc));
82 // Child died, so pretend it returned 1
83 actCall->call->setRetValue(1);
85 // Callback and release
86 actCall->call->callback();
87 if (actCall == sysCalls) {
88 sysCalls = actCall->next;
90 prev->next = actCall->next;
94 } else if (WIFSTOPPED(stat_loc)) {
95 lyxerr << "LyX: Child (pid: " << pid
96 << ") stopped on signal "
98 << ". Waiting for child to finish." << endl;
100 lyxerr << "LyX: Something rotten happened while "
101 "waiting for child " << pid << endl;