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

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