From: erickson Date: Fri, 7 Mar 2008 22:32:42 +0000 (+0000) Subject: added a basic signal handler for the top-level C process which sends SIGTERM to its... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6a34180fcecf6a8e56dc3c10772642645cb8649b;p=working%2FOpenSRF.git added a basic signal handler for the top-level C process which sends SIGTERM to its children to clean up git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1263 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/libopensrf/osrf_system.c b/src/libopensrf/osrf_system.c index 6437976..cd7553e 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;