[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Mon Nov 1 23:20:01 MDT 2010


The branch, master has been updated
       via  b717ec2 s3-param Fix up lp_set_cmdline() not to re-store cmdline options on each reload
       via  7d0f04a s3-libsmbclient Don't store 'debug_stderr' on the libsmbclient context
       via  b1099a5 s3-libsmbclient Add comments to describe the behaviour of DEBUG()
       via  e16c990 s3-libsmbclient-examples Add tests for debug behaviour.
       via  db2a61a debug Explain the behaviour of setup_logging() more clearly
       via  4aeb608 s3-debug Clarify the handling of invalid state.fd values in debug.c
       via  ed111d1 s3-debug Move 'load_case_tables()' before lp_set_cmdline() and popt calls
       via  e64dfdc s3-debug Convert from x_file to real file descriptors.
       via  d9f67ee s3-debug Remove last direct assignements to DEBUGLEVEL
       via  cf4de8e s3-debug Remove 'AllowDebugChange' and use lp_set_cmdline() instead
       via  9da4ace s3-debug Impove setup_logging() to specify logging to stderr
      from  4ae2789 lib/debug Use vdprintf rather than manually allocate

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit b717ec26d96d5285f554c56c01d885c19b1c9b65
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Nov 2 15:33:42 2010 +1100

    s3-param Fix up lp_set_cmdline() not to re-store cmdline options on each reload
    
    The previous code was buggy in that it did not honour the 'store'
    argument to lp_set_cmdline_helper(), and would use the stored
    parameter after freeing it when handling overwritten values.
    
    Andrew Bartlett
    
    Autobuild-User: Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date: Tue Nov  2 05:19:17 UTC 2010 on sn-devel-104

commit 7d0f04a651e4bed7e1e6d587a1bdaf3cfa6f9e33
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Nov 2 15:32:16 2010 +1100

    s3-libsmbclient Don't store 'debug_stderr' on the libsmbclient context
    
    Following the review of this patch series by Derrell Lipman, remove
    the seperate storage of the debug_stderr variable from the
    libsmbclient SMBC_internal_data context.
    
    Andrew Bartlett

commit b1099a5b560db0145534ed6484eee27c7d93528a
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Nov 1 20:55:04 2010 +1100

    s3-libsmbclient Add comments to describe the behaviour of DEBUG()
    
    This isn't quite what you would expect from this interface, but actually
    avoids some really nasty situations if you ever have more than one
    libsmbclient context in a process.
    
    In the real world, if you have asked for DEBUG() to stderr in one part
    of the code, you will want it globally, even in a different thread
    (which in the past would have rest everything to stdout again, at
    least while starting up).
    
    Andrew Bartlett

commit e16c9904c60bd7531ada1acd2396e56ee1213dea
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Nov 1 20:30:33 2010 +1100

    s3-libsmbclient-examples Add tests for debug behaviour.

commit db2a61ab26f8dab5c9b8f27ae25f9b1ca5fe67b4
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Nov 1 18:42:36 2010 +1100

    debug Explain the behaviour of setup_logging() more clearly

commit 4aeb608eca3be67498819000f5eea9ad63e9b7f8
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Oct 29 21:12:12 2010 +1100

    s3-debug Clarify the handling of invalid state.fd values in debug.c
    
    This makes it clear that -1 and 0 are both invalid file descriptor values
    for DEBUG output.
    
    Andrew Bartlett

commit ed111d11ebcbaa1e709485f86ca45e582a55301f
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Oct 29 21:10:31 2010 +1100

    s3-debug Move 'load_case_tables()' before lp_set_cmdline() and popt calls
    
    The problem here is that we cannot run lp_set_cmdline() (directly or
    indirectly via the popt helpers) until load_case_tables() has been run.
    
    However, load_case_tables does not have auto-initialisation, so we
    must init it once, and once only.
    
    Andrew Bartlett

commit e64dfdcc71e17f21419f24b3f2b32d477b4cea1e
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Oct 29 16:20:22 2010 +1100

    s3-debug Convert from x_file to real file descriptors.
    
    X_FILE does not gain us anything in this use case, we want our log
    messages on disk, not in a buffer, and we don't gain anything from the
    X_FILE api.  I discussed the matter with tridge, who feels that to use
    FILE in the first place was a mistake, and that X_FILE isn't any
    better, but was a stop-gap to avoid issues on solaris.
    
    Andrew Bartlett

commit d9f67eebf621adacf5514c7ba1ed17b4953db762
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Oct 29 15:29:09 2010 +1100

    s3-debug Remove last direct assignements to DEBUGLEVEL
    
    All future assignments of the debug level should go via
    lp_set_cmdline("log level", "x") because this will ensure the value is
    not overwritten in an smb.conf load.
    
    Andrew Bartlett

commit cf4de8ec2c8df2ceabbe3d836d296b058e7b19fb
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Oct 29 15:06:36 2010 +1100

    s3-debug Remove 'AllowDebugChange' and use lp_set_cmdline() instead
    
    By removing this global variable, the API between the two different
    debug systems is made more similar.  Both s3 and s4 now have
    lp_set_cmdline() which ensures that the smb.conf cannot overwrite
    these the user-specified log level.
    
    Andrew Bartlett

commit 9da4ace1d9789d300ab298bc34694c44b2062f30
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Oct 29 14:19:32 2010 +1100

    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

-----------------------------------------------------------------------

Summary of changes:
 examples/libsmbclient/testctx.c   |   17 +++-
 lib/util/debug.c                  |    8 ++-
 nsswitch/wins.c                   |    3 +-
 source3/client/client.c           |   22 +----
 source3/client/clitar.c           |    2 +-
 source3/client/smbspool.c         |    2 +-
 source3/include/debug.h           |   16 +++-
 source3/include/libsmb_internal.h |    5 -
 source3/lib/debug.c               |  182 +++++++++++++++++++------------------
 source3/lib/netapi/netapi.c       |   18 +---
 source3/lib/popt_common.c         |    4 +-
 source3/lib/smbconf/testsuite.c   |    2 +-
 source3/libsmb/libsmb_context.c   |   12 +--
 source3/libsmb/libsmb_setget.c    |   27 +++++-
 source3/nmbd/nmbd.c               |    9 +-
 source3/param/loadparm.c          |   13 ++-
 source3/param/test_lp_load.c      |   10 +--
 source3/rpcclient/rpcclient.c     |    4 +-
 source3/smbd/server.c             |   10 ++-
 source3/torture/locktest.c        |    4 +-
 source3/torture/locktest2.c       |    6 +-
 source3/torture/masktest.c        |   10 +--
 source3/torture/msgtest.c         |    2 +-
 source3/torture/pdbtest.c         |    2 +-
 source3/torture/smbiconv.c        |    2 +-
 source3/torture/torture.c         |    8 +-
 source3/torture/vfstest.c         |    4 +-
 source3/utils/dbwrap_tool.c       |    7 +-
 source3/utils/dbwrap_torture.c    |   10 +-
 source3/utils/net.c               |   12 +--
 source3/utils/nmblookup.c         |    4 +-
 source3/utils/ntlm_auth.c         |    2 +-
 source3/utils/pdbedit.c           |    2 +-
 source3/utils/profiles.c          |    4 +-
 source3/utils/sharesec.c          |   11 +-
 source3/utils/smbcacls.c          |   10 +--
 source3/utils/smbcontrol.c        |    2 +-
 source3/utils/smbcquotas.c        |    6 +-
 source3/utils/smbfilter.c         |    2 +-
 source3/utils/smbpasswd.c         |    8 +-
 source3/utils/smbtree.c           |    4 +-
 source3/utils/split_tokens.c      |   10 +--
 source3/utils/status.c            |    4 +-
 source3/utils/testparm.c          |   10 +--
 source3/web/swat.c                |   11 +-
 source3/winbindd/winbindd.c       |    6 +-
 46 files changed, 250 insertions(+), 279 deletions(-)


Changeset truncated at 500 lines:

diff --git a/examples/libsmbclient/testctx.c b/examples/libsmbclient/testctx.c
index 8820bc8..cec9776 100644
--- a/examples/libsmbclient/testctx.c
+++ b/examples/libsmbclient/testctx.c
@@ -1,11 +1,26 @@
 #include <libsmbclient.h>
+#include <stdlib.h>
+#include <stdio.h>
 
 void create_and_destroy_context (void)
 {
+  int i;
   SMBCCTX *ctx;
   ctx = smbc_new_context ();
+  /* Both should do the same thing */
+  smbc_setOptionDebugToStderr(ctx, 1);
+  smbc_option_set(ctx, "debug_to_stderr", 1);
+  smbc_setDebug(ctx, 1);
+  i = smbc_getDebug(ctx);
+  if (i != 1) { 
+	  printf("smbc_getDebug() did not return debug level set\n");
+	  exit(1);
+  }
+  if (!smbc_getOptionDebugToStderr(ctx)) {
+	  printf("smbc_setOptionDebugToStderr() did not stick\n");
+	  exit(1);
+  }
   smbc_init_context (ctx);
-
   smbc_free_context (ctx, 1);
 }
 
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 5760a70..54e7a5f 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -190,7 +190,13 @@ void debug_setup_talloc_log(void)
 
 /**
   control the name of the logfile and whether logging will be to stdout, stderr
-  or a file
+  or a file, and set up syslog
+
+  new_log indicates the destination for the debug log (an enum in
+  order of precedence - once set to DEBUG_FILE, it is not possible to
+  reset to DEBUG_STDOUT for example.  This makes it easy to override
+  for debug to stderr on the command line, as the smb.conf cannot
+  reset it back to file-based logging
 */
 _PUBLIC_ void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
 {
diff --git a/nsswitch/wins.c b/nsswitch/wins.c
index b4bc788..aa02f32 100644
--- a/nsswitch/wins.c
+++ b/nsswitch/wins.c
@@ -94,8 +94,7 @@ static int wins_lookup_open_socket_in(void)
 static void nss_wins_init(void)
 {
 	initialised = 1;
-	DEBUGLEVEL = 0;
-	AllowDebugChange = False;
+	lp_set_cmdline("log level", "0");
 
 	TimeInit();
 	setup_logging("nss_wins",False);
diff --git a/source3/client/client.c b/source3/client/client.c
index 9c02879..5129268 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -5046,14 +5046,11 @@ 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 );
-	DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
-	if ((dbf = x_fdup(x_stderr))) {
-		x_setbuf( dbf, NULL );
-	}
-
+	setup_logging( "smbclient", DEBUG_DEFAULT_STDERR );
 	load_case_tables();
 
+	lp_set_cmdline("log level", "1");
+
 	auth_info = user_auth_info_init(frame);
 	if (auth_info == NULL) {
 		exit(1);
@@ -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;
 
@@ -5196,12 +5190,6 @@ static int do_message_op(struct user_auth_info *a_info)
 					       poptGetArg(pc));
 	}
 
-	/*
-	 * Don't load debug level from smb.conf. It should be
-	 * set by cmdline arg or remain default (0)
-	 */
-	AllowDebugChange = false;
-
 	/* save the workgroup...
 
 	   FIXME!! do we need to do this for other options as well
@@ -5215,7 +5203,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 5aa59c8..bef53dc 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 07de579..1dc5487 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 467fb2f..328bfb6 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,16 @@ extern bool *DEBUGLEVEL_CLASS_ISSET;
 
 /* The following definitions come from lib/debug.c  */
 
+/** Possible destinations for the debug log (in order of precedence -
+ * once set to DEBUG_FILE, it is not possible to reset to DEBUG_STDOUT
+ * for example.  This makes it easy to override for debug to stderr on
+ * the command line, as the smb.conf cannot reset it back to
+ * file-based logging */
+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 +266,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 );
@@ -268,5 +274,7 @@ void check_log_size( void );
 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);
 
 #endif
