diff options
-rw-r--r-- | log.c | 2 | ||||
-rw-r--r-- | ssh.c | 6 |
2 files changed, 5 insertions, 3 deletions
@@ -343,7 +343,7 @@ log_change_level(LogLevel new_log_level) | |||
343 | int | 343 | int |
344 | log_is_on_stderr(void) | 344 | log_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 */ |
@@ -1392,7 +1392,7 @@ static void | |||
1392 | control_persist_detach(void) | 1392 | control_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); |