diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-02-03 22:10:26 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-02-03 22:10:26 +0100 |
commit | 2bd5e698ae6fd85d6671cd9cad94abaa0cd5d92d (patch) | |
tree | 7110d8ba04ac998c44837221ade7fe1e9b2fe4a6 | |
parent | 775d0e5de4b99dbcf6dbd243bfc6c0c4660b4b5b (diff) | |
download | rvnit-2bd5e698ae6fd85d6671cd9cad94abaa0cd5d92d.tar.gz rvnit-2bd5e698ae6fd85d6671cd9cad94abaa0cd5d92d.tar.xz rvnit-2bd5e698ae6fd85d6671cd9cad94abaa0cd5d92d.zip |
detect closed pipes in logger_loop where POLLIN was set
-rw-r--r-- | rvnit.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/rvnit.c b/rvnit.c index c7b9038..8c7b36b 100644 --- a/rvnit.c +++ b/rvnit.c @@ -452,6 +452,7 @@ logger_loop(void* ignored) if ((fds[j].revents & (POLLHUP | POLLERR)) && !(fds[j].revents & POLLIN)) { +closed_pipe: /* write end was closed, close whole pipe */ pthread_mutex_lock(&services_lock); for (int i = 0; i < MAX_SV; i++) { @@ -482,6 +483,12 @@ logger_loop(void* ignored) continue; } + if (rd == 0) { + // some OS set POLLIN|POLLHUP on closed pipes + // https://www.greenend.org.uk/rjk/tech/poll.html + goto closed_pipe; + } + if (rd < (int)sizeof buf && buf[rd - 1] != '\n') { // sometimes processes use multiple write calls // for one line, give them 25msec to do try to |