From 9787ec52773ee92de105e8d140a2659aa885d044 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 19 Jun 2025 10:42:46 +0200 Subject: [PATCH] nss: Include filename in debug printings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- tools/nss/libvirt_nss_log.c | 7 ++++++- tools/nss/libvirt_nss_log.h | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/nss/libvirt_nss_log.c b/tools/nss/libvirt_nss_log.c index 5365cf7a96..cf764adafc 100644 --- a/tools/nss/libvirt_nss_log.c +++ b/tools/nss/libvirt_nss_log.c @@ -35,6 +35,7 @@ nssLogPriorityToString(nssLogPriority prio) void nssLog(nssLogPriority prio, + const char *filename, const char *func, int linenr, const char *fmt, ...) @@ -47,7 +48,11 @@ nssLog(nssLogPriority prio, if (!getenv(NSS_LOG_ENV_VAR)) return; - fprintf(stderr, "%s %s:%d : ", nssLogPriorityToString(prio), func, linenr); + if ((filename = strrchr(filename, '/'))) + filename++; + + fprintf(stderr, "%s %s:%s():%d : ", + nssLogPriorityToString(prio), NULLSTR(filename), func, linenr); va_start(ap, fmt); vfprintf(stderr, fmt, ap); diff --git a/tools/nss/libvirt_nss_log.h b/tools/nss/libvirt_nss_log.h index 70a87fec71..c5bddd0eb5 100644 --- a/tools/nss/libvirt_nss_log.h +++ b/tools/nss/libvirt_nss_log.h @@ -13,15 +13,16 @@ typedef enum { } nssLogPriority; #define DEBUG(...) \ - nssLog(NSS_DEBUG, __FUNCTION__, __LINE__, __VA_ARGS__) + nssLog(NSS_DEBUG, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) #define ERROR(...) \ - nssLog(NSS_ERROR, __FUNCTION__, __LINE__, __VA_ARGS__) + nssLog(NSS_ERROR, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) #define NSS_LOG_ENV_VAR "LIBVIRT_NSS_DEBUG" void nssLog(nssLogPriority prio, + const char *filename, const char *func, int linenr, - const char *fmt, ...) __attribute__ ((format(printf, 4, 5))); + const char *fmt, ...) __attribute__ ((format(printf, 5, 6))); -- 2.47.2