+
diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h
index 0bfcd8f..39a32f9 100644
--- a/source3/include/libsmb_internal.h
+++ b/source3/include/libsmb_internal.h
@@ -138,11 +138,6 @@ struct SMBC_internal_data {
 	SMBCFILE *                              files;
 
         /*
-         * Log to standard error instead of the more typical standard output
-         */
-        bool                                    debug_stderr;
-
-        /*
          * Support "Create Time" in get/set with the *xattr() functions, if
          * true.  This replaces the dos attribute strings C_TIME, A_TIME and
          * M_TIME with CHANGE_TIME, ACCESS_TIME and WRITE_TIME, and adds
diff --git a/source3/lib/debug.c b/source3/lib/debug.c
index 3edf960..a97c0bf 100644
--- a/source3/lib/debug.c
+++ b/source3/lib/debug.c
@@ -70,20 +70,25 @@
  *   a newline.
  */
 
+/* state variables for the debug system */
+static struct {
+	int fd;   /* 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;
-bool    AllowDebugChange = True;
 
 /*
    used to check if the user specified a
@@ -109,10 +114,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 +134,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;
@@ -468,9 +468,6 @@ bool debug_parse_levels(const char *params_str)
 	/* Just in case */
 	debug_init();
 
-	if (AllowDebugChange == False)
-		return True;
-
 	params = str_list_make_v3(talloc_tos(), params_str, NULL);
 
 	if (debug_parse_params(params)) {
@@ -564,55 +561,42 @@ 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
+
+  new_log indicates the destination for the debug log (an enum in
+  order of precedence - once set to DEBUG_FILE, it is not possible to
+  reset to DEBUG_STDOUT for example.  This makes it easy to override
+  for debug to stderr on the command line, as the smb.conf cannot
+  reset it back to file-based logging
+*/
+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 +607,18 @@ void debug_set_logfile(const char *name)
 	debugf = SMB_STRDUP(name);
 }
 
+static void debug_close_fd(int fd)
+{
+	if (fd > 2) {
+		close(fd);
+	}
+}
+
+bool debug_get_output_is_stderr(void)
+{
+	return (state.logtype == DEBUG_DEFAULT_STDERR) || (state.logtype == DEBUG_STDERR);
+}
+
 /**************************************************************************
  reopen the log files
  note that we now do this unconditionally
@@ -631,16 +627,36 @@ void debug_set_logfile(const char *name)
  Fix from dgibson at 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;
+	int new_fd = 0;
+	int old_fd = 0;
 	bool ret = True;
 
-	if (stdout_logging)
-		return True;
+	char *fname = NULL;
+	if (state.reopening_logs) {
+		return true;
+	}
+
+	switch (state.logtype) {
+	case DEBUG_STDOUT:
+		debug_close_fd(state.fd);
+		state.fd = 1;
+		return true;
+
+	case DEBUG_DEFAULT_STDERR:
+	case DEBUG_STDERR:
+		debug_close_fd(state.fd);
+		state.fd = 2;
+		return true;
+
+	case DEBUG_FILE:
+		break;
+	}
 
 	oldumask = umask( 022 );
 
@@ -664,21 +680,17 @@ bool reopen_logs( void )
 	}
 
 	debugf = fname;
-	new_dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644);
+	new_fd = open( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644);
 
-	if (!new_dbf) {
+	if (new_fd == -1) {
 		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);
 		ret = False;
 	} else {
-		x_setbuf(new_dbf, NULL);
-		old_dbf = dbf;
-		dbf = new_dbf;
-		if (old_dbf)
-			(void) x_fclose(old_dbf);
+		old_fd = state.fd;
+		state.fd = new_fd;
+		debug_close_fd(old_fd);
 	}
 
 	/* Fix from klausr at ITAP.Physik.Uni-Stuttgart.De
@@ -689,7 +701,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.fd > 0 && dup2(state.fd, 2) == -1) {
 		close_low_fds(True); /* Close stderr too, if dup2 can't point it
 					at the logfile */
 	}
@@ -718,7 +730,7 @@ bool need_to_check_log_size( void )
 		return( False );
 
 	maxlog = lp_max_log_size() * 1024;
-	if( !dbf || maxlog <= 0 ) {
+	if ( state.fd > 0 || maxlog <= 0 ) {
 		debug_count = 0;
 		return(False);
 	}
@@ -747,10 +759,10 @@ void check_log_size( void )
 
 	maxlog = lp_max_log_size() * 1024;
 
-	if(sys_fstat(x_fileno(dbf), &st, false) == 0
+	if(sys_fstat(state.fd, &st, false) == 0
 	   && st.st_ex_size > maxlog ) {
 		(void)reopen_logs();
-		if( dbf && get_file_size( debugf ) > maxlog ) {
+		if( state.fd > 0 && get_file_size( debugf ) > maxlog ) {
 			char *name = NULL;
 
 			if (asprintf(&name, "%s.old", debugf ) < 0) {
@@ -767,10 +779,10 @@ void check_log_size( void )
 	}
 
 	/*
-	 * Here's where we need to panic if dbf == NULL..
+	 * Here's where we need to panic if state.fd == 0 or -1 (invalid values)
 	 */
 
-	if(dbf == NULL) {
+	if (state.fd <= 0) {
 		/* 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 +790,9 @@ 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) {
+		int fd = open( "/dev/console", O_WRONLY, 0);
+		if (fd != -1) {
+			state.fd = fd;
 			DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n",
 					debugf ));
 		} else {
@@ -804,10 +817,10 @@ void check_log_size( void )
 
 	debug_count++;
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list