s3-debug Impove setup_logging() to specify logging to stderr
authorAndrew Bartlett <abartlet@samba.org>
Fri, 29 Oct 2010 03:19:32 +0000 (14:19 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 2 Nov 2010 04:36:04 +0000 (04:36 +0000)
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

39 files changed:
source3/client/client.c
source3/client/clitar.c
source3/client/smbspool.c
source3/include/debug.h
source3/lib/debug.c
source3/lib/netapi/netapi.c
source3/lib/smbconf/testsuite.c
source3/libsmb/libsmb_context.c
source3/nmbd/nmbd.c
source3/param/test_lp_load.c
source3/rpcclient/rpcclient.c
source3/smbd/server.c
source3/torture/locktest.c
source3/torture/locktest2.c
source3/torture/masktest.c
source3/torture/msgtest.c
source3/torture/pdbtest.c
source3/torture/smbiconv.c
source3/torture/torture.c
source3/torture/vfstest.c
source3/utils/dbwrap_tool.c
source3/utils/dbwrap_torture.c
source3/utils/net.c
source3/utils/nmblookup.c
source3/utils/ntlm_auth.c
source3/utils/pdbedit.c
source3/utils/profiles.c
source3/utils/sharesec.c
source3/utils/smbcacls.c
source3/utils/smbcontrol.c
source3/utils/smbcquotas.c
source3/utils/smbfilter.c
source3/utils/smbpasswd.c
source3/utils/smbtree.c
source3/utils/split_tokens.c
source3/utils/status.c
source3/utils/testparm.c
source3/web/swat.c
source3/winbindd/winbindd.c

index 9c028799382f50010bf15a2518cb4a0af59e930e..a7c09cf6c52f8a770655bf786b8fc0b5e6090b91 100644 (file)
@@ -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",
index 5aa59c8cffe6c711607419516ab7f425191b364f..bef53dcbbc0ebe1eae956a5c4146b6397bb3fda9 100644 (file)
@@ -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"));
index 07de579e017d17748d59a71c86a06111fa5e1c77..1dc548727c37ee65caff4b00bc99b8e271d67601 100644 (file)
@@ -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 */
 
index 467fb2f122cd84945d98c5f26fc58cb4ef1059fa..6f7baec4619d291ca652f419e06ed805990729fa 100644 (file)
@@ -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
+
index 3edf9608ca105ecdc348ddb26ccc624f9b241633..321b08e0996c4d32889ce9ed51561bc79081eed3 100644 (file)
  *   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.
index c4c2556b0bb2908c91473de827093a1059a47050..30042467430be1dd194ffc31dbdd627c224ed8cb 100644 (file)
@@ -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();
index 2c6fedc4ca77db7a7bf2a52522738bec3366b602..80754dd20c3cc564fe55ecade2d98d491cf88321 100644 (file)
@@ -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,
index 7f4ede49efae985d6b6b45a4ea9352b31fabfc75..8e76387346a94b2848f73a1db88ccfafe2c59954 100644 (file)
@@ -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) &&
index fcbe50842d0cfcfc56e008b4b6972734da8b7152..e93ff82333fd4b8836df363276330a3ab2b81f8c 100644 (file)
@@ -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);
 }
index 53ac23b99ca69a7a1141c38f4ef96f50035ef1a4..94715b5a596125a2671d17356f33a9adf831869b 100644 (file)
@@ -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;
 
