From b8c59a1c8bb1352daacf03674a08bfa294edbbca Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 31 Jan 2016 09:49:21 +0100 Subject: [PATCH] Support for systemd --- arexxd.c | 20 ++++++++++++++------ arexxd.service | 13 +++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 arexxd.service diff --git a/arexxd.c b/arexxd.c index 52cb17c..462b664 100644 --- 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 \n\ Options:\n\ -d, --debug Debug mode (no chdir, no fork, no syslog)\n\ -l, --log-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; } diff --git a/arexxd.service b/arexxd.service new file mode 100644 index 0000000..e83cc62 --- /dev/null +++ b/arexxd.service @@ -0,0 +1,13 @@ +[Unit] +Description=Arexx data logger daemon +After=network.target + +[Service] +Type=simple +ExecStart=/usr/local/sbin/arexxd --no-fork +User=arexxd +Group=arexxd +KillMode=process + +[Install] +WantedBy=multi-user.target -- 2.39.5