12 #pragma implementation
19 // Default constructor
22 SystemcallsSingletoncontroller::SystemcallsSingletoncontroller()
30 // destroy structs for leaving program
31 // open question: should we stop childs here?
32 // Asger says no: I like to have my xdvi open after closing LyX. Maybe
33 // I want to print or something.
35 SystemcallsSingletoncontroller::~SystemcallsSingletoncontroller()
37 ControlledCalls *next;
40 next = sysCalls->next;
48 // Add child process information into controlled list
52 SystemcallsSingletoncontroller::addCall(Systemcalls const &newcall) {
53 ControlledCalls * newCall = new ControlledCalls;
54 if (newCall == 0) // sorry, no idea
56 newCall->next = sysCalls;
57 newCall->call = new Systemcalls(newcall);
64 // Check list, if there is a stopped child. If yes, call-back.
68 SystemcallsSingletoncontroller::timer() {
69 lyxerr << "Tick" << endl;
70 // check each entry of our list, if it's finished
71 ControlledCalls *prev = 0;
72 for (ControlledCalls *actCall= sysCalls; actCall; actCall= actCall->next)
74 pid_t pid= actCall->call->getpid();
76 int waitrpid = waitpid(pid, &stat_loc, WNOHANG);
78 lyxerr << "LyX: Error waiting for child:"
79 << strerror(errno) << endl;
80 } else if (WIFEXITED(stat_loc) || WIFSIGNALED(stat_loc)) {
81 if (WIFEXITED(stat_loc)) {
82 // Ok, the return value goes into retval.
83 actCall->call->setRetValue(WEXITSTATUS(stat_loc));
85 // Child died, so pretend it returned 1
86 actCall->call->setRetValue(1);
88 // Callback and release
89 actCall->call->callback();
90 if (actCall == sysCalls) {
91 sysCalls = actCall->next;
93 prev->next = actCall->next;
97 } else if (WIFSTOPPED(stat_loc)) {
98 lyxerr << "LyX: Child (pid: " << pid
99 << ") stopped on signal "
100 << WSTOPSIG(stat_loc)
101 << ". Waiting for child to finish." << endl;
103 lyxerr << "LyX: Something rotten happened while "
104 "waiting for child " << pid << endl;