[Box Backup-commit] COMMIT r2587 - box/trunk/lib/server

subversion at boxbackup.org subversion
Tue Nov 24 22:32:14 GMT 2009


Author: chris
Date: 2009-11-24 22:32:13 +0000 (Tue, 24 Nov 2009)
New Revision: 2587

Modified:
   box/trunk/lib/server/ServerStream.h
Log:
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.


Modified: box/trunk/lib/server/ServerStream.h
===================================================================
--- box/trunk/lib/server/ServerStream.h	2009-11-11 19:24:27 UTC (rev 2586)
+++ box/trunk/lib/server/ServerStream.h	2009-11-24 22:32:13 UTC (rev 2587)
@@ -302,16 +302,7 @@
 				// 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 @@
 		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);




More information about the Boxbackup-commit mailing list