12 #pragma implementation
18 #ifndef CXX_GLOBAL_CSTD
23 // Default constructor
26 SystemcallsSingletoncontroller::SystemcallsSingletoncontroller()
34 // destroy structs for leaving program
35 // open question: should we stop childs here?
36 // Asger says no: I like to have my xdvi open after closing LyX. Maybe
37 // I want to print or something.
39 SystemcallsSingletoncontroller::~SystemcallsSingletoncontroller()
41 ControlledCalls *next;
44 next = sysCalls->next;
52 // Add child process information into controlled list
56 SystemcallsSingletoncontroller::addCall(Systemcalls const &newcall) {
57 ControlledCalls * newCall = new ControlledCalls;
58 if (newCall == 0) // sorry, no idea
60 newCall->next = sysCalls;
61 newCall->call = new Systemcalls(newcall);
68 // Check list, if there is a stopped child. If yes, call-back.
72 SystemcallsSingletoncontroller::timer() {
73 lyxerr << "Tick" << endl;
74 // check each entry of our list, if it's finished
75 ControlledCalls *prev = 0;
76 for (ControlledCalls *actCall= sysCalls; actCall; actCall= actCall->next)
78 pid_t pid= actCall->call->getpid();
80 int waitrpid = waitpid(pid, &stat_loc, WNOHANG);
82 lyxerr << "LyX: Error waiting for child:"
83 << strerror(errno) << endl;
84 } else if (WIFEXITED(stat_loc) || WIFSIGNALED(stat_loc)) {
85 if (WIFEXITED(stat_loc)) {
86 // Ok, the return value goes into retval.
87 actCall->call->setRetValue(WEXITSTATUS(stat_loc));
89 // Child died, so pretend it returned 1
90 actCall->call->setRetValue(1);
92 // Callback and release
93 actCall->call->callback();
94 if (actCall == sysCalls) {
95 sysCalls = actCall->next;
97 prev->next = actCall->next;
101 } else if (WIFSTOPPED(stat_loc)) {
102 lyxerr << "LyX: Child (pid: " << pid
103 << ") stopped on signal "
104 << WSTOPSIG(stat_loc)
105 << ". Waiting for child to finish." << endl;
107 lyxerr << "LyX: Something rotten happened while "
108 "waiting for child " << pid << endl;