index 34a81742e488b2f62fef0425497817c370a61468..a98f500e626b7a9fee48a34b3ed03a7b989020cf 100644 (file)
@@ -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) {
index cdf43203638270dccd8a1c371bb401525600ad0e..ebcc8ab6d7bedcd7c8bea3dc50c18820c009cdb9 100644 (file)
@@ -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 */
index a90c2e2dfee02227c7b30bf0e619e5014f1e5b76..9c8c6965b1f48e869a63a89ee93511271cd9a2ab 100644 (file)
@@ -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;server<NSERVERS;server++) {
                share[server] = argv[1+server];
index 5c8a2d8019ed953a7b1ca87419dfe85d54d66a06..033fe123ad068cb240db7f422bf35d738129ef04 100644 (file)
@@ -491,13 +491,13 @@ static void usage(void)
 
        setlinebuf(stdout);
 
-       dbf = x_stderr;
-
        if (argc < 5 || argv[1][0] == '-') {
                usage();
                exit(1);
        }
 
+       setup_logging(argv[0], DEBUG_STDOUT);
+
        share1 = argv[1];
        share2 = argv[2];
        nfspath1 = argv[3];
@@ -506,8 +506,6 @@ static void usage(void)
        all_string_sub(share1,"/","\\",0);
        all_string_sub(share2,"/","\\",0);
 
-       setup_logging(argv[0],True);
-
        argc -= 4;
        argv += 4;
 
index 82aa6bff3615c2c8988abd5045ceee5c17a28fab..b8bcb4ade0049dabb780b17d88c661bb1672cdb4 100644 (file)
@@ -484,8 +484,6 @@ static void usage(void)
 
        setlinebuf(stdout);
 
-       dbf = x_stderr;
-
        DEBUGLEVEL = 0;
        AllowDebugChange = False;
 
@@ -498,7 +496,7 @@ static void usage(void)
 
        all_string_sub(share,"/","\\",0);
 
-       setup_logging(argv[0],True);
+       setup_logging(argv[0], DEBUG_STDERR);
 
        argc -= 1;
        argv += 1;
index 6d1a6897724ee361c1517d15c6afc982d88029be..adb45f75e3a64aabc671a842a749fdafc8f555c2 100644 (file)
@@ -49,7 +49,7 @@ static void pong_message(struct messaging_context *msg_ctx,
 
        load_case_tables();
 
-       setup_logging(argv[0],True);
+       setup_logging(argv[0], DEBUG_STDOUT);
 
        lp_load(get_dyn_CONFIGFILE(),False,False,False,True);
 
index 6745ab0f7d24d9ee1787de8ea3c9b21aa984c816..82f8132797f0efce08c3fad31c0429dae79913d8 100644 (file)
@@ -259,7 +259,7 @@ int main(int argc, char **argv)
 
        /* Load configuration */
        lp_load(get_dyn_CONFIGFILE(), False, False, True, True);
-       setup_logging("pdbtest", True);
+       setup_logging("pdbtest", DEBUG_STDOUT);
 
        if (backend == NULL) {
                backend = lp_passdb_backend();
index d5d580c30be0ec21b614a50269ce564aaf8d7c2d..0ba796d9683446f1facf61c5f470124390d5d49f 100644 (file)
@@ -201,7 +201,7 @@ int main(int argc, char *argv[])
 
        /* the following functions are part of the Samba debugging
           facilities.  See lib/debug.c */
-       setup_logging("smbiconv", True);
+       setup_logging("smbiconv", DEBUG_STDOUT);
 
        if (preload_modules[0]) smb_load_modules(preload_modules);
 
index 57db3d47b70cfdcd2c7f4bc5268cb6bfbf5e7e55..bc4b58be739214aa8aeb79504d8cc92e59478719 100644 (file)
@@ -7937,15 +7937,13 @@ static void usage(void)
        TALLOC_CTX *frame = talloc_stackframe();
        int seed = time(NULL);
 
-       dbf = x_stdout;
-
 #ifdef HAVE_SETBUFFER
        setbuffer(stdout, NULL, 0);
 #endif
 
-       load_case_tables();
+       setup_logging("smbtorture", DEBUG_STDOUT);
 
-       setup_logging("smbtorture", true);
+       load_case_tables();
 
        if (is_default_dyn_CONFIGFILE()) {
                if(getenv("SMB_CONF_PATH")) {
index 76025eef1fc3c8ed7345a6364af1b4406106b61b..3b0ec54564c00ce73ecd0070c3c05d248b49e397 100644 (file)
@@ -462,7 +462,7 @@ int main(int argc, char *argv[])
 
        /* the following functions are part of the Samba debugging
           facilities.  See lib/debug.c */
-       setup_logging("vfstest", True);
+       setup_logging("vfstest", DEBUG_STDOUT);
        
        /* Load command lists */
 
index da96bd706f96d950c72a69c8850d66d6a671b15d..ef61ea9dbbf0e6f8210a67afc2d0cb5d01fe29d4 100644 (file)
@@ -215,7 +215,7 @@ int main(int argc, const char **argv)
 
        load_case_tables();
        DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
-       dbf = x_stderr;
+       setup_logging(argv[0], DEBUG_STDERR);
        AllowDebugChange = false;
        lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
 
index 2d9761bac4a599d23e4ca1c8ffd68ff42ad53d99..35d00734896154c71cd7caaac215e47955b581fe 100644 (file)
@@ -258,6 +258,7 @@ int main(int argc, const char *argv[])
                setlinebuf(stdout);
        }
 
+       setup_logging(argv[0], DEBUG_STDERR);
        DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
 
        pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
@@ -279,7 +280,6 @@ int main(int argc, const char *argv[])
        }
 
        load_case_tables();
-       dbf = x_stderr;
        AllowDebugChange = false;
        lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
 
index 9585398a566f22f8b0941f749afe9925089a0710..6993f9e52c45a7418b2c1fa28a997078f4007577 100644 (file)
@@ -822,6 +822,8 @@ static struct functable net_func[] = {
 
        zero_sockaddr(&c->opt_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,
index 1187c96d7361a0ffa82d11fc90f09636e0effc8d..d7e0cb23ced1957d740e93cca5d486d0d486cbcf 100644 (file)
@@ -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);
index f8145b4a6da461c5888422c0ccfe204bfda65d55..9f0c839186c5044611ec22b0ac04365a4bbd26e9 100644 (file)
@@ -2557,7 +2557,7 @@ enum {
        /* Samba client initialisation */
        load_case_tables();
 
-       dbf = x_stderr;
+       setup_logging("ntlm_auth", DEBUG_STDERR);
 
        /* Parse options */
 
index 5482b1099e5257a2325888b9efdc581a30fcec7f..400805375e121357c017bd2e4c95f4c783bd7854 100644 (file)
@@ -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);
index 50c9d534e9a062e32e8c59ef637618959cef2dc4..53862f441fc39af93642237cd6075cfe89c4d65c 100644 (file)
@@ -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);
index a945fe58f6f0a2006a0302499097ba852f21951d..ae959bafb5d3c9828971c8ebced5ca1b393021bf 100644 (file)
@@ -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);
 
index d9a4304463dba08a267ff8a3794c02cbd0bddebf..5ccdae6d08f356af0affdb24157a0ba3c1e97ad6 100644 (file)
@@ -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);
index 998971dfa26fdd6b4deabcecfa8efd413f853573..f4daf830885a958e85533c3868754a5e9912b127 100644 (file)
@@ -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 */
 
index 8ee573eafcd534dc0607952a3568a726d3332205..9721bc0b47b5864571ff1d6264121f984478191b 100644 (file)
@@ -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);
 
