Signal SIGUSR1 akes a graceful stop
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 17 Apr 2012 14:20:03 +0000 (16:20 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 17 Apr 2012 14:20:03 +0000 (16:20 +0200)
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

index ce60c60..7183419 100644 (file)
@@ -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) {