X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fmetaproxy_prog.cpp;h=2719870ab5609062d99101f703f0f527e642321b;hb=c1d953eee6c00432493bc364da6284704ccd9cc2;hp=4cba4248ff701d16d597848c15045f37a0de3716;hpb=dfea092810f0735486a91bdb42d47cc9e9c3bc5a;p=metaproxy-moved-to-github.git diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index 4cba424..2719870 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2009 Index Data + Copyright (C) 2005-2011 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 @@ -27,14 +27,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#include "filter.hpp" -#include "package.hpp" +#include +#include #include "router_flexml.hpp" #include "factory_static.hpp" #if HAVE_UNISTD_H #include #endif +#include #ifdef WIN32 #include #include @@ -43,14 +44,41 @@ 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; + +#if HAVE_UNISTD_H +static pid_t process_group = 0; + +static void sig_term_handler(int s) { - mp::RouterFleXML *routerp = (mp::RouterFleXML*) data; + kill(-process_group, SIGTERM); /* kill all children processes as well */ + _exit(0); +} +#endif + +static void handler_debug(void *data) +{ +#if HAVE_UNISTD_H + process_group = getpgid(0); // save process group ID + + signal(SIGTERM, sig_term_handler); +#endif + routerp = (mp::RouterFleXML*) data; + routerp->start(); mp::Package pack; - pack.router(*routerp).move(); + pack.router(*routerp).move(); /* should never exit */ } +static void handler_normal(void *data) +{ +#if HAVE_UNISTD_H + /* make the current working process group leader */ + setpgid(0, 0); +#endif + handler_debug(data); +} + static int sc_main( yaz_sc_t s, int argc, char **argv) @@ -103,7 +131,11 @@ static int sc_main( uid = arg; break; case 'V': - std::cout << VERSION "\n"; + std::cout << VERSION; +#ifdef VERSION_SHA1 + std::cout << " " VERSION_SHA1; +#endif + std::cout << "\n"; return 0; break; case 'w': @@ -132,7 +164,12 @@ static int sc_main( return 1; } - yaz_log(YLOG_LOG, "Metaproxy " VERSION " started"); + yaz_log(YLOG_LOG, "Metaproxy start " VERSION +#ifdef VERSION_SHA1 + " " VERSION_SHA1 +#endif + ); + xmlDocPtr doc = xmlReadFile(fname, NULL, XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS @@ -150,12 +187,26 @@ static int sc_main( yaz_log(YLOG_FATAL, "XInclude processing failed"); return 1; } + WRBUF base_path = wrbuf_alloc(); + const char *last_p = strrchr(fname, +#ifdef WIN32 + '\\' +#else + '/' +#endif + ); + if (last_p) + wrbuf_write(base_path, fname, last_p - fname); + mp::FactoryStatic factory; - mp::RouterFleXML router(doc, factory, false); + 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, mode == YAZ_DAEMON_DEBUG ? + handler_debug : handler_normal, router, pidfile, uid); } catch (std::logic_error &e) { yaz_log (YLOG_FATAL,"std::logic error: %s" , e.what() );