lib/util/debug: with log level = 10 we should be more verbose
[metze/samba/wip.git] / lib / util / debug.c
index d2f3d922aec7096adacfe97c25e3173cef3c4db0..2812136a210b5eab5ad60494ff5d7602c47e87d6 100644 (file)
@@ -91,7 +91,8 @@ static struct {
 } state = {
        .settings = {
                .timestamp_logs = true
-       }
+       },
+       .fd = 2 /* stderr by default */
 };
 
 /* -------------------------------------------------------------------------- **
@@ -202,7 +203,7 @@ void gfree_debugsyms(void)
 
        TALLOC_FREE(format_bufr);
 
-       debug_num_classes = DBGC_MAX_FIXED;
+       debug_num_classes = 0;
 
        state.initialized = false;
 }
@@ -255,6 +256,7 @@ int debug_add_class(const char *classname)
        int ndx;
        int *new_class_list;
        char **new_name_list;
+       int default_level;
 
        if (!classname)
                return -1;
@@ -274,12 +276,14 @@ int debug_add_class(const char *classname)
                new_class_list = DEBUGLEVEL_CLASS;
        }
 
+       default_level = DEBUGLEVEL_CLASS[DBGC_ALL];
+
        new_class_list = talloc_realloc(NULL, new_class_list, int, ndx + 1);
        if (!new_class_list)
                return -1;
        DEBUGLEVEL_CLASS = new_class_list;
 
-       DEBUGLEVEL_CLASS[ndx] = DEBUGLEVEL_CLASS[DBGC_ALL];
+       DEBUGLEVEL_CLASS[ndx] = default_level;
 
        new_name_list = talloc_realloc(NULL, classname_table, char *, ndx + 1);
        if (!new_name_list)
@@ -490,6 +494,10 @@ void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
 
 void debug_set_logfile(const char *name)
 {
+       if (name == NULL || *name == 0) {
+               /* this copes with calls when smb.conf is not loaded yet */
+               return;
+       }
        TALLOC_FREE(state.debugf);
        state.debugf = talloc_strdup(NULL, name);
 }
@@ -506,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
@@ -534,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;
@@ -561,7 +575,7 @@ bool reopen_logs_internal(void)
 
        if (new_fd == -1) {
                log_overflow = true;
-               DEBUG(0, ("Unable to open new log file %s: %s\n", state.debugf, strerror(errno)));
+               DEBUG(0, ("Unable to open new log file '%s': %s\n", state.debugf, strerror(errno)));
                log_overflow = false;
                ret = false;
        } else {
@@ -636,7 +650,12 @@ void check_log_size( void )
         *  loop check do a new check as root.
         */
 
-       if( geteuid() != 0) {
+#if _SAMBA_BUILD_ == 3
+       if (geteuid() != sec_initial_uid())
+#else
+       if( geteuid() != 0)
+#endif
+       {
                /* We don't check sec_initial_uid() here as it isn't
                 * available in common code and we don't generally
                 * want to rotate and the possibly lose logs in
@@ -929,10 +948,10 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
 
                header_str[0] = '\0';
 
-               if( state.settings.debug_pid)
+               if (level >= 10 && state.settings.debug_pid)
                        slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)getpid());
 
-               if( state.settings.debug_uid) {
+               if (level >= 10 && state.settings.debug_uid) {
                        size_t hs_len = strlen(header_str);
                        slprintf(header_str + hs_len,
                        sizeof(header_str) - 1 - hs_len,
@@ -941,7 +960,7 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
                                (unsigned int)getuid(), (unsigned int)getgid());
                }
 
-               if (state.settings.debug_class && (cls != DBGC_ALL)) {
+               if (level >= 10 && state.settings.debug_class && (cls != DBGC_ALL)) {
                        size_t hs_len = strlen(header_str);
                        slprintf(header_str + hs_len,
                                 sizeof(header_str) -1 - hs_len,