X-Git-Url: https://git.evergreen-ils.org/?p=OpenSRF.git;a=blobdiff_plain;f=src%2Flibopensrf%2Fosrf_system.c;h=136558f9e9fdb3bb4ebe2b3b10e73cdff1a8aa08;hp=64379769c8990ce80adb0d4527662de4c44723b5;hb=21581ede2de0280ab8c1738d9edf4476824821a2;hpb=2e2f5ef8dc3ed3c43009c401ff1bbbc660964a6e diff --git a/src/libopensrf/osrf_system.c b/src/libopensrf/osrf_system.c index 6437976..136558f 100644 --- a/src/libopensrf/osrf_system.c +++ b/src/libopensrf/osrf_system.c @@ -7,6 +7,19 @@ static void report_child_status( pid_t pid, int status ); struct child_node; typedef struct child_node ChildNode; +static void handleKillSignal(int signo) { + /* we are the top-level process and we've been + * killed. Kill all of our children */ + kill(0, SIGTERM); + sleep(1); /* give the children a chance to die before we reap them */ + pid_t child_pid; + int status; + while( (child_pid=waitpid(-1,&status,WNOHANG)) > 0) + osrfLogInfo(OSRF_LOG_MARK, "Killed child %d", child_pid); + _exit(0); +} + + struct child_node { ChildNode* pNext; @@ -148,6 +161,9 @@ int osrfSystemBootstrap( char* hostname, char* configfile, char* contextNode ) { } // should we do something if there are no apps? does the wait(NULL) below do that for us? osrfStringArrayFree(arr); + + signal(SIGTERM, handleKillSignal); + signal(SIGINT, handleKillSignal); while(1) { errno = 0; @@ -377,6 +393,7 @@ int osrfSystemBootstrapClientResc( char* config_file, char* contextnode, char* r if (failure) { osrfStringArrayFree(arr); + free(log_file); free(log_level); free(username); free(password);