From b078c89a9ee8e512b53560ff48cd041b25ac2cdf Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 17 Mar 2010 14:30:58 +0100 Subject: [PATCH] Capture SIGTERM in main prog and destroy filters --- src/metaproxy_prog.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index ef4f8f1..11b04b2 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if HAVE_UNISTD_H #include #endif +#include #ifdef WIN32 #include #include @@ -43,10 +44,22 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA namespace mp = metaproxy_1; -static void handler(void *data) +mp::RouterFleXML *routerp = 0; + +static void sig_term_handler(int s) { - mp::RouterFleXML *routerp = (mp::RouterFleXML*) data; + if (routerp) + { + delete routerp; + } + exit(0); +} +static void handler(void *data) +{ + routerp = (mp::RouterFleXML*) data; + + signal(SIGTERM, sig_term_handler); mp::Package pack; pack.router(*routerp).move(); } @@ -162,12 +175,13 @@ static int sc_main( wrbuf_write(base_path, fname, last_p - fname); mp::FactoryStatic factory; - mp::RouterFleXML router(doc, factory, false, wrbuf_cstr(base_path)); + mp::RouterFleXML *router = + new mp::RouterFleXML(doc, factory, false, wrbuf_cstr(base_path)); wrbuf_destroy(base_path); yaz_sc_running(s); - yaz_daemon("metaproxy", mode, handler, &router, pidfile, uid); + yaz_daemon("metaproxy", mode, handler, router, pidfile, uid); } catch (std::logic_error &e) { yaz_log (YLOG_FATAL,"std::logic error: %s" , e.what() ); -- 1.7.10.4