summary refs log tree commit diff
diff options
context:
space:
mode:
-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;