From 9114ff00c92459958b2319d56ff0bd36c60e5ccb Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Fri, 28 Jan 2022 15:18:33 +0100 Subject: handle closed pipes in logger and close other end too --- rvnit.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/rvnit.c b/rvnit.c index f070ddd..345603b 100644 --- a/rvnit.c +++ b/rvnit.c @@ -399,7 +399,27 @@ logger_loop(void* ignored) } for (nfds_t j = 0; j < nfds; j++) { - // XXX HUP, NVAL + if (fds[j].revents & POLLNVAL) { + dprintf(2, "invalid fd %d\n", fds[j].revents); + continue; + } + + if ((fds[j].revents & (POLLHUP | POLLERR)) && + !(fds[j].revents & POLLIN)) { + /* write end was closed, close whole pipe */ + pthread_mutex_lock(&services_lock); + for (int i = 0; i < MAX_SV; i++) { + if (services[i].logfd[0] == fds[j].fd) { + close(services[i].logfd[0]); + services[i].logfd[0] = -1; + services[i].logfd[1] = -1; + services[i].logged = 0; + break; + } + } + pthread_mutex_unlock(&services_lock); + } + if (!(fds[j].revents & POLLIN)) continue; -- cgit 1.4.1