summary refs log tree commit diff
path: root/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--daemon.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/daemon.c b/daemon.c
index 9eb8bb4..42ea78f 100644
--- a/daemon.c
+++ b/daemon.c
@@ -209,8 +209,11 @@ int main(int argc, char *argv[]) {
 		warn("%s", fifoPath);
 	}
 
-	int fifo = open(fifoPath, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+	// 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};
 
 	openlog(getprogname(), LOG_NDELAY | LOG_PID | LOG_PERROR, LOG_DAEMON);
 
@@ -277,8 +280,19 @@ int main(int argc, char *argv[]) {
 			(timespecisset(&deadline) ? &timeout : NULL),
 			&mask
 		);
+		if (nfds < 0 && errno != EINTR) {
+			syslog(LOG_ERR, "ppoll: %m");
+			continue;
+		}
+
+		if (nfds > 0 && fds[0].revents) {
+			for (char *line; NULL != (line = lineRead(&fifoLine, fifo));) {
+				syslog(LOG_INFO, "control: %s", line);
+			}
+			if (errno != EAGAIN) syslog(LOG_ERR, "read: %m");
+		}
 
-		// TODO: Handle FIFO and pipes.
+		// TODO: Handle pipes.
 
 		if (timespecisset(&deadline)) {
 			clock_gettime(CLOCK_MONOTONIC, &now);