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

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