From: Pavel Filipenský Date: Sun, 8 May 2022 19:06:13 +0000 (+0200) Subject: debug: add debug_traceid_set/get() interface X-Git-Tag: talloc-2.3.4~207 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e48fc192d24a53db4209de262caec4d5b491952e;p=thirdparty%2Fsamba.git debug: add debug_traceid_set/get() interface Signed-off-by: Pavel Filipenský Reviewed-by: Andreas Schneider Reviewed-by: Jeremy Allison --- diff --git a/lib/util/debug.c b/lib/util/debug.c index 4143cb6058a..42f408736ff 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -1796,11 +1796,21 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func) sizeof(state.header_str) - state.hs_len, ", class=%s", classname_table[cls]); + if (state.hs_len >= sizeof(state.header_str) - 1) { + goto full; + } } - if (state.hs_len >= sizeof(state.header_str) - 1) { - goto full; + if (debug_traceid_get() != 0) { + state.hs_len += snprintf(state.header_str + state.hs_len, + sizeof(state.header_str) - state.hs_len, + ", traceid=%" PRIu64, + debug_traceid_get()); + if (state.hs_len >= sizeof(state.header_str) - 1) { + goto full; + } } + state.header_str[state.hs_len] = ']'; state.hs_len++; if (state.hs_len < sizeof(state.header_str) - 1) { @@ -1884,3 +1894,17 @@ bool dbgtext(const char *format_str, ... ) return ret; } + +static uint64_t debug_traceid = 0; + +uint64_t debug_traceid_set(uint64_t id) +{ + uint64_t old_id = debug_traceid; + debug_traceid = id; + return old_id; +} + +uint64_t debug_traceid_get(void) +{ + return debug_traceid; +} diff --git a/lib/util/debug.h b/lib/util/debug.h index e356e065811..5f4833b0fcd 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -23,6 +23,7 @@ #ifndef _SAMBA_DEBUG_H #define _SAMBA_DEBUG_H +#include #include #include #include @@ -338,4 +339,10 @@ void debug_set_callback(void *private_ptr, debug_callback_fn fn); char *debug_get_ringbuf(void); size_t debug_get_ringbuf_size(void); +/* Explicitly set new traceid. The old id is returned. */ +uint64_t debug_traceid_set(uint64_t id); + +/* Get the current traceid. */ +uint64_t debug_traceid_get(void); + #endif /* _SAMBA_DEBUG_H */