X-Git-Url: https://git.evergreen-ils.org/?p=OpenSRF.git;a=blobdiff_plain;f=src%2Frouter%2Fosrf_router_main.c;h=5227d0c59be60f087710f533878868af10ba04fe;hp=0111e8bb04f7718814f83ade7ad62755d072990d;hb=61fe442042aa82b09202111fe3656cf464bbd2b9;hpb=c471145f680443a83e721bd6fbe79a178b090d4c diff --git a/src/router/osrf_router_main.c b/src/router/osrf_router_main.c index 0111e8b..5227d0c 100644 --- a/src/router/osrf_router_main.c +++ b/src/router/osrf_router_main.c @@ -28,27 +28,24 @@ */ static osrfRouter* router = NULL; +static sig_atomic_t stop_signal = 0; + +static void setupRouter(jsonObject* configChunk); + /** - @brief Respond to signal by cleaning up and exiting immediately. + @brief Respond to signal by setting a switch that will interrupt the main loop. @param signo The signal number. + + Signal handler. We not only interrupt the main loop but also remember the signal + number so that we can report it later and re-raise it. */ void routerSignalHandler( int signo ) { - osrfLogWarning( OSRF_LOG_MARK, "Received signal [%d], cleaning up...", signo ); - - osrfConfigCleanup(); - osrfRouterFree(router); - osrfLogWarning( OSRF_LOG_MARK, "Cleanup successful. Re-raising signal" ); - router = NULL; - - // Re-raise the signal so that the parent process can detect it. - signal( signo, SIG_DFL ); - raise( signo ); + signal( signo, routerSignalHandler ); + router_stop( router ); + stop_signal = signo; } -static void setupRouter(jsonObject* configChunk); - - /** @brief The top-level function of the router program. @param argc Number of items in command line. @@ -98,12 +95,12 @@ int main( int argc, char* argv[] ) { jsonObject* configChunk = jsonObjectGetIndex(configInfo, i); if( ! jsonObjectGetKey( configChunk, "transport" ) ) { - // In searching the configuration file for a given context, we may have found a spurious - // hit on an unrelated part of the configuration file that happened to use the same XML - // tag. In fact this happens routinely in practice. + // In searching the configuration file for a given context, we may have found a + // spurious hit on an unrelated part of the configuration file that happened to use + // the same XML tag. In fact this happens routinely in practice. - // If we don't see a member for "transport" then this is presumably such a spurious hit, - // so we silently ignore it. + // If we don't see a member for "transport" then this is presumably such a spurious + // hit, so we silently ignore it. // It is also possible that it's the right part of the configuration file but it has a // typo or other such error, making it look spurious. In that case, well, too bad. @@ -115,6 +112,13 @@ int main( int argc, char* argv[] ) { } } + if( stop_signal ) { + // Interrupted by a signal? Re raise so the parent can see it. + osrfLogWarning( OSRF_LOG_MARK, "Interrupted by signal %d; re-raising", + (int) stop_signal ); + raise( stop_signal ); + } + return EXIT_SUCCESS; } @@ -224,6 +228,8 @@ static void setupRouter(jsonObject* configChunk) { osrfRouterFree(router); router = NULL; + + osrfLogInfo( OSRF_LOG_MARK, "Router freed" ); return; }