Skip to contentSkip to conversation

close open file descriptors in daemonize

PATCH New Jeff Moyer 1 participant 1 message Nov 9, 2006 Kernel automounter

lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 close open file descriptors in daemonize

Our daemonize function should really close open file descriptors that were leaked to us. This actually did result in a bug, whereby an "rpm -Uvh" from an ssh session would leave the user unable to logout.

It's a pretty simple patch. Comments welcome.

-Jeff

daemon/automount.c +5 -0
index 3c42c8a..c09eaf6 100644
@@ -1436,10 +1436,15 @@ static void become_daemon(void)
 	pid_t pid;
 	int nullfd;
 	int pfds[2];
+	int i;
 
 	/* Don't BUSY any directories unnecessarily */
 	chdir("/");
 
+	/* close open file descriptors, stdin/out/err are handled below */
+	for (i = 3; i < 255; i++)
+		close(i);
+
 	/* Detach from foreground process */
 	if (!submount) {
 		if (pipe(pfds) < 0) {