From db11d810fc9c3e55a555609756ef11c57374a889 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 28 Aug 2007 00:29:22 +0000 Subject: [PATCH] patch from Scott McKellar to examine and report the exit status of child processes as they shut down git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1087 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libopensrf/osrf_system.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/libopensrf/osrf_system.c b/src/libopensrf/osrf_system.c index e5596dd..f06c193 100644 --- a/src/libopensrf/osrf_system.c +++ b/src/libopensrf/osrf_system.c @@ -4,6 +4,7 @@ #include static int _osrfSystemInitCache( void ); +static void report_child_status( pid_t pid, int status ); static transport_client* osrfGlobalTransportClient = NULL; @@ -140,7 +141,8 @@ int osrfSystemBootstrap( char* hostname, char* configfile, char* contextNode ) { while(1) { errno = 0; - pid_t pid = wait(NULL); + int status; + pid_t pid = wait( &status ); if(-1 == pid) { if(errno == ECHILD) osrfLogError(OSRF_LOG_MARK, "We have no more live services... exiting"); @@ -148,13 +150,38 @@ int osrfSystemBootstrap( char* hostname, char* configfile, char* contextNode ) { osrfLogError(OSRF_LOG_MARK, "Exiting top-level system loop with error: %s", strerror(errno)); break; } else { - osrfLogError(OSRF_LOG_MARK, "We lost a top-level service process with PID %ld", pid); + report_child_status( pid, status ); } } return 0; } + +static void report_child_status( pid_t pid, int status ) { + + if( WIFEXITED( status ) ) + { + int rc = WEXITSTATUS( status ); // return code of child process + if( rc ) + osrfLogError( OSRF_LOG_MARK, "Child process %ld exited with return code %d", + (long) pid, rc ); + else + osrfLogError( OSRF_LOG_MARK, "Child process %ld exited normally", (long) pid ); + } + else if( WIFSIGNALED( status ) ) + { + osrfLogError( OSRF_LOG_MARK, "Child process %ld killed by signal %d", + (long) pid, WTERMSIG( status) ); + } + else if( WIFSTOPPED( status ) ) + { + osrfLogError( OSRF_LOG_MARK, "Child process %ld stopped by signal %d", + (long) pid, (int) WSTOPSIG( status ) ); + } +} + + int osrf_system_bootstrap_client_resc( char* config_file, char* contextnode, char* resource ) { int failure = 0; -- 2.11.0