s3: util: Do not take over stderr when there is no log file
[sfrench/samba-autobuild/.git] / lib / util / debug.c
index 141f3a595cada3fe0e405917c9b2029a423ea852..d41e0f99c7703e0498a5929749c7f16f49462459 100644 (file)
@@ -1077,8 +1077,11 @@ bool reopen_logs_internal(void)
        force_check_log_size();
        (void)umask(oldumask);
 
-       /* Take over stderr to catch output into logs */
-       if (state.fd > 0) {
+       /*
+        * If log file was opened or created successfully, take over stderr to
+        * catch output into logs.
+        */
+       if (new_fd != -1) {
                if (dup2(state.fd, 2) == -1) {
                        /* Close stderr too, if dup2 can't point it -
                           at the logfile.  There really isn't much