Handle SIGCHLD for collecting zombie processes

The old code failed to collect the following command to *shell correctly:
 exec > /dev/null 2> /dev/null < /dev/null ; sleep 10

The timeout in CExecSock::close2() was over before the child processes exited
and a zombie was left behind. Plus we used some ugly busy looping while
waiting for the child to exit. Using SIGCHLD for collecting zombies is
soooooo much nicer.


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1504 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2009-05-04 19:21:26 +00:00
parent bbb62bed08
commit c0ee24f313
2 changed files with 10 additions and 6 deletions

View File

@@ -556,11 +556,6 @@ int CExecSock::popen2(int & iReadFD, int & iWriteFD, const CString & sCommand) {
void CExecSock::close2(int iPid, int iReadFD, int iWriteFD) {
close(iReadFD);
close(iWriteFD);
u_int iNow = time(NULL);
while (waitpid(iPid, NULL, WNOHANG) == 0) {
if ((time(NULL) - iNow) > 5)
break; // giveup
usleep(100);
}
// If a zombie is left behind, SIGCHLD will handle it
return;
}