From ebd44fb60618ce60fe269bfd3d1443db9cd8a362 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 17 Aug 2020 16:19:29 -0400 Subject: [PATCH] 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. --- daemon.c | 10 +++++----- 1 file 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;