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

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