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

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