summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--log.c2
-rw-r--r--ssh.c6
2 files changed, 5 insertions, 3 deletions
diff --git a/log.c b/log.c
index e68b84a20..6c596414b 100644
--- a/log.c
+++ b/log.c
@@ -343,7 +343,7 @@ log_change_level(LogLevel new_log_level)
343int 343int
344log_is_on_stderr(void) 344log_is_on_stderr(void)
345{ 345{
346 return log_on_stderr; 346 return log_on_stderr && log_stderr_fd == STDERR_FILENO;
347} 347}
348 348
349/* redirect what would usually get written to stderr to specified file */ 349/* redirect what would usually get written to stderr to specified file */
diff --git a/ssh.c b/ssh.c
index 314dd528d..af39e724f 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1392,7 +1392,7 @@ static void
1392control_persist_detach(void) 1392control_persist_detach(void)
1393{ 1393{
1394 pid_t pid; 1394 pid_t pid;
1395 int devnull; 1395 int devnull, keep_stderr;
1396 1396
1397 debug("%s: backgrounding master process", __func__); 1397 debug("%s: backgrounding master process", __func__);
1398 1398
@@ -1423,8 +1423,10 @@ control_persist_detach(void)
1423 error("%s: open(\"/dev/null\"): %s", __func__, 1423 error("%s: open(\"/dev/null\"): %s", __func__,
1424 strerror(errno)); 1424 strerror(errno));
1425 } else { 1425 } else {
1426 keep_stderr = log_is_on_stderr() && debug_flag;
1426 if (dup2(devnull, STDIN_FILENO) == -1 || 1427 if (dup2(devnull, STDIN_FILENO) == -1 ||
1427 dup2(devnull, STDOUT_FILENO) == -1) 1428 dup2(devnull, STDOUT_FILENO) == -1 ||
1429 (!keep_stderr && dup2(devnull, STDERR_FILENO) == -1))
1428 error("%s: dup2: %s", __func__, strerror(errno)); 1430 error("%s: dup2: %s", __func__, strerror(errno));
1429 if (devnull > STDERR_FILENO) 1431 if (devnull > STDERR_FILENO)
1430 close(devnull); 1432 close(devnull);