s3-libsmbclient Add comments to describe the behaviour of DEBUG()
authorAndrew Bartlett <abartlet@samba.org>
Mon, 1 Nov 2010 09:55:04 +0000 (20:55 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 2 Nov 2010 04:36:04 +0000 (04:36 +0000)
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

source3/include/debug.h
source3/lib/debug.c
source3/libsmb/libsmb_context.c
source3/libsmb/libsmb_setget.c

index 92fa6e61453bbd972180f02eb33eb28e51024abc..328bfb63b98dde4c02283c6b4f1268eaa7e01181 100644 (file)
@@ -274,6 +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
 
index f9f4cae000b1c7994a57cfd46a8dfae021f23733..a97c0bf923729d6800e18106aa714aea8505b965 100644 (file)
@@ -614,6 +614,11 @@ static void debug_close_fd(int 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
index 8e76387346a94b2848f73a1db88ccfafe2c59954..22e0a047172157f20a9f39a1618705409d507197 100644 (file)
@@ -557,9 +557,11 @@ smbc_init_context(SMBCCTX *context)
         
         if (context->internal->debug_stderr) {
             /*
-             * Hmmm... Do we want a unique dbf per-thread? For now, we'll just
-             * leave it up to the user. If any one context spefies debug to
-             * stderr then all will be.
+             * We do not have a unique per-thread debug state? For
+             * now, we'll just leave it up to the user. If any one
+             * context spefies debug to stderr then all will be (and
+             * will stay that way, as it is unsafe to flip back if
+             * stdout is in use for other things)
              */
            setup_logging("libsmbclient", DEBUG_STDERR);
         }
index f2f5aec6c46ff59052a45d4ed5d6cb361efbdb4d..0d260d7cf2939038b1cd63dc195034884dfe6e5f 100644 (file)
@@ -120,10 +120,18 @@ smbc_setTimeout(SMBCCTX *c, int timeout)
 smbc_bool
 smbc_getOptionDebugToStderr(SMBCCTX *c)
 {
-        return c->internal->debug_stderr;
+       /* Because this is a global concept, it is better to check
+        * what is really set, rather than what we wanted set
+        * (particularly as you cannot go back to stdout). */
+        return debug_get_output_is_stderr();
 }
 
-/** Set whether to log to standard error instead of standard output */
+/** Set whether to log to standard error instead of standard output.
+ * This option is 'sticky' - once set to true, it cannot be set to
+ * false again, as it is global to the process, as once we have been
+ * told that it is not safe to safe to write to stdout, we shouldn't
+ * go back as we don't know it was this context that set it that way.
+ */
 void
 smbc_setOptionDebugToStderr(SMBCCTX *c, smbc_bool b)
 {