]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/debug: fix fd check before dup'ing to stderr
authorRalph Boehme <slow@samba.org>
Wed, 10 Nov 2021 13:13:11 +0000 (14:13 +0100)
committerRalph Boehme <slow@samba.org>
Thu, 11 Nov 2021 13:49:32 +0000 (13:49 +0000)
Before I added per-class logfile and we had only one fd for the logfile the code
looked like this:

        /* Take over stderr to catch output into logs */
        if (state.fd > 0) {
                if (dup2(state.fd, 2) == -1) {
                        /* Close stderr too, if dup2 can't point it -
                           at the logfile.  There really isn't much
                           that can be done on such a fundamental
                           failure... */
                        close_low_fd(2);
                }
        }

In the current code the equivalent to state.fd is dbgc_config[DBGC_ALL].fd.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14897

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/util/debug.c

index 2f4a86734ce12a47c6c9cf603ab069e18b6cd190..4ed1543ef4bec378d985ad4ddd9bddd1f2e2ee60 100644 (file)
@@ -1249,7 +1249,6 @@ bool reopen_logs_internal(void)
 {
        struct debug_backend *b = NULL;
        mode_t oldumask;
-       int new_fd = 0;
        size_t i;
        bool ok;
 
@@ -1314,7 +1313,7 @@ bool reopen_logs_internal(void)
         * If log file was opened or created successfully, take over stderr to
         * catch output into logs.
         */
-       if (new_fd != -1) {
+       if (dbgc_config[DBGC_ALL].fd > 0) {
                if (dup2(dbgc_config[DBGC_ALL].fd, 2) == -1) {
                        /* Close stderr too, if dup2 can't point it -
                           at the logfile.  There really isn't much