summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--daemon.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/daemon.c b/daemon.c
index 0b07bb9..7030978 100644
--- a/daemon.c
+++ b/daemon.c
@@ -20,11 +20,13 @@
 #include <grp.h>
 #include <pwd.h>
 #include <stdbool.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sysexits.h>
+#include <syslog.h>
 #include <unistd.h>
 
 #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.
 	
ubject'>FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe Absolutely indiscriminately. 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe For some reason I haven't been able to figure out, trying to poll /dev/tty returns POLLNVAL (and this was using 100% CPU looping), but using stderr instead works fine. 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe