Open syslog, daemonize, write PID

This commit is contained in:
C. McEnroe 2020-08-14 13:08:06 -04:00
parent 3b38cfdbfe
commit 231dcefc55

View File

@ -20,11 +20,13 @@
#include <grp.h> #include <grp.h>
#include <pwd.h> #include <pwd.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sysexits.h> #include <sysexits.h>
#include <syslog.h>
#include <unistd.h> #include <unistd.h>
#include "daemon.h" #include "daemon.h"
@ -114,7 +116,19 @@ int main(int argc, char *argv[]) {
int fifo = open(fifoPath, O_RDONLY | O_NONBLOCK | O_CLOEXEC); int fifo = open(fifoPath, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (fifo < 0) err(EX_CANTCREAT, "%s", fifoPath); 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. // TODO: Main loop.