Simplify sigint handler.
[apps/pfixtools.git] / main-postlicyd.c
index f9b96f5..ff5097f 100644 (file)
@@ -232,6 +232,7 @@ static int main_initialize(void)
     signal(SIGPIPE, SIG_IGN);
     signal(SIGINT,  &common_sighandler);
     signal(SIGTERM, &common_sighandler);
+    signal(SIGHUP,  &common_sighandler);
     signal(SIGSEGV, &common_sighandler);
     syslog(LOG_INFO, "Starting...");
     return 0;
@@ -252,6 +253,7 @@ void usage(void)
           "Options:\n"
           "    -l <port>    port to listen to\n"
           "    -p <pidfile> file to write our pid to\n"
+          "    -f           stay in foreground\n"
          , stderr);
 }
 
@@ -264,10 +266,11 @@ int main(int argc, char *argv[])
         .sin_addr   = { htonl(INADDR_LOOPBACK) },
     };
     const char *pidfile = NULL;
+    bool daemonize = true;
     int port = DEFAULT_PORT;
     int sock = -1;
 
-    for (int c = 0; (c = getopt(argc, argv, "h" "l:p:")) >= 0; ) {
+    for (int c = 0; (c = getopt(argc, argv, "hf" "l:p:")) >= 0; ) {
         switch (c) {
           case 'p':
             pidfile = optarg;
@@ -275,6 +278,9 @@ int main(int argc, char *argv[])
           case 'l':
             port = atoi(optarg);
             break;
+          case 'f':
+            daemonize = false;
+            break;
           default:
             usage();
             return EXIT_FAILURE;
@@ -296,7 +302,7 @@ int main(int argc, char *argv[])
         return EXIT_FAILURE;
     }
 
-    if (daemon_detach() < 0) {
+    if (daemonize && daemon_detach() < 0) {
         syslog(LOG_CRIT, "unable to fork");
         return EXIT_FAILURE;
     }