]> mj.ucw.cz Git - arexx.git/blobdiff - arexxd.c
Support for systemd
[arexx.git] / arexxd.c
index 52cb17c71401e5cff4332e328790b54737a102a0..462b664c4812541268e194cbd253be19c113fa9e 100644 (file)
--- a/arexxd.c
+++ b/arexxd.c
@@ -45,6 +45,7 @@ static int debug_packets;
 static int debug_raw_data;
 static int debug_usb;
 static char *log_dir = DEFAULT_LOG_DIR;
+static int no_fork;
 
 static void die(char *fmt, ...)
 {
@@ -604,6 +605,7 @@ static void interruptible_msleep(int ms)
 static const struct option long_options[] = {
        { "debug",              0, NULL, 'd' },
        { "log-dir",            1, NULL, 'l' },
+       { "no-fork",            0, NULL, 'n' },
        { "debug-packets",      0, NULL, 'p' },
        { "debug-raw",          0, NULL, 'r' },
        { "version",            0, NULL, 'V' },
@@ -618,6 +620,7 @@ Usage: arexxd <options>\n\
 Options:\n\
 -d, --debug            Debug mode (no chdir, no fork, no syslog)\n\
 -l, --log-dir=<dir>    Directory where all received data should be stored\n\
+-n, --no-fork          Do not fork\n\
 -p, --debug-packets    Log all packets sent and received\n\
 -r, --debug-raw                Log conversion from raw values\n\
 -u, --debug-usb                Enable libusb debug messages (to stdout/stderr)\n\
@@ -629,7 +632,7 @@ Options:\n\
 int main(int argc, char **argv)
 {
        int opt;
-       while ((opt = getopt_long(argc, argv, "dl:pruV", long_options, NULL)) >= 0)
+       while ((opt = getopt_long(argc, argv, "dl:npruV", long_options, NULL)) >= 0)
                switch (opt) {
                        case 'd':
                                debug_mode++;
@@ -637,6 +640,9 @@ int main(int argc, char **argv)
                        case 'l':
                                log_dir = optarg;
                                break;
+                       case 'n':
+                               no_fork++;
+                               break;
                        case 'p':
                                debug_packets++;
                                break;
@@ -672,11 +678,13 @@ int main(int argc, char **argv)
                        setlinebuf(stdout);
                }
                openlog("arexxd", LOG_NDELAY, LOG_DAEMON);
-               pid_t pid = fork();
-               if (pid < 0)
-                       die("fork() failed: %m");
-               if (pid)
-                       return 0;
+               if (!no_fork) {
+                       pid_t pid = fork();
+                       if (pid < 0)
+                               die("fork() failed: %m");
+                       if (pid)
+                               return 0;
+               }
                setsid();
                use_syslog = 1;
        }