Don't recurse in reopen_logs().
authorAndrew Bartlett <abartlet@samba.org>
Thu, 11 Jun 2009 08:53:14 +0000 (18:53 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 11 Jun 2009 08:54:32 +0000 (18:54 +1000)
Use the state to avoid recursion in reopen_logs(), as DEBUG() can call
this function.

Andrew Bartlett

lib/util/debug.c

index 578822088fb21055637fbcb507ab1ab9161e8f45..58905187ee31cfce16f694561828a91b5ddd67d2 100644 (file)
@@ -50,6 +50,7 @@ static struct {
        int fd;
        enum debug_logtype logtype;
        const char *prog_name;
        int fd;
        enum debug_logtype logtype;
        const char *prog_name;
+       bool reopening_logs;
 } state;
 
 static bool reopen_logs_scheduled;
 } state;
 
 static bool reopen_logs_scheduled;
@@ -139,6 +140,9 @@ _PUBLIC_ void reopen_logs(void)
 {
        char *fname = NULL;
        int old_fd = state.fd;
 {
        char *fname = NULL;
        int old_fd = state.fd;
+       if (state.reopening_logs) {
+               return;
+       }
 
        switch (state.logtype) {
        case DEBUG_STDOUT:
 
        switch (state.logtype) {
        case DEBUG_STDOUT:
@@ -150,6 +154,7 @@ _PUBLIC_ void reopen_logs(void)
                break;
 
        case DEBUG_FILE:
                break;
 
        case DEBUG_FILE:
+               state.reopening_logs = true;
                if (logfile && (*logfile) == '/') {
                        fname = strdup(logfile);
                } else {
                if (logfile && (*logfile) == '/') {
                        fname = strdup(logfile);
                } else {
@@ -167,6 +172,7 @@ _PUBLIC_ void reopen_logs(void)
                } else {
                        DEBUG(1, ("Failed to find name for file-based logfile!\n"));
                }
                } else {
                        DEBUG(1, ("Failed to find name for file-based logfile!\n"));
                }
+               state.reopening_false = true;
 
                break;
        }
 
                break;
        }