From 2bd5e698ae6fd85d6671cd9cad94abaa0cd5d92d Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Thu, 3 Feb 2022 22:10:26 +0100 Subject: detect closed pipes in logger_loop where POLLIN was set --- rvnit.c | 7 +++++++ 1 file changed, 7 insertions(+) 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 -- cgit 1.4.1