lib/util: set current_msg_{level,class} also during a DEBUGADD[C]() call
authorStefan Metzmacher <metze@samba.org>
Fri, 26 Apr 2019 11:40:58 +0000 (13:40 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 28 May 2019 07:16:25 +0000 (07:16 +0000)
In some situations we use DEBUGADDC() in order to print out content
without a related debug header line.

This is important with the new per class logfile with:

 log level = 1 dsdb_json_audit:10@/var/log/samba/log.dsdb_json_audit

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13915

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/util/debug.c
lib/util/debug.h

index 23c78ae19c9364feb3a467ffc4294dc6166be5bd..d2fbab12414d5c17c2e6f77f2600ebe5881b9581 100644 (file)
@@ -1479,6 +1479,17 @@ void dbgflush( void )
        bufr_print();
 }
 
+bool dbgsetclass(int level, int cls)
+{
+       /* Set current_msg_level. */
+       current_msg_level = level;
+
+       /* Set current message class */
+       current_msg_class = cls;
+
+       return true;
+}
+
 /***************************************************************************
  Print a Debug Header.
 
@@ -1523,11 +1534,7 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
                return( true );
        }
 
-       /* Set current_msg_level. */
-       current_msg_level = level;
-
-       /* Set current message class */
-       current_msg_class = cls;
+       dbgsetclass(level, cls);
 
        /* Don't print a header if we're logging to stdout. */
        if ( state.logtype != DEBUG_FILE ) {
index 5c56d4fd675e967924c2c43f64d9fbe31c79c579..67dbf3357e36cf808c25d0bb04926095d3e28071 100644 (file)
@@ -45,6 +45,7 @@
 bool dbgtext_va(const char *, va_list ap) PRINTF_ATTRIBUTE(1,0);
 bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
 bool dbghdrclass( int level, int cls, const char *location, const char *func);
+bool dbgsetclass(int level, int cls);
 
 /*
  * Define all new debug classes here. A class is represented by an entry in
@@ -205,12 +206,14 @@ void debuglevel_set_class(size_t idx, int level);
 
 #define DEBUGADD( level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
-         unlikely(debuglevel_get_class(DBGC_CLASS) >= (level)) \
+       unlikely(debuglevel_get_class(DBGC_CLASS) >= (level)) \
+       && (dbgsetclass(level, DBGC_CLASS))                   \
        && (dbgtext body) )
 
 #define DEBUGADDC( dbgc_class, level, body ) \
   (void)( ((level) <= MAX_DEBUG_LEVEL) && \
-          unlikely((debuglevel_get_class(dbgc_class) >= (level))) \
+       unlikely((debuglevel_get_class(dbgc_class) >= (level))) \
+       && (dbgsetclass(level, dbgc_class))                     \
        && (dbgtext body) )
 
 /* Print a separator to the debug log. */