diff options
-rw-r--r-- | source4/lib/util/debug.c | 46 | ||||
-rw-r--r-- | source4/smbd/server.c | 9 |
2 files changed, 38 insertions, 17 deletions
diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 65f8586eaa..2c40064b75 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -47,11 +47,31 @@ static struct { const char *prog_name; } state; +static BOOL reopen_logs_scheduled; +static BOOL check_reopen_logs(void) +{ + if (state.fd == 0 || reopen_logs_scheduled) { + reopen_logs_scheduled = False; + reopen_logs(); + } + + if (state.fd <= 0) return False; + + return True; +} + +_PUBLIC_ void debug_schedule_reopen_logs(void) +{ + reopen_logs_scheduled = True; +} + static void log_timestring(int level, const char *location, const char *func) { char *t = NULL; char *s = NULL; + if (!check_reopen_logs()) return; + if (state.logtype != DEBUG_FILE) return; t = timestring(NULL, time(NULL)); @@ -87,11 +107,7 @@ _PUBLIC_ void do_debug(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) va_list ap; char *s = NULL; - if (state.fd == 0) { - reopen_logs(); - } - - if (state.fd <= 0) return; + if (!check_reopen_logs()) return; va_start(ap, format); vasprintf(&s, format, ap); @@ -179,9 +195,9 @@ _PUBLIC_ const char *do_debug_tab(uint_t n) */ _PUBLIC_ void log_suspicious_usage(const char *from, const char *info) { - if (debug_handlers.ops.log_suspicious_usage) { - debug_handlers.ops.log_suspicious_usage(from, info); - } + if (!debug_handlers.ops.log_suspicious_usage) return; + + debug_handlers.ops.log_suspicious_usage(from, info); } @@ -190,9 +206,9 @@ _PUBLIC_ void log_suspicious_usage(const char *from, const char *info) */ _PUBLIC_ void print_suspicious_usage(const char* from, const char* info) { - if (debug_handlers.ops.print_suspicious_usage) { - debug_handlers.ops.print_suspicious_usage(from, info); - } + if (!debug_handlers.ops.print_suspicious_usage) return; + + debug_handlers.ops.print_suspicious_usage(from, info); } _PUBLIC_ uint32_t get_task_id(void) @@ -205,9 +221,11 @@ _PUBLIC_ uint32_t get_task_id(void) _PUBLIC_ void log_task_id(void) { - if (debug_handlers.ops.log_task_id) { - debug_handlers.ops.log_task_id(state.fd); - } + if (!debug_handlers.ops.log_task_id) return; + + if (!check_reopen_logs()) return; + + debug_handlers.ops.log_task_id(state.fd); } /** diff --git a/source4/smbd/server.c b/source4/smbd/server.c index b23a91769e..3036966f6a 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -98,6 +98,11 @@ static void cleanup_tmp_files(void) talloc_free(mem_ctx); } +static void sig_hup(int sig) +{ + debug_schedule_reopen_logs(); +} + /* setup signal masks */ @@ -124,9 +129,7 @@ static void setup_signals(void) BlockSignals(False, SIGHUP); BlockSignals(False, SIGTERM); - /* as we don't handle on this signals yet, we need to ignore them, - * instead of terminating */ - CatchSignal(SIGHUP, SIG_IGN); + CatchSignal(SIGHUP, sig_hup); } /* |