]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
debug: add debug_traceid_set/get() interface
authorPavel Filipenský <pfilipen@redhat.com>
Sun, 8 May 2022 19:06:13 +0000 (21:06 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 10 May 2022 17:31:31 +0000 (17:31 +0000)
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/debug.c
lib/util/debug.h

index 4143cb6058afc18c36f67ad1cc2601605ac268f3..42f408736ff1d55aabcc1b2c09d122ec5a4f5178 100644 (file)
@@ -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;
+}
index e356e0658114b4d233731addd2bc8db69b2f823b..5f4833b0fcdc0a32fad77c35e62c09d1774feb93 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef _SAMBA_DEBUG_H
 #define _SAMBA_DEBUG_H
 
+#include <stdint.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdarg.h>
@@ -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 */