From 0ad7756e85f8c841414beff0982871c50ba33ee0 Mon Sep 17 00:00:00 2001 From: silverleo Date: Wed, 20 May 2009 10:36:34 +0000 Subject: [PATCH] Revert rev1504 that introduced an error with modtcl. Tcl fork()s to create a child process, the child exits and tcl tries to get the child's exit code via waitpid() but when the child process exits, we get SIGCHLD, call waitpid() ourselves and thus the exit code (and the whole zombie) is discarded and tcl can't get the child's exit code. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1513 726aef4b-f618-498e-8847-2d620e286838 --- FileUtils.cpp | 7 ++++++- main.cpp | 8 -------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/FileUtils.cpp b/FileUtils.cpp index d9150223..ebfe18d3 100644 --- a/FileUtils.cpp +++ b/FileUtils.cpp @@ -556,6 +556,11 @@ int CExecSock::popen2(int & iReadFD, int & iWriteFD, const CString & sCommand) { void CExecSock::close2(int iPid, int iReadFD, int iWriteFD) { close(iReadFD); close(iWriteFD); - // If a zombie is left behind, SIGCHLD will handle it + u_int iNow = time(NULL); + while (waitpid(iPid, NULL, WNOHANG) == 0) { + if ((time(NULL) - iNow) > 5) + break; // giveup + usleep(100); + } return; } diff --git a/main.cpp b/main.cpp index 7ff172f9..e389a5b2 100644 --- a/main.cpp +++ b/main.cpp @@ -62,11 +62,6 @@ static void rehash(int sig) { CZNC::Get().SetNeedRehash(true); } -static void reapChilds(int sig) { - while (waitpid(-1, NULL, WNOHANG) > 0) { - } -} - static bool isRoot() { // User root? If one of these were root, we could switch the others to root, too if (geteuid() == 0 || getuid() == 0) @@ -248,9 +243,6 @@ int main(int argc, char** argv) { sa.sa_handler = rehash; sigaction(SIGHUP, &sa, (struct sigaction*) NULL); - sa.sa_handler = reapChilds; - sigaction(SIGCHLD, &sa, (struct sigaction*) NULL); - // Once this signal is caught, the signal handler is reset // to SIG_DFL. This avoids endless loop with signals. sa.sa_flags = SA_RESETHAND;