summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-01-27 21:21:21 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-01-27 21:21:21 +0100
commit1e69166d4a9c4cd63532a0349c333c9ecd7c4f3c (patch)
tree15521eef3cc5a4a4d03083fcf6aeb2135e10fa1c
parent27132b5b5a769d90d3e98289ef8d5e250c9bed56 (diff)
downloadrvnit-1e69166d4a9c4cd63532a0349c333c9ecd7c4f3c.tar.gz
rvnit-1e69166d4a9c4cd63532a0349c333c9ecd7c4f3c.tar.xz
rvnit-1e69166d4a9c4cd63532a0349c333c9ecd7c4f3c.zip
spawn daemons with closed stdin
This also prevents them from getting controlling tty.
-rw-r--r--rvnit.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/rvnit.c b/rvnit.c
index a372add..274eeda 100644
--- a/rvnit.c
+++ b/rvnit.c
@@ -61,6 +61,7 @@ pthread_t logger_thread;
 int selflogfd[2];
 int newlogfd[2];
 int globallogfd[2];
+int nullfd;
 
 int pid1;
 int real_pid1;
@@ -151,6 +152,10 @@ restart(int i)
 			// loggers get read end of loggerpipe
 			dup2(loggerpipe[0], 0);
 		}
+		if (services[i].name[2] == 'D') {
+			// daemons get /dev/null as stdin
+			dup2(nullfd, 0);
+		}
 		if (services[i].name[2] == 'G') {
 			// global loggers get read end of global log pipe
 			dup2(globallogfd[0], 0);
@@ -701,6 +706,17 @@ main(int argc, char *argv[])
 #endif
 	}
 
+	nullfd = open("/dev/nullz", O_RDONLY | O_CLOEXEC);
+	if (nullfd < 0) {
+		perror("rvnit: open /dev/null");
+
+		// use a closed pipe instead
+		int fd[2];
+		pipe(fd);
+		nullfd = fd[0];
+		close(fd[1]);
+	}
+
 	if (pthread_mutex_init(&services_lock, 0) != 0) {
 		perror("rvnit: pthread_mutex_init");
 		return 111;