From: Andrew Bartlett Date: Fri, 29 Oct 2010 03:19:32 +0000 (+1100) Subject: s3-debug Impove setup_logging() to specify logging to stderr X-Git-Url: http://git.samba.org/samba.git/?a=commitdiff_plain;h=9da4ace1d9789d300ab298bc34694c44b2062f30;p=kai%2Fsamba.git s3-debug Impove setup_logging() to specify logging to stderr This change improves the setup_logging() API so that callers which wish to set up logging to stderr can simply ask for it, rather than directly modify the dbf global variable. Andrew Bartlett --- diff --git a/source3/client/client.c b/source3/client/client.c index 9c028799382..a7c09cf6c52 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -5046,11 +5046,8 @@ static int do_message_op(struct user_auth_info *a_info) set_global_myname( "" ); /* set default debug level to 1 regardless of what smb.conf sets */ - setup_logging( "smbclient", true ); + setup_logging( "smbclient", DEBUG_DEFAULT_STDERR ); DEBUGLEVEL_CLASS[DBGC_ALL] = 1; - if ((dbf = x_fdup(x_stderr))) { - x_setbuf( dbf, NULL ); - } load_case_tables(); @@ -5119,10 +5116,7 @@ static int do_message_op(struct user_auth_info *a_info) } break; case 'E': - if (dbf) { - x_fclose(dbf); - } - dbf = x_stderr; + setup_logging("smbclient", DEBUG_STDERR ); display_set_stderr(); break; @@ -5215,7 +5209,7 @@ static int do_message_op(struct user_auth_info *a_info) } if ( override_logfile ) - setup_logging( lp_logfile(), false ); + setup_logging( lp_logfile(), DEBUG_FILE ); if (!lp_load(get_dyn_CONFIGFILE(),true,false,false,true)) { fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 5aa59c8cffe..bef53dcbbc0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1946,7 +1946,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) * tar output */ if (tarhandle == 1) { - dbf = x_stderr; + setup_logging("smbclient", DEBUG_STDERR); } if (!argv[Optind]) { DEBUG(0,("Must specify tar filename\n")); diff --git a/source3/client/smbspool.c b/source3/client/smbspool.c index 07de579e017..1dc548727c3 100644 --- a/source3/client/smbspool.c +++ b/source3/client/smbspool.c @@ -240,7 +240,7 @@ main(int argc, /* I - Number of command-line arguments */ * Setup the SAMBA server state... */ - setup_logging("smbspool", True); + setup_logging("smbspool", DEBUG_STDOUT); lp_set_in_client(True); /* Make sure that we tell lp_load we are */ diff --git a/source3/include/debug.h b/source3/include/debug.h index 467fb2f122c..6f7baec4619 100644 --- a/source3/include/debug.h +++ b/source3/include/debug.h @@ -59,8 +59,6 @@ bool dbghdr( int level, const char *location, const char *func); #pragma mips_frequency_hint NEVER dbghdr #endif -extern XFILE *dbf; - /* If we have these macros, we can add additional info to the header. */ #ifdef HAVE_FUNCTION_MACRO @@ -250,6 +248,13 @@ extern bool *DEBUGLEVEL_CLASS_ISSET; /* The following definitions come from lib/debug.c */ +/* Possible destinations for the debug log (in order of precedence, + * only a higher value will override a lower value */ +enum debug_logtype {DEBUG_DEFAULT_STDERR = 0, DEBUG_STDOUT = 1, DEBUG_FILE = 2, DEBUG_STDERR = 3}; + +void setup_logging(const char *prog_name, enum debug_logtype new_logtype); + +void debug_close_dbf(void); void gfree_debugsyms(void); const char *debug_classname_from_index(int ndx); int debug_add_class(const char *classname); @@ -258,8 +263,6 @@ bool debug_parse_levels(const char *params_str); void debug_message(struct messaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data); void debug_init(void); void debug_register_msgs(struct messaging_context *msg_ctx); -void setup_logging(const char *pname, bool interactive); -void setup_logging_stdout( void ); void debug_set_logfile(const char *name); bool reopen_logs( void ); void force_check_log_size( void ); @@ -270,3 +273,4 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func); bool dbghdr(int level, const char *location, const char *func); #endif + diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 3edf9608ca1..321b08e0996 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -70,16 +70,22 @@ * a newline. */ +/* state variables for the debug system */ +static struct { + XFILE *dbf; /* The log file handle */ + enum debug_logtype logtype; /* The type of logging we are doing: eg stdout, file, stderr */ + const char *prog_name; + bool reopening_logs; +} state; + /* -------------------------------------------------------------------------- ** * External variables. * - * dbf - Global debug file handle. * debugf - Debug file name. * DEBUGLEVEL - System-wide debug message limit. Messages with message- * levels higher than DEBUGLEVEL will not be processed. */ -XFILE *dbf = NULL; static char *debugf = NULL; bool debug_warn_unknown_class = True; bool debug_auto_add_unknown_class = True; @@ -109,10 +115,6 @@ int DEBUGLEVEL = &debug_all_class_hack; /* -------------------------------------------------------------------------- ** * Internal variables. * - * stdout_logging - Default False, if set to True then dbf will be set to - * stdout and debug output will go to dbf only, and not - * to syslog. Set in setup_logging() and read in Debug1(). - * * debug_count - Number of debug messages that have been output. * Used to check log size. * @@ -133,7 +135,6 @@ int DEBUGLEVEL = &debug_all_class_hack; * are unable to open a new log file for some reason. */ -static bool stdout_logging = False; static int debug_count = 0; #ifdef WITH_SYSLOG static int syslog_level = 0; @@ -564,55 +565,36 @@ void debug_register_msgs(struct messaging_context *msg_ctx) debuglevel_message); } -/*************************************************************************** - Get ready for syslog stuff -**************************************************************************/ - -void setup_logging(const char *pname, bool interactive) +/** + control the name of the logfile and whether logging will be to stdout, stderr + or a file, and set up syslog +*/ +void setup_logging(const char *prog_name, enum debug_logtype new_logtype) { debug_init(); - - /* reset to allow multiple setup calls, going from interactive to - non-interactive */ - stdout_logging = False; - if (dbf) { - x_fflush(dbf); - if (dbf != x_stdout) { - (void) x_fclose(dbf); - } + if (state.logtype < new_logtype) { + state.logtype = new_logtype; } - - dbf = NULL; - - if (interactive) { - stdout_logging = True; - dbf = x_stdout; - x_setbuf( x_stdout, NULL ); + if (prog_name) { + state.prog_name = prog_name; } + reopen_logs(); + + if (state.logtype == DEBUG_FILE) { #ifdef WITH_SYSLOG - else { - const char *p = strrchr_m( pname,'/' ); + const char *p = strrchr_m( prog_name,'/' ); if (p) - pname = p + 1; + prog_name = p + 1; #ifdef LOG_DAEMON - openlog( pname, LOG_PID, SYSLOG_FACILITY ); + openlog( prog_name, LOG_PID, SYSLOG_FACILITY ); #else /* for old systems that have no facility codes. */ - openlog( pname, LOG_PID ); + openlog( prog_name, LOG_PID ); #endif - } #endif + } } -/** - Just run logging to stdout for this program -*/ -_PUBLIC_ void setup_logging_stdout(void) -{ - setup_logging(NULL, True); -} - - /*************************************************************************** Set the logfile name. **************************************************************************/ @@ -623,6 +605,18 @@ void debug_set_logfile(const char *name) debugf = SMB_STRDUP(name); } +static void debug_close_xfile(XFILE *dbf) +{ + if (dbf && (dbf != x_stderr && dbf != x_stdout)) { + x_fclose(dbf); + } +} + +void debug_close_dbf(void) +{ + debug_close_xfile(state.dbf); + state.dbf = NULL; +} /************************************************************************** reopen the log files note that we now do this unconditionally @@ -631,16 +625,37 @@ void debug_set_logfile(const char *name) Fix from dgibson@linuxcare.com. **************************************************************************/ -bool reopen_logs( void ) +/** + reopen the log file (usually called because the log file name might have changed) +*/ +bool reopen_logs(void) { - char *fname = NULL; mode_t oldumask; XFILE *new_dbf = NULL; XFILE *old_dbf = NULL; bool ret = True; - if (stdout_logging) - return True; + char *fname = NULL; + if (state.reopening_logs) { + return true; + } + + switch (state.logtype) { + case DEBUG_STDOUT: + state.dbf = x_stdout; + x_setbuf( x_stdout, NULL ); + return true; + + case DEBUG_DEFAULT_STDERR: + case DEBUG_STDERR: + debug_close_xfile(state.dbf); + state.dbf = x_stderr; + x_setbuf( x_stderr, NULL ); + return true; + + case DEBUG_FILE: + break; + } oldumask = umask( 022 ); @@ -670,15 +685,15 @@ bool reopen_logs( void ) log_overflow = True; DEBUG(0, ("Unable to open new log file %s: %s\n", debugf, strerror(errno))); log_overflow = False; - if (dbf) - x_fflush(dbf); + if (state.dbf) + x_fflush(state.dbf); ret = False; } else { x_setbuf(new_dbf, NULL); - old_dbf = dbf; - dbf = new_dbf; + old_dbf = state.dbf; + state.dbf = new_dbf; if (old_dbf) - (void) x_fclose(old_dbf); + debug_close_xfile(old_dbf); } /* Fix from klausr@ITAP.Physik.Uni-Stuttgart.De @@ -689,7 +704,7 @@ bool reopen_logs( void ) (void)umask(oldumask); /* Take over stderr to catch output into logs */ - if (dbf && dup2(x_fileno(dbf), 2) == -1) { + if (state.dbf && dup2(x_fileno(state.dbf), 2) == -1) { close_low_fds(True); /* Close stderr too, if dup2 can't point it at the logfile */ } @@ -718,7 +733,7 @@ bool need_to_check_log_size( void ) return( False ); maxlog = lp_max_log_size() * 1024; - if( !dbf || maxlog <= 0 ) { + if( !state.dbf || maxlog <= 0 ) { debug_count = 0; return(False); } @@ -747,10 +762,10 @@ void check_log_size( void ) maxlog = lp_max_log_size() * 1024; - if(sys_fstat(x_fileno(dbf), &st, false) == 0 + if(sys_fstat(x_fileno(state.dbf), &st, false) == 0 && st.st_ex_size > maxlog ) { (void)reopen_logs(); - if( dbf && get_file_size( debugf ) > maxlog ) { + if( state.dbf && get_file_size( debugf ) > maxlog ) { char *name = NULL; if (asprintf(&name, "%s.old", debugf ) < 0) { @@ -770,7 +785,7 @@ void check_log_size( void ) * Here's where we need to panic if dbf == NULL.. */ - if(dbf == NULL) { + if(state.dbf == NULL) { /* This code should only be reached in very strange * circumstances. If we merely fail to open the new log we * should stick with the old one. ergo this should only be @@ -778,8 +793,8 @@ void check_log_size( void ) * startup or when the log level is increased from zero. * -dwg 6 June 2000 */ - dbf = x_fopen( "/dev/console", O_WRONLY, 0); - if(dbf) { + state.dbf = x_fopen( "/dev/console", O_WRONLY, 0); + if(state.dbf) { DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n", debugf )); } else { @@ -804,10 +819,10 @@ void check_log_size( void ) debug_count++; - if( stdout_logging ) { + if ( state.logtype != DEBUG_FILE ) { va_start( ap, format_str ); - if(dbf) - (void)x_vfprintf( dbf, format_str, ap ); + if(state.dbf) + (void)x_vfprintf( state.dbf, format_str, ap ); va_end( ap ); errno = old_errno; goto done; @@ -822,13 +837,13 @@ void check_log_size( void ) if( !lp_syslog_only() ) #endif { - if( !dbf ) { + if( !state.dbf ) { mode_t oldumask = umask( 022 ); - dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 ); + state.dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 ); (void)umask( oldumask ); - if( dbf ) { - x_setbuf( dbf, NULL ); + if( state.dbf ) { + x_setbuf( state.dbf, NULL ); } else { errno = old_errno; goto done; @@ -880,11 +895,11 @@ void check_log_size( void ) #endif { va_start( ap, format_str ); - if(dbf) - (void)x_vfprintf( dbf, format_str, ap ); + if(state.dbf) + (void)x_vfprintf( state.dbf, format_str, ap ); va_end( ap ); - if(dbf) - (void)x_fflush( dbf ); + if(state.dbf) + (void)x_fflush( state.dbf ); } done: @@ -926,7 +941,7 @@ static void bufr_print( void ) static void format_debug_text( const char *msg ) { size_t i; - bool timestamp = (!stdout_logging && (lp_timestamp_logs() || !(lp_loaded()))); + bool timestamp = (state.logtype == DEBUG_FILE && (lp_timestamp_logs() || !(lp_loaded()))); if (!format_bufr) { debug_init(); @@ -970,8 +985,8 @@ static void format_debug_text( const char *msg ) void dbgflush( void ) { bufr_print(); - if(dbf) - (void)x_fflush( dbf ); + if(state.dbf) + (void)x_fflush( state.dbf ); } /*************************************************************************** @@ -1021,8 +1036,9 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func) #endif /* Don't print a header if we're logging to stdout. */ - if( stdout_logging ) + if ( state.logtype != DEBUG_FILE ) { return( True ); + } /* Print the header if timestamps are turned on. If parameters are * not yet loaded, then default to timestamps on. diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index c4c2556b0bb..30042467430 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -80,11 +80,8 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) } /* prevent setup_logging() from closing x_stderr... */ - dbf = 0; - setup_logging("libnetapi", true); + setup_logging("libnetapi", DEBUG_STDERR); - dbf = x_stderr; - x_setbuf(x_stderr, NULL); AllowDebugChange = false; load_case_tables(); diff --git a/source3/lib/smbconf/testsuite.c b/source3/lib/smbconf/testsuite.c index 2c6fedc4ca7..80754dd20c3 100644 --- a/source3/lib/smbconf/testsuite.c +++ b/source3/lib/smbconf/testsuite.c @@ -294,7 +294,7 @@ int main(int argc, const char **argv) }; load_case_tables(); - dbf = x_stderr; + setup_logging(argv[0], DEBUG_STDERR); /* parse options */ pc = poptGetContext("smbconftort", argc, (const char **)argv, diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c index 7f4ede49efa..8e76387346a 100644 --- a/source3/libsmb/libsmb_context.c +++ b/source3/libsmb/libsmb_context.c @@ -47,7 +47,7 @@ SMBC_module_init(void * punused) load_case_tables(); - setup_logging("libsmbclient", True); + setup_logging("libsmbclient", DEBUG_STDOUT); /* Here we would open the smb.conf file if needed ... */ @@ -561,8 +561,7 @@ smbc_init_context(SMBCCTX *context) * leave it up to the user. If any one context spefies debug to * stderr then all will be. */ - dbf = x_stderr; - x_setbuf(x_stderr, NULL); + setup_logging("libsmbclient", DEBUG_STDERR); } if ((!smbc_getFunctionAuthData(context) && diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index fcbe50842d0..e93ff82333f 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -863,8 +863,11 @@ 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); } - - setup_logging( argv[0], log_stdout ); + if (log_stdout) { + setup_logging( argv[0], DEBUG_STDOUT); + } else { + setup_logging( argv[0], DEBUG_FILE); + } reopen_logs(); @@ -1024,8 +1027,8 @@ static bool open_sockets(bool isdaemon, int port) TALLOC_FREE(frame); process(); - if (dbf) - x_fclose(dbf); + debug_close_dbf(); + kill_async_dns_child(); return(0); } diff --git a/source3/param/test_lp_load.c b/source3/param/test_lp_load.c index 53ac23b99ca..94715b5a596 100644 --- a/source3/param/test_lp_load.c +++ b/source3/param/test_lp_load.c @@ -49,7 +49,7 @@ int main(int argc, const char **argv) while(poptGetNextOpt(pc) != -1); - setup_logging(poptGetArg(pc), True); + setup_logging(poptGetArg(pc), DEBUG_STDERR); if (poptPeekArg(pc)) { config_file = poptGetArg(pc); @@ -61,7 +61,6 @@ int main(int argc, const char **argv) count = atoi(count_str); } - dbf = x_stderr; /* Don't let the debuglevel be changed by smb.conf. */ AllowDebugChange = False; diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 34a81742e48..a98f500e626 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -912,7 +912,7 @@ out_free: /* the following functions are part of the Samba debugging facilities. See lib/debug.c */ - setup_logging("rpcclient", True); + setup_logging("rpcclient", DEBUG_STDOUT); rpcclient_auth_info = user_auth_info_init(frame); if (rpcclient_auth_info == NULL) { diff --git a/source3/smbd/server.c b/source3/smbd/server.c index cdf43203638..ebcc8ab6d7b 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -915,7 +915,11 @@ extern void build_options(bool screen); log_stdout = True; } - setup_logging(argv[0],log_stdout); + if (log_stdout) { + setup_logging(argv[0], DEBUG_STDOUT); + } else { + setup_logging(argv[0], DEBUG_FILE); + } if (print_build_options) { build_options(True); /* Display output to screen as well as debug */ diff --git a/source3/torture/locktest.c b/source3/torture/locktest.c index a90c2e2dfee..9c8c6965b1f 100644 --- a/source3/torture/locktest.c +++ b/source3/torture/locktest.c @@ -604,14 +604,12 @@ static void usage(void) load_case_tables(); - dbf = x_stderr; - if (argc < 3 || argv[1][0] == '-') { usage(); exit(1); } - setup_logging(argv[0],True); + setup_logging(argv[0], DEBUG_STDOUT); for (server=0;serveropt_dest_ip); + setup_logging(argv[0], DEBUG_STDERR); + load_case_tables(); setlocale(LC_ALL, ""); @@ -834,7 +836,6 @@ static struct functable net_func[] = { /* set default debug level to 0 regardless of what smb.conf sets */ DEBUGLEVEL_CLASS[DBGC_ALL] = 0; - dbf = x_stderr; c->private_data = net_func; pc = poptGetContext(NULL, argc, (const char **) argv, long_options, diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 1187c96d736..d7e0cb23ced 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -259,7 +259,7 @@ int main(int argc,char *argv[]) load_case_tables(); - setup_logging(argv[0],True); + setup_logging(argv[0], DEBUG_STDOUT); pc = poptGetContext("nmblookup", argc, (const char **)argv, long_options, POPT_CONTEXT_KEEP_FIRST); diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c index f8145b4a6da..9f0c839186c 100644 --- a/source3/utils/ntlm_auth.c +++ b/source3/utils/ntlm_auth.c @@ -2557,7 +2557,7 @@ enum { /* Samba client initialisation */ load_case_tables(); - dbf = x_stderr; + setup_logging("ntlm_auth", DEBUG_STDERR); /* Parse options */ diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index 5482b1099e5..400805375e1 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -1058,7 +1058,7 @@ int main (int argc, char **argv) load_case_tables(); - setup_logging("pdbedit", True); + setup_logging("pdbedit", DEBUG_STDOUT); pc = poptGetContext(NULL, argc, (const char **) argv, long_options, POPT_CONTEXT_KEEP_FIRST); diff --git a/source3/utils/profiles.c b/source3/utils/profiles.c index 50c9d534e9a..53862f441fc 100644 --- a/source3/utils/profiles.c +++ b/source3/utils/profiles.c @@ -215,9 +215,7 @@ int main( int argc, char *argv[] ) /* setup logging options */ - setup_logging( "profiles", True ); - dbf = x_stderr; - x_setbuf( x_stderr, NULL ); + setup_logging( "profiles", DEBUG_STDERR); pc = poptGetContext("profiles", argc, (const char **)argv, long_options, POPT_CONTEXT_KEEP_FIRST); diff --git a/source3/utils/sharesec.c b/source3/utils/sharesec.c index a945fe58f6f..ae959bafb5d 100644 --- a/source3/utils/sharesec.c +++ b/source3/utils/sharesec.c @@ -543,10 +543,8 @@ int main(int argc, const char *argv[]) } /* set default debug level to 1 regardless of what smb.conf sets */ - setup_logging( "sharesec", True ); + setup_logging( "sharesec", DEBUG_STDERR); DEBUGLEVEL_CLASS[DBGC_ALL] = 1; - dbf = x_stderr; - x_setbuf( x_stderr, NULL ); pc = poptGetContext("sharesec", argc, argv, long_options, 0); diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index d9a4304463d..5ccdae6d08f 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -1203,10 +1203,8 @@ static struct cli_state *connect_one(struct user_auth_info *auth_info, /* set default debug level to 1 regardless of what smb.conf sets */ - setup_logging( "smbcacls", True ); + setup_logging( "smbcacls", DEBUG_STDERR); DEBUGLEVEL_CLASS[DBGC_ALL] = 1; - dbf = x_stderr; - x_setbuf( x_stderr, NULL ); AllowDebugChange = false; setlinebuf(stdout); diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 998971dfa26..f4daf830885 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -1379,7 +1379,7 @@ int main(int argc, const char **argv) load_case_tables(); - setup_logging(argv[0],True); + setup_logging(argv[0], DEBUG_STDOUT); /* Parse command line arguments using popt */ diff --git a/source3/utils/smbcquotas.c b/source3/utils/smbcquotas.c index 8ee573eafcd..9721bc0b47b 100644 --- a/source3/utils/smbcquotas.c +++ b/source3/utils/smbcquotas.c @@ -464,10 +464,8 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" }, ZERO_STRUCT(qt); /* set default debug level to 1 regardless of what smb.conf sets */ - setup_logging( "smbcquotas", True ); + setup_logging( "smbcquotas", DEBUG_STDERR); DEBUGLEVEL_CLASS[DBGC_ALL] = 1; - dbf = x_stderr; - x_setbuf( x_stderr, NULL ); setlinebuf(stdout); diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 9d3e46825ff..2f78140897b 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -295,7 +295,7 @@ int main(int argc, char *argv[]) load_case_tables(); - setup_logging(argv[0],True); + setup_logging(argv[0], DEBUG_STDOUT); configfile = get_dyn_CONFIGFILE(); diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 2ae7e4dcdfb..0fc002ad8aa 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -584,7 +584,7 @@ int main(int argc, char **argv) local_flags = process_options(argc, argv, local_flags); - setup_logging("smbpasswd", True); + setup_logging("smbpasswd", DEBUG_STDERR); /* * Set the machine NETBIOS name if not already diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c index f27011cdea0..c6d4be0e44b 100644 --- a/source3/utils/smbtree.c +++ b/source3/utils/smbtree.c @@ -291,9 +291,7 @@ static bool print_tree(struct user_auth_info *user_info) setlinebuf(stdout); - dbf = x_stderr; - - setup_logging(argv[0],True); + setup_logging(argv[0], DEBUG_STDERR); auth_info = user_auth_info_init(frame); if (auth_info == NULL) { diff --git a/source3/utils/split_tokens.c b/source3/utils/split_tokens.c index 6c49b8b6e75..e07d03aded0 100644 --- a/source3/utils/split_tokens.c +++ b/source3/utils/split_tokens.c @@ -50,7 +50,7 @@ int main(int argc, const char *argv[]) while(poptGetNextOpt(pc) != -1); - setup_logging(poptGetArg(pc), true); + setup_logging(poptGetArg(pc), DEBUG_STDERR); sequence = poptGetArg(pc); @@ -59,7 +59,6 @@ int main(int argc, const char *argv[]) return 1; } - dbf = x_stderr; DEBUGLEVEL = 0; AllowDebugChange = false; diff --git a/source3/utils/status.c b/source3/utils/status.c index ecfbf061372..1ad2e9b1094 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -309,9 +309,7 @@ static int traverse_sessionid(const char *key, struct sessionid *session, sec_init(); load_case_tables(); - setup_logging(argv[0],True); - - dbf = x_stderr; + setup_logging(argv[0], DEBUG_STDERR); if (getuid() != geteuid()) { d_printf("smbstatus should not be run setuid\n"); diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 6d606bba41c..8b8a31ea40e 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -365,7 +365,7 @@ rameter is ignored when using CUPS libraries.\n", exit(0); } - setup_logging(poptGetArg(pc), True); + setup_logging(poptGetArg(pc), DEBUG_STDERR); if (poptPeekArg(pc)) config_file = poptGetArg(pc); @@ -381,7 +381,6 @@ rameter is ignored when using CUPS libraries.\n", goto done; } - dbf = x_stderr; /* Don't let the debuglevel be changed by smb.conf. */ AllowDebugChange = False; diff --git a/source3/web/swat.c b/source3/web/swat.c index 1250204d03e..531cf3f4112 100644 --- a/source3/web/swat.c +++ b/source3/web/swat.c @@ -1413,12 +1413,12 @@ const char *lang_msg_rotate(TALLOC_CTX *ctx, const char *msgid) /* we don't want any SIGPIPE messages */ BlockSignals(True,SIGPIPE); - dbf = x_fopen("/dev/null", O_WRONLY, 0); - if (!dbf) dbf = x_stderr; + debug_set_logfile("/dev/null"); /* we don't want stderr screwing us up */ close(2); open("/dev/null", O_WRONLY); + setup_logging("swat", DEBUG_FILE); pc = poptGetContext("swat", argc, (const char **) argv, long_options, 0); @@ -1429,9 +1429,10 @@ const char *lang_msg_rotate(TALLOC_CTX *ctx, const char *msgid) poptFreeContext(pc); load_case_tables(); - - setup_logging(argv[0],False); + + /* This should set a more apporiate log file */ load_config(True); + reopen_logs(); load_interfaces(); iNumNonAutoPrintServices = lp_numservices(); load_printers(server_event_context(), server_messaging_context()); diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index b8a9e16075a..c831c94221a 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -1217,7 +1217,11 @@ int main(int argc, char **argv, char **envp) SAFE_FREE(lfile); } } - setup_logging("winbindd", log_stdout); + if (log_stdout) { + setup_logging("winbindd", DEBUG_STDOUT); + } else { + setup_logging("winbindd", DEBUG_FILE); + } reopen_logs(); DEBUG(0,("winbindd version %s started.\n", samba_version_string()));