From 8201a0aedbe7a1cf3cbcd333ee0c8da57fab5c59 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 24 Nov 2009 22:32:13 +0000 Subject: Add debugging for child processes terminating normally or abnormally, as Brendon Baumgartner reported symptoms that sound like a bbstored child process crashing, and nothing in the logs indicates what happened to it. --- lib/server/ServerStream.h | 54 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'lib/server/ServerStream.h') diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h index 34de7def..e49dbcbe 100644 --- a/lib/server/ServerStream.h +++ b/lib/server/ServerStream.h @@ -302,16 +302,7 @@ public: // Clean up child processes (if forking daemon) if(ForkToHandleRequests && !IsSingleProcess()) { - int status = 0; - int p = 0; - do - { - if((p = ::waitpid(0 /* any child in process group */, &status, WNOHANG)) == -1 - && errno != ECHILD && errno != EINTR) - { - THROW_EXCEPTION(ServerException, ServerWaitOnChildError) - } - } while(p > 0); + WaitForChildren(); } #endif // !WIN32 } @@ -326,6 +317,49 @@ public: DeleteSockets(); } + #ifndef WIN32 // no waitpid() on Windows + void WaitForChildren() + { + int p = 0; + do + { + int status = 0; + p = ::waitpid(0 /* any child in process group */, + &status, WNOHANG); + + if(p == -1 && errno != ECHILD && errno != EINTR) + { + THROW_EXCEPTION(ServerException, + ServerWaitOnChildError) + } + else if(p == 0) + { + // no children exited, will return from + // function + } + else if(WIFEXITED(status)) + { + BOX_INFO("child process " << p << " " + "terminated normally"); + } + else if(WIFSIGNALED(status)) + { + int sig = WTERMSIG(status); + BOX_ERROR("child process " << p << " " + "terminated abnormally with " + "signal " << sig); + } + else + { + BOX_WARNING("something unknown happened " + "to child process " << p << ": " + "status = " << status); + } + } + while(p > 0); + } + #endif + virtual void HandleConnection(StreamType &rStream) { Connection(rStream); -- cgit v1.2.3