diff options
Diffstat (limited to 'lib/TaskMan.cc')
-rw-r--r-- | lib/TaskMan.cc | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc index 546bbc6..4d782a0 100644 --- a/lib/TaskMan.cc +++ b/lib/TaskMan.cc @@ -22,14 +22,30 @@ int TaskMan::number = 0; bool TaskMan::inited = false; static int got_sigchild = 0; -static vector<pid_t> process; -static int nbprocess = 0; void taskman_sigchild(int sig) { - got_sigchild = 1; - process.push_back(wait(0)); + int status; + pid_t pid; + + pid = wait(&status); + if (TaskMan::GotChild(pid, status)) { + got_sigchild = 1; + } signal(SIGCHLD, taskman_sigchild); - nbprocess++; +} + +int TaskMan::GotChild(pid_t pid, int status) { + int r = 0; + + for (vector<w4pr_t>::iterator p = w4pr.begin(); p && (p != w4pr.end()); p++) { + if (p->pr == pid) { + p->flag = true; + p->status = status; + r = 1; + } + } + + return r; } void TaskMan::Init() throw (GeneralException) { @@ -141,11 +157,7 @@ void TaskMan::MainLoop() throw (GeneralException) { TaskList.erase(p); number--; p--; - if (t->HasToClean()) { - delete t; - } else { - Zombies.push_back(t); - } + Zombies.push_back(t); } } } @@ -172,7 +184,7 @@ void TaskMan::MainLoop() throw (GeneralException) { q->events = 0; } else { cerr << "==== TaskMan: adding watch over handle \"" << p->ha->GetName() << "\" for task \"" << p->T->GetName() << "\"\n"; - if (p->ha->CanWatch() { + if (p->ha->CanWatch()) { q->fd = p->ha->GetHandle(); q->events = (p->flags & W4_READING ? POLLIN : 0) | (p->flags & W4_WRITING ? POLLOUT : 0); } else { @@ -203,7 +215,11 @@ void TaskMan::MainLoop() throw (GeneralException) { r = select(highest + 1, &readfds, &writefds, &exceptfds, NULL); #endif if (r == -1) { - throw GeneralException(String("Error during poll: ") + strerror(errno)); + if (errno == EINTR) { + // child + } else { + throw GeneralException(String("Error during poll: ") + strerror(errno)); + } } else if (r == 0) { // timeout... } else { @@ -252,17 +268,10 @@ void TaskMan::MainLoop() throw (GeneralException) { if (q) { TaskList.erase(q); number--; - if (p->T->HasToClean()) { - delete p->T; - } else { - Zombies.push_back(p->T); - } + Zombies.push_back(p->T); w4ha.erase(p); p--; erased = true; - } else { - // Hu-ho, something wrong... - throw GeneralException("TaskMan: internal error (task not found)"); } } @@ -303,12 +312,8 @@ void TaskMan::MainLoop() throw (GeneralException) { } TaskList.erase(f); number--; - if (o->HasToClean()) { - delete o; - } else { - Zombies.push_back(o); - no_zombies = 0; - } + Zombies.push_back(o); + no_zombies = 0; } } else { delete t; |