index 9d3e46825ffa22f890df5c18b66fb3c849ffb52d..2f78140897b9cd52a6c8bfb63bb7207310304023 100644 (file)
@@ -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();
 
index 2ae7e4dcdfb5fb29eac983edcbab0a7046589b8a..0fc002ad8aa79de5cc1f836a7c9cbf5bf662df44 100644 (file)
@@ -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
index f27011cdea0be48d405a61304df3613e4ff5cc10..c6d4be0e44b3ee7052ee786e8ec6e90f6daca341 100644 (file)
@@ -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) {
index 6c49b8b6e75e8ce78c0a0aeee97e96dec4097a79..e07d03aded03033eb4e68d8e1abfa90054ed9764 100644 (file)
@@ -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;
 
index ecfbf0613721a16739cfff4a609d610bbe797ca6..1ad2e9b1094d91e0f5c5326435aa96a066d3765f 100644 (file)
@@ -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");
index 6d606bba41cda2794663f956a9ce754b474c82da..8b8a31ea40e5ed1ebe35027103f15a7c542a927d 100644 (file)
@@ -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;
 
index 1250204d03e837eb98b2cc9261de24ed9b0ba882..531cf3f41121497d339c10b597ca7335fb0192ea 100644 (file)
@@ -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());
index b8a9e16075a1a727a2a9001c0977abffb0e07044..c831c94221a3efc61801e00984347d9fa80b3c17 100644 (file)
@@ -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()));