about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-08-17 16:19:29 -0400
committerJune McEnroe <june@causal.agency>2020-08-17 16:21:34 -0400
commitebd44fb60618ce60fe269bfd3d1443db9cd8a362 (patch)
tree336aa0548fc86e428562da9e58cfba44d10442f0
parentUse a non-blocking lock on the PID file (diff)
downloadcatsit-ebd44fb60618ce60fe269bfd3d1443db9cd8a362.tar.gz
catsit-ebd44fb60618ce60fe269bfd3d1443db9cd8a362.zip
Use a separate fd for the fake fifo writer
From OpenBSD open(2):

> A FIFO should either be opened with O_RDONLY or with O_WRONLY.  The
> behavior for opening a FIFO with O_RDWR is undefined.
Diffstat (limited to '')
-rw-r--r--daemon.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/daemon.c b/daemon.c
index a1be594..785504f 100644
--- a/daemon.c
+++ b/daemon.c
@@ -265,13 +265,13 @@ int main(int argc, char *argv[]) {
 		warn("%s", fifoPath);
 	}
 
-	// XXX: Make sure there is always at least one writer open, otherwise we
-	// get EOF continually.
-	int fifo = open(fifoPath, O_RDWR | O_NONBLOCK | O_CLOEXEC);
-	if (fifo < 0) err(EX_CANTCREAT, "%s", fifoPath);
 	struct Line fifoLine = {0};
+	int fifo = open(fifoPath, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+	if (fifo < 0) err(EX_CANTCREAT, "%s", fifoPath);
 
-	openlog(getprogname(), LOG_NDELAY | LOG_PID | LOG_PERROR, LOG_DAEMON);
+	// XXX: Keep a writer open so the reader never gets EOF.
+	int writer = open(fifoPath, O_WRONLY | O_NONBLOCK | O_CLOEXEC);
+	if (writer < 0) err(EX_CANTCREAT, "%s", fifoPath);
 
 	error = parseConfig(configPath);
 	if (error) return EX_DATAERR;