debug: log early messages to stdout, and keep it open
authorAndrew Bartlett <abartlet@samba.org>
Mon, 18 Jul 2011 07:07:25 +0000 (17:07 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 19 Jul 2011 23:17:09 +0000 (09:17 +1000)
The --log-stdout option was compromised by the log file descriptors being
closed once the file process forked.

Andrew Bartlett

Signed-off-by: Andrew Tridgell <tridge@samba.org>
lib/util/debug.c
lib/util/debug.h
source3/nmbd/nmbd.c
source3/smbd/server.c
source3/winbindd/winbindd.c

index c1b33de6d1e818018dc236fea02f18890b5a425b..cc57ba8419ea3766e2e6bb1674ad4f347ab25ae3 100644 (file)
@@ -514,6 +514,11 @@ bool debug_get_output_is_stderr(void)
        return (state.logtype == DEBUG_DEFAULT_STDERR) || (state.logtype == DEBUG_STDERR);
 }
 
+bool debug_get_output_is_stdout(void)
+{
+       return (state.logtype == DEBUG_DEFAULT_STDOUT) || (state.logtype == DEBUG_STDOUT);
+}
+
 /**************************************************************************
  reopen the log files
  note that we now do this unconditionally
@@ -542,6 +547,7 @@ bool reopen_logs_internal(void)
 
        switch (state.logtype) {
        case DEBUG_STDOUT:
+       case DEBUG_DEFAULT_STDOUT:
                debug_close_fd(state.fd);
                state.fd = 1;
                return true;
index 2708b19fd149f513b4305cadcaab6ebcd6696db1..c61a2c55beba18c496693008cf8ad5e56c44bba6 100644 (file)
@@ -229,6 +229,7 @@ void dbgflush( void );
 bool dbghdrclass(int level, int cls, const char *location, const char *func);
 bool dbghdr(int level, const char *location, const char *func);
 bool debug_get_output_is_stderr(void);
+bool debug_get_output_is_stdout(void);
 void debug_schedule_reopen_logs(void);
 char *debug_list_class_names_and_levels(void);
 
index d8a4b17a0719438b7429e9b3c5aed2b9775ab69f..e8a8b0ead92bd2cf5ffb013d4b144c913a852315 100644 (file)
@@ -766,6 +766,8 @@ static bool open_sockets(bool isdaemon, int port)
        talloc_enable_null_tracking();
        frame = talloc_stackframe();
 
+       setup_logging(argv[0], DEBUG_DEFAULT_STDOUT);
+
        load_case_tables();
 
        global_nmb_port = NMB_PORT;
@@ -840,8 +842,9 @@ static bool open_sockets(bool isdaemon, int port)
                DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
                exit(1);
        }
+
        if (log_stdout) {
-               setup_logging( argv[0], DEBUG_STDOUT);
+               setup_logging(argv[0], DEBUG_STDOUT);
        } else {
                setup_logging( argv[0], DEBUG_FILE);
        }
index 6fc2a14fc4156c198c3daeb80b72f93b7e3984d2..f51565a411d57cd32456f7ebea705ee88155b659 100644 (file)
@@ -428,7 +428,9 @@ static void smbd_accept_connection(struct tevent_context *ev,
 
                /* close our standard file
                   descriptors */
-               close_low_fds(False);
+               if (!debug_get_output_is_stdout()) {
+                       close_low_fds(False); /* Don't close stderr */
+               }
 
                /*
                 * Can't use TALLOC_FREE here. Nulling out the argument to it
@@ -910,6 +912,8 @@ extern void build_options(bool screen);
        talloc_enable_null_tracking();
        frame = talloc_stackframe();
 
+       setup_logging(argv[0], DEBUG_DEFAULT_STDOUT);
+
        load_case_tables();
 
        smbd_init_globals();
@@ -1287,7 +1291,9 @@ extern void build_options(bool screen);
                smbd_server_conn->sock = dup(0);
 
                /* close our standard file descriptors */
-               close_low_fds(False); /* Don't close stderr */
+               if (!debug_get_output_is_stdout()) {
+                       close_low_fds(False); /* Don't close stderr */
+               }
 
 #ifdef HAVE_ATEXIT
                atexit(killkids);
index 469d64e41d597b4476765476ead0c2128ffe6da1..dd6ac16cfdef95fa682c884cbf9534537ada9a4f 100644 (file)
@@ -1232,6 +1232,8 @@ int main(int argc, char **argv, char **envp)
        talloc_enable_null_tracking();
        frame = talloc_stackframe();
 
+       setup_logging("winbindd", DEBUG_DEFAULT_STDOUT);
+
        /* glibc (?) likes to print "User defined signal 1" and exit if a
           SIGUSR[12] is received before a handler is installed */
 
@@ -1316,6 +1318,7 @@ int main(int argc, char **argv, char **envp)
                        SAFE_FREE(lfile);
                }
        }
+
        if (log_stdout) {
                setup_logging("winbindd", DEBUG_STDOUT);
        } else {