(wrong string) ée

From: <git_AT_suckless.org>
Date: Mon, 26 Sep 2016 10:57:59 +0200 (CEST)

commit e3dacbb542daeda7797855b01b3afbf7c433ad5f
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Sun Sep 25 12:24:17 2016 +0200
Commit: sin <sin_AT_2f30.org>
CommitDate: Mon Sep 26 09:57:54 2016 +0100

    respawn: reopen the fifo at end of line, and use read-only
    
    Signed-off-by: Mattias Andrée <maandree_AT_kth.se>

diff --git a/respawn.c b/respawn.c
index 77670f5..7fdd1ec 100644
--- a/respawn.c
+++ b/respawn.c
_AT_@ -1,5 +1,4 @@
 /* See LICENSE file for copyright and license details. */
-#include <sys/select.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
_AT_@ -7,6 +6,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <poll.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
_AT_@ -37,9 +37,9 @@ main(int argc, char *argv[])
         pid_t pid;
         char buf[BUFSIZ];
         int savederrno;
- int fd;
         ssize_t n;
- fd_set rdfd;
+ struct pollfd pollset[1];
+ int polln;
 
         ARGBEGIN {
         case 'd':
_AT_@ -63,26 +63,33 @@ main(int argc, char *argv[])
         signal(SIGTERM, sigterm);
 
         if (fifo) {
- /* TODO: we should use O_RDONLY and re-open the fd on EOF */
- fd = open(fifo, O_RDWR | O_NONBLOCK);
- if (fd < 0)
+ pollset->fd = open(fifo, O_RDONLY | O_NONBLOCK);
+ if (pollset->fd < 0)
                         eprintf("open %s:", fifo);
+ pollset->events = POLLIN;
         }
 
         while (1) {
                 if (fifo) {
- FD_ZERO(&rdfd);
- FD_SET(fd, &rdfd);
- n = select(fd + 1, &rdfd, NULL, NULL, NULL);
- if (n < 0)
- eprintf("select:");
- if (n == 0 || FD_ISSET(fd, &rdfd) == 0)
- continue;
- while ((n = read(fd, buf, sizeof(buf))) > 0)
+ pollset->revents = 0;
+ polln = poll(pollset, 1, -1);
+ if (polln <= 0) {
+ if (polln == 0 || errno == EAGAIN)
+ continue;
+ eprintf("poll:");
+ }
+ while ((n = read(pollset->fd, buf, sizeof(buf))) > 0)
                                 ;
                         if (n < 0)
                                 if (errno != EAGAIN)
                                         eprintf("read %s:", fifo);
+ if (n == 0) {
+ close(pollset->fd);
+ pollset->fd = open(fifo, O_RDONLY | O_NONBLOCK);
+ if (pollset->fd < 0)
+ eprintf("open %s:", fifo);
+ pollset->events = POLLIN;
+ }
                 }
                 pid = fork();
                 if (pid < 0)
Received on Mon Sep 26 2016 - 10:57:59 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 26 2016 - 11:00:15 CEST