[Opensrf-commits] r1263 - trunk/src/libopensrf

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Mar 7 18:05:23 EST 2008


Author: erickson
Date: 2008-03-07 17:32:42 -0500 (Fri, 07 Mar 2008)
New Revision: 1263

Modified:
   trunk/src/libopensrf/osrf_system.c
Log:
added a basic signal handler for the top-level C process which sends SIGTERM to its children to clean up

Modified: trunk/src/libopensrf/osrf_system.c
===================================================================
--- trunk/src/libopensrf/osrf_system.c	2008-03-06 21:32:27 UTC (rev 1262)
+++ trunk/src/libopensrf/osrf_system.c	2008-03-07 22:32:42 UTC (rev 1263)
@@ -7,6 +7,19 @@
 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 @@
 	} // 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;



More information about the opensrf-commits mailing list