diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-07-18 17:07:25 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2011-07-20 09:17:09 +1000 |
commit | 485898458a1f786febd400be30bb3917fe5f71eb (patch) | |
tree | 9ec865e0baddf3e65960e329a812f35bd3a093b1 | |
parent | 3c9d01e3e58e2217915317406541ac8c6f6dcf92 (diff) | |
download | samba-485898458a1f786febd400be30bb3917fe5f71eb.tar.gz samba-485898458a1f786febd400be30bb3917fe5f71eb.tar.bz2 samba-485898458a1f786febd400be30bb3917fe5f71eb.zip |
debug: log early messages to stdout, and keep it open
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>
-rw-r--r-- | lib/util/debug.c | 6 | ||||
-rw-r--r-- | lib/util/debug.h | 1 | ||||
-rw-r--r-- | source3/nmbd/nmbd.c | 5 | ||||
-rw-r--r-- | source3/smbd/server.c | 10 | ||||
-rw-r--r-- | source3/winbindd/winbindd.c | 3 |
5 files changed, 22 insertions, 3 deletions
diff --git a/lib/util/debug.c b/lib/util/debug.c index c1b33de6d1..cc57ba8419 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -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; diff --git a/lib/util/debug.h b/lib/util/debug.h index 2708b19fd1..c61a2c55be 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -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); diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d8a4b17a07..e8a8b0ead9 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -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); } diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 6fc2a14fc4..f51565a411 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -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); diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 469d64e41d..dd6ac16cfd 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -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 { |