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 lyxerr << "Tick" << endl;
68 // check each entry of our list, if it's finished
69 ControlledCalls *prev = 0;
70 for (ControlledCalls *actCall= sysCalls; actCall; actCall= actCall->next)
72 pid_t pid= actCall->call->getpid();
74 int waitrpid = waitpid(pid, &stat_loc, WNOHANG);
76 lyxerr << "LyX: Error waiting for child:"
77 << strerror(errno) << endl;
78 } else if (WIFEXITED(stat_loc) || WIFSIGNALED(stat_loc)) {
79 if (WIFEXITED(stat_loc)) {
80 // Ok, the return value goes into retval.
81 actCall->call->setRetValue(WEXITSTATUS(stat_loc));
83 // Child died, so pretend it returned 1
84 actCall->call->setRetValue(1);
86 // Callback and release
87 actCall->call->callback();
88 if (actCall == sysCalls) {
89 sysCalls = actCall->next;
91 prev->next = actCall->next;
95 } else if (WIFSTOPPED(stat_loc)) {
96 lyxerr << "LyX: Child (pid: " << pid
97 << ") stopped on signal "
99 << ". Waiting for child to finish." << endl;
101 lyxerr << "LyX: Something rotten happened while "
102 "waiting for child " << pid << endl;