summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-01-28 15:18:33 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-01-28 15:18:33 +0100
commit9114ff00c92459958b2319d56ff0bd36c60e5ccb (patch)
tree75a28c6611f15f33189379fdbddac5bb635fd4a4
parentd18c05f88e28762ae284b4a856cf03c3955eb6b7 (diff)
downloadrvnit-9114ff00c92459958b2319d56ff0bd36c60e5ccb.tar.gz
rvnit-9114ff00c92459958b2319d56ff0bd36c60e5ccb.tar.xz
rvnit-9114ff00c92459958b2319d56ff0bd36c60e5ccb.zip
handle closed pipes in logger and close other end too
-rw-r--r--rvnit.c22
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;