Beginnings of graceful stop
[metaproxy-moved-to-github.git] / src / metaproxy_prog.cpp
index 16512e7..ce60c60 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Metaproxy.
-   Copyright (C) 2005-2011 Index Data
+   Copyright (C) 2005-2012 Index Data
 
 Metaproxy is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <metaproxy/filter.hpp>
 #include <metaproxy/package.hpp>
+#include <metaproxy/util.hpp>
 #include "router_flexml.hpp"
 #include "factory_static.hpp"
 
@@ -51,8 +52,11 @@ static pid_t process_group = 0;
 
 static void sig_term_handler(int s)
 {
+    routerp->stop();
+#if 0
     kill(-process_group, SIGTERM); /* kill all children processes as well */
     _exit(0);
+#endif
 }
 #endif
 
@@ -68,6 +72,7 @@ static void handler_debug(void *data)
 
     mp::Package pack;
     pack.router(*routerp).move(); /* should never exit */
+    _exit(0);
 }
     
 static void handler_normal(void *data)
@@ -190,7 +195,7 @@ static int sc_main(
         yaz_log(YLOG_FATAL, "XInclude processing failed");
         return 1;
     }
-    WRBUF base_path = wrbuf_alloc();
+    mp::wrbuf base_path;
     const char *last_p = strrchr(fname,
 #ifdef WIN32
                                  '\\'
@@ -228,7 +233,6 @@ static int sc_main(
         yaz_log(YLOG_FATAL, "Unknown Exception");
         ret = 1;
     }
-    wrbuf_destroy(base_path);
     xmlFreeDoc(doc);
     return ret;
 }