add option to prevent daemonization
[apps/pfixtools.git] / main-postlicyd.c
index f9b96f5..51f56ef 100644 (file)
@@ -252,6 +252,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 +265,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 +277,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 +301,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;
     }