From 15ea05a9ad38b8f63868845eff0ebb62c3d8b0a1 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 17 Apr 2012 16:20:03 +0200 Subject: [PATCH] Signal SIGUSR1 akes a graceful stop Thus, all Z39.50/HTTP connections to the server are kept alive, but the listening socket is closed. Signal SIGTERM destroys the server immediately as before. --- src/metaproxy_prog.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index ce60c60..7183419 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -50,22 +50,25 @@ mp::RouterFleXML *routerp = 0; #if HAVE_UNISTD_H static pid_t process_group = 0; -static void sig_term_handler(int s) +static void sig_usr1_handler(int s) { routerp->stop(); -#if 0 +} + +static void sig_term_handler(int s) +{ kill(-process_group, SIGTERM); /* kill all children processes as well */ _exit(0); -#endif } #endif -static void handler_debug(void *data) +static void work_common(void *data) { #if HAVE_UNISTD_H process_group = getpgid(0); // save process group ID signal(SIGTERM, sig_term_handler); + signal(SIGUSR1, sig_usr1_handler); #endif routerp = (mp::RouterFleXML*) data; routerp->start(); @@ -74,14 +77,19 @@ static void handler_debug(void *data) pack.router(*routerp).move(); /* should never exit */ _exit(0); } + +static void work_debug(void *data) +{ + work_common(data); +} -static void handler_normal(void *data) +static void work_normal(void *data) { #if HAVE_UNISTD_H /* make the current working process group leader */ setpgid(0, 0); #endif - handler_debug(data); + work_common(data); } static int sc_main( @@ -218,7 +226,7 @@ static int sc_main( yaz_sc_running(s); yaz_daemon("metaproxy", mode, mode == YAZ_DAEMON_DEBUG ? - handler_debug : handler_normal, router, pidfile, uid); + work_debug : work_normal, router, pidfile, uid); } } catch (std::logic_error &e) { -- 1.7.10.4