diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-01-28 15:18:33 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-01-28 15:18:33 +0100 |
commit | 9114ff00c92459958b2319d56ff0bd36c60e5ccb (patch) | |
tree | 75a28c6611f15f33189379fdbddac5bb635fd4a4 | |
parent | d18c05f88e28762ae284b4a856cf03c3955eb6b7 (diff) | |
download | rvnit-9114ff00c92459958b2319d56ff0bd36c60e5ccb.tar.gz rvnit-9114ff00c92459958b2319d56ff0bd36c60e5ccb.tar.xz rvnit-9114ff00c92459958b2319d56ff0bd36c60e5ccb.zip |
handle closed pipes in logger and close other end too
-rw-r--r-- | rvnit.c | 22 |
1 files changed, 21 insertions, 1 deletions
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; |