URL: https://github.com/SSSD/sssd/pull/5795 Author: justin-stephenson Title: #5795: debug: Add chain ID support for journald logger Action: synchronized
To pull the PR as Git branch: git remote add ghsssd https://github.com/SSSD/sssd git fetch ghsssd pull/5795/head:pr5795 git checkout pr5795
From cf0cb160a26b60b05cb817a74fa3ea9fb5b23f7f Mon Sep 17 00:00:00 2001 From: Justin Stephenson <jstep...@redhat.com> Date: Fri, 24 Sep 2021 16:05:58 +0000 Subject: [PATCH] debug: Add chain ID support for journald logger --- src/util/debug.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/util/debug.c b/src/util/debug.c index 61f67b6390..989589a707 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -36,6 +36,8 @@ #include "util/util.h" +#define DEBUG_CHAIN_ID_FMT "[RID#%lu] " + /* from debug_backtrace.h */ void sss_debug_backtrace_init(void); void sss_debug_backtrace_vprintf(int level, const char *format, va_list ap); @@ -267,6 +269,9 @@ void sss_vdebug_fn(const char *file, const char *format, va_list ap) { + char chain_id_fmt_fixed[256]; + char *chain_id_fmt_dyn = NULL; + char *result_fmt; static time_t last_time; static char last_time_str[128]; struct timeval tv; @@ -287,7 +292,26 @@ void sss_vdebug_fn(const char *file, * searchable. */ va_copy(ap_fallback, ap); - ret = journal_send(file, line, function, level, format, ap); + if (debug_chain_id > 0) { + result_fmt = chain_id_fmt_fixed; + ret = snprintf(chain_id_fmt_fixed, sizeof(chain_id_fmt_fixed), + DEBUG_CHAIN_ID_FMT"%s", debug_chain_id, format); + if (ret < 0) { + return; + } else if (ret >= sizeof(chain_id_fmt_fixed)) { + ret = asprintf(&chain_id_fmt_dyn, DEBUG_CHAIN_ID_FMT"%s", + debug_chain_id, format); + if (ret < 0) { + return; + } + result_fmt = chain_id_fmt_dyn; + } + + ret = journal_send(file, line, function, level, result_fmt, ap); + free(chain_id_fmt_dyn); + } else { + ret = journal_send(file, line, function, level, format, ap); + } if (ret != EOK) { /* Emergency fallback, send to STDERR */ vfprintf(stderr, format, ap_fallback); @@ -325,7 +349,7 @@ void sss_vdebug_fn(const char *file, debug_prg_name, function, level); if (debug_chain_id > 0) { - sss_debug_backtrace_printf(level, "[RID#%lu] ", debug_chain_id); + sss_debug_backtrace_printf(level, DEBUG_CHAIN_ID_FMT, debug_chain_id); } sss_debug_backtrace_vprintf(level, format, ap);
_______________________________________________ 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