r14038: reopen log files after a SIGHUP
authorStefan Metzmacher <metze@samba.org>
Wed, 8 Mar 2006 12:31:57 +0000 (12:31 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:52:37 +0000 (13:52 -0500)
metze

source/lib/util/debug.c
source/smbd/server.c

index 65f8586eaa68e05e2aab5c2145de7bfafae4d4b3..2c40064b7553735562df5d720450df570681cc55 100644 (file)
@@ -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);
 }
 
 /**
index b23a91769e41e2a12b5b6bee0283efab1c12555e..3036966f6a0d6f6fb98b52b66c524c731a535470 100644 (file)
@@ -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);
 }
 
 /*