Change suggested by Scott McKellar; handle c-app children death without a
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 29 May 2007 03:03:44 +0000 (03:03 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 29 May 2007 03:03:44 +0000 (03:03 +0000)
signal handler.

http://list.georgialibraries.org/pipermail/open-ils-dev/2007-May/000955.html

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@923 9efc2488-bf62-4759-914b-345cdb29e865

src/libstack/osrf_system.c

index bc5d148..a9f793e 100644 (file)
@@ -118,7 +118,7 @@ int osrfSystemBootstrap( char* hostname, char* configfile, char* contextNode ) {
                                        if( osrfAppRegisterApplication( appname, libfile ) == 0 ) 
                                                osrf_prefork_run(appname);
        
-                                       osrfLogDebug( OSRF_LOG_MARK, "Server exiting for app %s and library %s", appname, libfile );
+                                       osrfLogDebug( OSRF_LOG_MARK, "Server exiting for app %s and library %s\n", appname, libfile );
                                        exit(0);
                                }
                        } // language == c
@@ -130,10 +130,20 @@ int osrfSystemBootstrap( char* hostname, char* configfile, char* contextNode ) {
        /* background and let our children do their thing */
        daemonize();
        while(1) {
-               signal(SIGCHLD, osrfSystemSignalHandler);
-               sleep(10000);
+               errno = 0;
+               pid_t pid = wait( NULL );
+               if ( -1 == pid ) {
+                       if ( errno != ECHILD ) {
+                               char* err_str = strerror( errno );
+                               osrfLogWarning( OSRF_LOG_MARK, "Exiting on singal or error: %s\n", err_str );
+                               free(err_str);
+                       }
+                       break;
+               } else {
+                       osrfLogWarning( OSRF_LOG_MARK, "We lost child %d", pid);
+               }
        }
-       
+
        return 0;
 }