From: Ralph Boehme Date: Wed, 10 Nov 2021 13:13:11 +0000 (+0100) Subject: lib/debug: fix fd check before dup'ing to stderr X-Git-Tag: ldb-2.5.0~95 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=948a82bd2651e73e4e669a89dc77ba93abbb9b2f;p=thirdparty%2Fsamba.git lib/debug: fix fd check before dup'ing to stderr 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 Reviewed-by: Andreas Schneider --- diff --git a/lib/util/debug.c b/lib/util/debug.c index 2f4a86734ce..4ed1543ef4b 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -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