From 8bc13b261478537c874ed2ce92c5563b49d4d74c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 26 Apr 2019 13:21:15 +0200 Subject: [PATCH 1/3] lib/util: fix call to dbghdrclass() for DEBUGC() dbghdrclass() sets the global 'current_msg_class' and for that DEBUGC() should pass the given dbgc_class instead of the per file DBGC_CLASS. This is important with the new per class logfile with: log level = 1 dsdb_audit:10@/var/log/samba/log.dsdb_audit BUG: https://bugzilla.samba.org/show_bug.cgi?id=13915 Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme (cherry picked from commit bb0ffbf38cb1955c9e400003add680eabcf706a6) --- lib/util/debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/debug.h b/lib/util/debug.h index e6f54a7657f0..bd85067dd4be 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -201,7 +201,7 @@ void debuglevel_set_class(size_t idx, int level); #define DEBUGC( dbgc_class, level, body ) \ (void)( ((level) <= MAX_DEBUG_LEVEL) && \ unlikely(debuglevel_get_class(dbgc_class) >= (level)) \ - && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \ + && (dbghdrclass( level, dbgc_class, __location__, __FUNCTION__ )) \ && (dbgtext body) ) #define DEBUGADD( level, body ) \ -- 2.17.1 From bdfeadfeda555ce54029c000b1f4084fb7c669f5 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 26 Apr 2019 13:32:43 +0200 Subject: [PATCH 2/3] lib/util: remove unused prototypes in debug.h BUG: https://bugzilla.samba.org/show_bug.cgi?id=13915 Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme (cherry picked from commit d98a971247450d494c581c5454e6c270ad1b6880) --- lib/util/debug.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/util/debug.h b/lib/util/debug.h index bd85067dd4be..5c56d4fd675e 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -45,7 +45,6 @@ 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 dbghdr( int level, const char *location, const char *func); /* * Define all new debug classes here. A class is represented by an entry in @@ -318,7 +317,6 @@ void force_check_log_size( void ); bool need_to_check_log_size( void ); void check_log_size( void ); void dbgflush( void ); -bool dbghdrclass(int level, int cls, const char *location, const char *func); bool debug_get_output_is_stderr(void); bool debug_get_output_is_stdout(void); void debug_schedule_reopen_logs(void); -- 2.17.1 From c2f5aebe665b2cdd9f1259f91c8a55efc3323e24 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 26 Apr 2019 13:40:58 +0200 Subject: [PATCH 3/3] lib/util: set current_msg_{level,class} also during a DEBUGADD[C]() call 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 Reviewed-by: Ralph Boehme (cherry picked from commit 0da12ff93d213ac742eeb865bfa5697ca8a2280a) --- lib/util/debug.c | 17 ++++++++++++----- lib/util/debug.h | 7 +++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/util/debug.c b/lib/util/debug.c index 7f3d13da53c6..38df787c658c 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -1475,6 +1475,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. @@ -1519,11 +1530,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 ) { diff --git a/lib/util/debug.h b/lib/util/debug.h index 5c56d4fd675e..67dbf3357e36 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -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. */ -- 2.17.1