summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2009-11-24 22:32:13 +0000
committerChris Wilson <chris+github@qwirx.com>2009-11-24 22:32:13 +0000
commit8201a0aedbe7a1cf3cbcd333ee0c8da57fab5c59 (patch)
treecd0207b6d1b8defcca155370bdf7a8a9d5a1e545
parentd44b716362edc74aff3d2a0df222fbb9e40f47c1 (diff)
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.
-rw-r--r--lib/server/ServerStream.h54
1 files changed, 44 insertions, 10 deletions
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);