URL: https://github.com/SSSD/sssd/pull/5735 Author: cryptomilk Title: #5735: util: Avoid an extern variable by using sss_chain_id_get() Action: synchronized
To pull the PR as Git branch: git remote add ghsssd https://github.com/SSSD/sssd git fetch ghsssd pull/5735/head:pr5735 git checkout pr5735
From 59958cd245266016255b047397360018929347f1 Mon Sep 17 00:00:00 2001 From: Andreas Schneider <a...@redhat.com> Date: Wed, 4 Aug 2021 09:22:30 +0200 Subject: [PATCH] util: Avoid an extern variable by using sss_chain_id_get() Signed-off-by: Andreas Schneider <a...@redhat.com> --- src/util/debug.c | 19 ++++++++++++++++--- src/util/debug.h | 6 ++++++ src/util/sss_chain_id.c | 41 +++++++++-------------------------------- src/util/sss_chain_id.h | 6 ------ 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/src/util/debug.c b/src/util/debug.c index 61f67b6390..805f3b6235 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -35,6 +35,7 @@ #endif #include "util/util.h" +#include "util/sss_chain_id.h" /* from debug_backtrace.h */ void sss_debug_backtrace_init(void); @@ -50,7 +51,7 @@ int debug_microseconds = SSSDBG_MICROSECONDS_UNRESOLVED; enum sss_logger_t sss_logger = STDERR_LOGGER; const char *debug_log_file = "sssd"; FILE *_sss_debug_file; -uint64_t debug_chain_id; +static uint64_t debug_chain_id; const char *sss_logger_str[] = { [STDERR_LOGGER] = "stderr", @@ -324,8 +325,8 @@ void sss_vdebug_fn(const char *file, sss_debug_backtrace_printf(level, "[%s] [%s] (%#.4x): ", debug_prg_name, function, level); - if (debug_chain_id > 0) { - sss_debug_backtrace_printf(level, "[RID#%lu] ", debug_chain_id); + if (sss_chain_id_get() > 0) { + sss_debug_backtrace_printf(level, "[RID#%lu] ", sss_chain_id_get()); } sss_debug_backtrace_vprintf(level, format, ap); @@ -489,3 +490,15 @@ void _sss_talloc_log_fn(const char *message) { DEBUG(SSSDBG_FATAL_FAILURE, "%s\n", message); } + +uint64_t sss_chain_id_set(uint64_t id) +{ + uint64_t old_id = debug_chain_id; + debug_chain_id = id; + return old_id; +} + +uint64_t sss_chain_id_get(void) +{ + return debug_chain_id; +} diff --git a/src/util/debug.h b/src/util/debug.h index 9d3499dbdf..378ce37e39 100644 --- a/src/util/debug.h +++ b/src/util/debug.h @@ -181,6 +181,12 @@ void sss_debug_fn(const char *file, int level, const char *format, ...) SSS_ATTRIBUTE_PRINTF(5, 6); +/* Explicitly set new chain id. The old id is returned. */ +uint64_t sss_chain_id_set(uint64_t id); + +/* Get the current chain id. */ +uint64_t sss_chain_id_get(void); + #define APPEND_LINE_FEED 0x1 /* can be used as a sss_vdebug_fn() flag */ /* Checks whether level is set in generic debug_level. diff --git a/src/util/sss_chain_id.c b/src/util/sss_chain_id.c index f892e2eb78..472ff94763 100644 --- a/src/util/sss_chain_id.c +++ b/src/util/sss_chain_id.c @@ -23,7 +23,6 @@ #include <tevent.h> #ifdef BUILD_CHAIN_ID -extern uint64_t debug_chain_id; static void sss_chain_id_trace_fde(struct tevent_fd *fde, enum tevent_event_trace_point point, @@ -32,11 +31,11 @@ static void sss_chain_id_trace_fde(struct tevent_fd *fde, switch (point) { case TEVENT_EVENT_TRACE_ATTACH: /* Assign the current chain id when the event is created. */ - tevent_fd_set_tag(fde, debug_chain_id); + tevent_fd_set_tag(fde, sss_chain_id_get()); break; case TEVENT_EVENT_TRACE_BEFORE_HANDLER: /* Set the chain id when a handler is being called. */ - debug_chain_id = tevent_fd_get_tag(fde); + sss_chain_id_set(tevent_fd_get_tag(fde)); break; default: /* Do nothing. */ @@ -51,11 +50,11 @@ static void sss_chain_id_trace_signal(struct tevent_signal *se, switch (point) { case TEVENT_EVENT_TRACE_ATTACH: /* Assign the current chain id when the event is created. */ - tevent_signal_set_tag(se, debug_chain_id); + tevent_signal_set_tag(se, sss_chain_id_get()); break; case TEVENT_EVENT_TRACE_BEFORE_HANDLER: /* Set the chain id when a handler is being called. */ - debug_chain_id = tevent_signal_get_tag(se); + sss_chain_id_set(tevent_signal_get_tag(se)); break; default: /* Do nothing. */ @@ -70,11 +69,11 @@ static void sss_chain_id_trace_timer(struct tevent_timer *timer, switch (point) { case TEVENT_EVENT_TRACE_ATTACH: /* Assign the current chain id when the event is created. */ - tevent_timer_set_tag(timer, debug_chain_id); + tevent_timer_set_tag(timer, sss_chain_id_get()); break; case TEVENT_EVENT_TRACE_BEFORE_HANDLER: /* Set the chain id when a handler is being called. */ - debug_chain_id = tevent_timer_get_tag(timer); + sss_chain_id_set(tevent_timer_get_tag(timer)); break; default: /* Do nothing. */ @@ -89,11 +88,11 @@ static void sss_chain_id_trace_immediate(struct tevent_immediate *im, switch (point) { case TEVENT_EVENT_TRACE_ATTACH: /* Assign the current chain id when the event is created. */ - tevent_immediate_set_tag(im, debug_chain_id); + tevent_immediate_set_tag(im, sss_chain_id_get()); break; case TEVENT_EVENT_TRACE_BEFORE_HANDLER: /* Set the chain id when a handler is being called. */ - debug_chain_id = tevent_immediate_get_tag(im); + sss_chain_id_set(tevent_immediate_get_tag(im)); break; default: /* Do nothing. */ @@ -111,7 +110,7 @@ static void sss_chain_id_trace_loop(enum tevent_trace_point point, * after the event handler was finished, we need to restore chain * id to 0 (out of request). */ - debug_chain_id = 0; + sss_chain_id_set(0); break; default: /* Do nothing. */ @@ -128,18 +127,6 @@ void sss_chain_id_setup(struct tevent_context *ev) tevent_set_trace_immediate_callback(ev, sss_chain_id_trace_immediate, NULL); } -uint64_t sss_chain_id_set(uint64_t id) -{ - uint64_t old_id = debug_chain_id; - debug_chain_id = id; - return old_id; -} - -uint64_t sss_chain_id_get(void) -{ - return debug_chain_id; -} - #else /* BUILD_CHAIN_ID not defined */ void sss_chain_id_setup(struct tevent_context *ev) @@ -147,14 +134,4 @@ void sss_chain_id_setup(struct tevent_context *ev) return; } -uint64_t sss_chain_id_set(uint64_t id) -{ - return 0; -} - -uint64_t sss_chain_id_get(void) -{ - return 0; -} - #endif /* BUILD_CHAIN_ID */ diff --git a/src/util/sss_chain_id.h b/src/util/sss_chain_id.h index b29fad0cb1..675ba93899 100644 --- a/src/util/sss_chain_id.h +++ b/src/util/sss_chain_id.h @@ -26,10 +26,4 @@ /* Setup chain id tracking on tevent context. */ void sss_chain_id_setup(struct tevent_context *ev); -/* Explicitly set new chain id. The old id is returned. */ -uint64_t sss_chain_id_set(uint64_t id); - -/* Get the current chain id. */ -uint64_t sss_chain_id_get(void); - #endif /* _SSS_CHAIN_ID_ */
_______________________________________________ sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/sssd-devel@lists.fedorahosted.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure