From 231dcefc55bc041634c7ef7c9f077109144068c4 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 14 Aug 2020 13:08:06 -0400 Subject: Open syslog, daemonize, write PID --- daemon.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/daemon.c b/daemon.c index 0b07bb9..7030978 100644 --- a/daemon.c +++ b/daemon.c @@ -20,11 +20,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include "daemon.h" @@ -114,7 +116,19 @@ int main(int argc, char *argv[]) { int fifo = open(fifoPath, O_RDONLY | O_NONBLOCK | O_CLOEXEC); if (fifo < 0) err(EX_CANTCREAT, "%s", fifoPath); - // TODO: Daemonize, write pid file. + openlog("spawnd", LOG_NDELAY | LOG_PID | LOG_PERROR, LOG_DAEMON); + + if (daemonize) { + error = daemon(0, 0); + if (error) { + syslog(LOG_ERR, "daemon: %m"); + return EX_OSERR; + } + } + if (pidPath) { + int len = dprintf(pidFile, "%ju", (uintmax_t)getpid()); + if (len < 0) syslog(LOG_WARNING, "%s: %m", pidPath); + } // TODO: Main loop. -- cgit 1.4.1