summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-01-06 19:45:12 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-01-06 19:45:12 +0100
commitb60d6eecb30db5d8c6c5411677a4c0a70d138653 (patch)
treed02a695ed8d27c82d94a53fb6ce845c4c635d4d9
parent1da9e52fe56f0ee34a4ee9eb0f981a87e8e1c984 (diff)
downloadrvnit-b60d6eecb30db5d8c6c5411677a4c0a70d138653.tar.gz
rvnit-b60d6eecb30db5d8c6c5411677a4c0a70d138653.tar.xz
rvnit-b60d6eecb30db5d8c6c5411677a4c0a70d138653.zip
use pipe to trigger logger rescan
-rw-r--r--rvnit.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/rvnit.c b/rvnit.c
index 74af39b..0626ce3 100644
--- a/rvnit.c
+++ b/rvnit.c
@@ -49,6 +49,7 @@ pthread_t socket_thread;
 pthread_t logger_thread;
 
 int selflogfd[2];
+int newlogfd[2];
 
 sig_atomic_t want_shutdown;
 sig_atomic_t want_rescan;
@@ -63,12 +64,6 @@ on_sigint(int sig)
 }
 
 void
-on_sigusr2(int sig)
-{
-	(void)sig;
-}
-
-void
 on_sigcont(int sig)
 {
 	(void)sig;
@@ -95,7 +90,7 @@ restart(int i)
 		fcntl(services[i].logfd[0], F_SETFL, O_NONBLOCK);
 		fcntl(services[i].logfd[1], F_SETFL, O_NONBLOCK);
 
-		pthread_kill(logger_thread, SIGUSR2);
+		write(newlogfd[1], "!", 1);
 	}
 
 	if (services[i].name[2] == 'L') {
@@ -292,12 +287,16 @@ logger_loop(void* ignored)
 		struct pollfd fds[MAX_SV];
 		nfds_t nfds = 0;
 
+		fds[nfds].fd = newlogfd[0];
+		fds[nfds].events = POLLIN;
+		nfds++;
+
 		fds[nfds].fd = selflogfd[0];
 		fds[nfds].events = POLLIN;
 		nfds++;
 
 		for (int i = 0; i < MAX_SV; i++) {
-			if (/*services[i].pid > 0 && */ !services[i].logged && services[i].logfd[0] > 0) {
+			if (!services[i].logged && services[i].logfd[0] > 0) {
 				fds[nfds].fd = services[i].logfd[0];
 				fds[nfds].events = POLLIN;
 				nfds++;
@@ -305,11 +304,21 @@ logger_loop(void* ignored)
 		}
 
 		int n = poll(fds, nfds, -1);
-		if (n < 0)
+		if (n < 0) {
+			perror("poll");
+			sleep(1);
+			continue;
+		}
+
+		if (fds[0].revents & POLLIN) {
+			/* data on newlogfd, restart */
+			char c;
+			read(fds[0].fd, &c, 1);
 			continue;
+		}
 
-		if (n == 1 && (fds[0].revents & POLLHUP) &&
-		    !(fds[0].revents & POLLIN)) {
+		if (n == 1 && (fds[1].revents & POLLHUP) &&
+		    !(fds[1].revents & POLLIN)) {
 			/* selflog was closed, end thread */
 			break;
 		}
@@ -469,7 +478,11 @@ main()
 	fcntl(selflogfd[0], F_SETFD, FD_CLOEXEC);
 	fcntl(selflogfd[1], F_SETFD, FD_CLOEXEC);
 
-	sigaction(SIGUSR2, &(struct sigaction){.sa_handler=on_sigusr2}, 0);
+	pipe(newlogfd);
+	fcntl(newlogfd[0], F_SETFL, O_NONBLOCK);
+	fcntl(newlogfd[1], F_SETFL, O_NONBLOCK);
+	fcntl(newlogfd[0], F_SETFD, FD_CLOEXEC);
+	fcntl(newlogfd[1], F_SETFD, FD_CLOEXEC);
 
 	main_thread = pthread_self();
 	pthread_create(&socket_thread, 0, socket_loop, 0);