bmh10 / rpms / openssh

Forked from rpms/openssh 2 days ago
Clone

Blame SOURCES/openssh-6.6p1-ControlPersist-stderr.patch

f8987c
From d2d6bf864e52af8491a60dd507f85b74361f5da3 Mon Sep 17 00:00:00 2001
f8987c
From: "djm@openbsd.org" <djm@openbsd.org>
f8987c
Date: Fri, 29 Apr 2016 08:07:53 +0000
f8987c
Subject: [PATCH] upstream commit
f8987c
f8987c
close ControlPersist background process stderr when not
f8987c
 in debug mode or when logging to a file or syslog. bz#1988 ok dtucker
f8987c
f8987c
Upstream-ID: 4fb726f0fdcb155ad419913cea10dc4afd409d24
f8987c
---
f8987c
 log.c | 4 ++--
f8987c
 ssh.c | 8 +++++---
f8987c
 2 files changed, 7 insertions(+), 5 deletions(-)
f8987c
f8987c
diff --git a/log.c b/log.c
f8987c
index ad12930..277afda 100644
f8987c
--- a/log.c
f8987c
+++ b/log.c
f8987c
@@ -342,7 +342,7 @@ log_change_level(LogLevel new_log_level)
f8987c
 int
f8987c
 log_is_on_stderr(void)
f8987c
 {
f8987c
-	return log_on_stderr;
f8987c
+	return log_on_stderr && log_stderr_fd == STDERR_FILENO;
f8987c
 }
f8987c
 
f8987c
 /* redirect what would usually get written to stderr to specified file */
f8987c
diff --git a/ssh.c b/ssh.c
f8987c
index a999d50..a881ba1 100644
f8987c
--- a/ssh.c
f8987c
+++ b/ssh.c
f8987c
@@ -1395,7 +1395,7 @@ static void
f8987c
 control_persist_detach(void)
f8987c
 {
f8987c
 	pid_t pid;
f8987c
-	int devnull;
f8987c
+	int devnull, keep_stderr;
f8987c
 
f8987c
 	debug("%s: backgrounding master process", __func__);
f8987c
 
f8987c
@@ -1426,8 +1426,10 @@ control_persist_detach(void)
f8987c
 		error("%s: open(\"/dev/null\"): %s", __func__,
f8987c
 		    strerror(errno));
f8987c
 	} else {
f8987c
+		keep_stderr = log_is_on_stderr() && debug_flag;
f8987c
 		if (dup2(devnull, STDIN_FILENO) == -1 ||
f8987c
-		    dup2(devnull, STDOUT_FILENO) == -1)
f8987c
+		    dup2(devnull, STDOUT_FILENO) == -1 ||
f8987c
+		    (!keep_stderr && dup2(devnull, STDERR_FILENO) == -1))
f8987c
 			error("%s: dup2: %s", __func__, strerror(errno));
f8987c
 		if (devnull > STDERR_FILENO)
f8987c
 			close(devnull);
f8987c