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.
This commit is contained in:
C. McEnroe 2020-08-17 16:19:29 -04:00
parent ea96ef48cb
commit ebd44fb606

View File

@ -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;