Blame SOURCES/autofs-5.1.4-move-close-stdio-descriptors-to-become_daemon.patch

85ad07
autofs-5.1.4 - move close stdio descriptors to become_daemon()
85ad07
85ad07
From: Ian Kent <raven@themaw.net>
85ad07
85ad07
Move the stdio file descriptor close to the become_daemon() function
85ad07
as closing these file descriptors, ie. detaching from ttys, is part
85ad07
of the preperation for becoming a system daemon.
85ad07
85ad07
Signed-off-by: Ian Kent <raven@themaw.net>
85ad07
---
85ad07
 CHANGELOG          |    1 +
85ad07
 daemon/automount.c |   27 ++++++++++++++++++++++++++-
85ad07
 include/log.h      |    1 -
85ad07
 lib/log.c          |   30 ------------------------------
85ad07
 4 files changed, 27 insertions(+), 32 deletions(-)
85ad07
85ad07
--- autofs-5.0.7.orig/CHANGELOG
85ad07
+++ autofs-5.0.7/CHANGELOG
85ad07
@@ -314,6 +314,7 @@
85ad07
 - add NULL check in prepare_attempt_prefix().
85ad07
 - update build info with systemd.
85ad07
 - use flags for startup boolean options.
85ad07
+- move close stdio descriptors to become_daemon().
85ad07
 
85ad07
 25/07/2012 autofs-5.0.7
85ad07
 =======================
85ad07
--- autofs-5.0.7.orig/daemon/automount.c
85ad07
+++ autofs-5.0.7/daemon/automount.c
85ad07
@@ -1220,6 +1220,8 @@ static void become_daemon(unsigned int f
85ad07
 		}
85ad07
 		log_to_stderr();
85ad07
 	} else {
85ad07
+		int nullfd;
85ad07
+
85ad07
 		if (open_pipe(start_pipefd) < 0) {
85ad07
 			fprintf(stderr, "%s: failed to create start_pipefd.\n",
85ad07
 				program);
85ad07
@@ -1263,7 +1265,30 @@ static void become_daemon(unsigned int f
85ad07
 			close(start_pipefd[1]);
85ad07
 			exit(*pst_stat);
85ad07
 		}
85ad07
-		log_to_syslog();
85ad07
+
85ad07
+		/* Redirect all our file descriptors to /dev/null */
85ad07
+		nullfd = open("/dev/null", O_RDWR);
85ad07
+		if (nullfd < 0) {
85ad07
+			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
85ad07
+			fprintf(stderr, "cannot open /dev/null: %s", estr);
85ad07
+			res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
85ad07
+			close(start_pipefd[1]);
85ad07
+			exit(*pst_stat);
85ad07
+		}
85ad07
+
85ad07
+		if (dup2(nullfd, STDIN_FILENO) < 0 ||
85ad07
+		    dup2(nullfd, STDOUT_FILENO) < 0 ||
85ad07
+		    dup2(nullfd, STDERR_FILENO) < 0) {
85ad07
+			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
85ad07
+			fprintf(stderr,
85ad07
+				"redirecting file descriptors failed: %s", estr);
85ad07
+			res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
85ad07
+			close(start_pipefd[1]);
85ad07
+			exit(*pst_stat);
85ad07
+		}
85ad07
+
85ad07
+		open_log();
85ad07
+		close(nullfd);
85ad07
 	}
85ad07
 
85ad07
 	/* Write pid file if requested */
85ad07
--- autofs-5.0.7.orig/include/log.h
85ad07
+++ autofs-5.0.7/include/log.h
85ad07
@@ -36,7 +36,6 @@ extern void set_log_debug_ap(struct auto
85ad07
 extern void set_mnt_logging(unsigned global_logopt);
85ad07
 
85ad07
 extern void open_log(void);
85ad07
-extern void log_to_syslog(void);
85ad07
 extern void log_to_stderr(void);
85ad07
  
85ad07
 extern void log_info(unsigned int, const char* msg, ...);
85ad07
--- autofs-5.0.7.orig/lib/log.c
85ad07
+++ autofs-5.0.7/lib/log.c
85ad07
@@ -314,36 +314,6 @@ void open_log(void)
85ad07
 	return;
85ad07
 }
85ad07
 
85ad07
-void log_to_syslog(void)
85ad07
-{
85ad07
-	char buf[MAX_ERR_BUF];
85ad07
-	int nullfd;
85ad07
-
85ad07
-	open_log();
85ad07
-
85ad07
-	/* Redirect all our file descriptors to /dev/null */
85ad07
-	nullfd = open("/dev/null", O_RDWR);
85ad07
-	if (nullfd < 0) {
85ad07
-		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
85ad07
-		fprintf(stderr, "cannot open /dev/null: %s", estr);
85ad07
-		exit(1);
85ad07
-	}
85ad07
-
85ad07
-	if (dup2(nullfd, STDIN_FILENO) < 0 ||
85ad07
-	    dup2(nullfd, STDOUT_FILENO) < 0 ||
85ad07
-	    dup2(nullfd, STDERR_FILENO) < 0) {
85ad07
-		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
85ad07
-		fprintf(stderr,
85ad07
-			"redirecting file descriptors failed: %s", estr);
85ad07
-		exit(1);
85ad07
-	}
85ad07
-
85ad07
-	if (nullfd > 2)
85ad07
-		close(nullfd);
85ad07
-
85ad07
-	return;
85ad07
-}
85ad07
-
85ad07
 void log_to_stderr(void)
85ad07
 {
85ad07
 	if (syslog_open) {