/* This file is part of Metaproxy.
- Copyright (C) 2005-2010 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
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
+#include <signal.h>
#ifdef WIN32
#include <direct.h>
#include <io.h>
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)
+{
+ kill(-process_group, SIGTERM); /* kill all children processes as well */
+ _exit(0);
+}
+#endif
+
+static void handler_debug(void *data)
{
- mp::RouterFleXML *routerp = (mp::RouterFleXML*) 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)
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':
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
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, 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() );