- po::options_description desc("Allowed options");
- desc.add_options()
- ("help,h", "produce help message")
- ("version,V", "show version")
- ("config", po::value< std::vector<std::string> >(), "xml config")
- ;
-
- po::positional_options_description p;
- p.add("config", -1);
-
- po::variables_map vm;
- po::store(po::command_line_parser(argc, argv).
- options(desc).positional(p).run(), vm);
- po::notify(vm);
-
- if (vm.count("help")) {
- std::cout << desc << "\n";
- return 1;
- }
- if (vm.count("version")) {
- std::cout << "Metaproxy " VERSION "\n";
- return 0;
- }
- xmlDocPtr doc = 0;
- if (vm.count("config"))
+ routerp->stop(signo);
+ }
+}
+#endif
+
+static void work_common(void *data)
+{
+ set_log_prefix();
+#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::RouterXML*) data;
+ routerp->start();
+
+ mp::Package pack;
+ pack.router(*routerp).move();
+#if HAVE_UNISTD_H
+ switch (sig_received)
+ {
+ case SIGTERM:
+ yaz_log(YLOG_LOG, "metaproxy received SIGTERM");
+ break;
+ case SIGUSR1:
+ yaz_log(YLOG_LOG, "metaproxy received SIGUSR1");
+ break;
+ case 0:
+ break;
+ default:
+ yaz_log(YLOG_LOG, "metaproxy received signo=%d", sig_received);
+ }
+#endif
+ yaz_log(YLOG_LOG, "metaproxy stop");
+ delete routerp;
+ routerp = 0;
+#if HAVE_UNISTD_H
+ kill(-process_group, SIGTERM); /* kill all children processes as well */
+#endif
+ _exit(0);
+}
+
+static void work_debug(void *data)
+{
+ work_common(data);
+}
+
+static void work_normal(void *data)
+{
+#if HAVE_UNISTD_H
+ /* make the current working process group leader */
+ setpgid(0, 0);
+#endif
+ work_common(data);
+}
+
+static int sc_main(
+ yaz_sc_t s,
+ int argc, char **argv)
+{
+ bool test_config = false;
+ const char *fname = 0;
+ int ret;
+ char *arg;
+ unsigned mode = 0;
+ const char *pidfile = 0;
+ const char *uid = 0;
+
+ set_log_prefix();
+
+ while ((ret = options("c{config}:Dh{help}l:m:p:tu:v:V{version}w:X",
+ argv, argc, &arg)) != -2)
+ {
+ switch (ret)