From: Michal Privoznik Date: Wed, 18 Jun 2025 06:57:46 +0000 (+0200) Subject: nss: Make logging conditional on an envvar X-Git-Tag: v11.6.0-rc1~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8a911ef9d5012063f4a05a942a5ea1dd6c008a1;p=thirdparty%2Flibvirt.git nss: Make logging conditional on an envvar As promised in previous commit, make NSS modules silent by default and enable debug printings if LIBVIRT_NSS_DEBUG envvar is set. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- diff --git a/docs/nss.rst b/docs/nss.rst index be137d987b..b84861b1eb 100644 --- a/docs/nss.rst +++ b/docs/nss.rst @@ -111,6 +111,19 @@ their IP addresses in any other way (usermode networking, assigned network devices and so on) will not be able to have their hostnames resolved through it. +Debugging +--------- + +:since:`Since 11.6.0` both NSS modules check for ``LIBVIRT_NSS_DEBUG`` +environment variable¸ which if set to any value turns on printing of debug and +error messages onto standard error output. This can be useful when debugging +either of the module. + +:: + + $ LIBVIRT_NSS_DEBUG=1 getent hosts mydomain + + Alternatives ------------ diff --git a/tools/nss/libvirt_nss_log.c b/tools/nss/libvirt_nss_log.c index 672a170542..5365cf7a96 100644 --- a/tools/nss/libvirt_nss_log.c +++ b/tools/nss/libvirt_nss_log.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "libvirt_nss_log.h" #include "libvirt_nss.h" @@ -43,6 +44,9 @@ nssLog(nssLogPriority prio, g_autofree char *ebuf = NULL; va_list ap; + if (!getenv(NSS_LOG_ENV_VAR)) + return; + fprintf(stderr, "%s %s:%d : ", nssLogPriorityToString(prio), func, linenr); va_start(ap, fmt); diff --git a/tools/nss/libvirt_nss_log.h b/tools/nss/libvirt_nss_log.h index d99d88e711..70a87fec71 100644 --- a/tools/nss/libvirt_nss_log.h +++ b/tools/nss/libvirt_nss_log.h @@ -18,6 +18,8 @@ typedef enum { #define ERROR(...) \ nssLog(NSS_ERROR, __FUNCTION__, __LINE__, __VA_ARGS__) +#define NSS_LOG_ENV_VAR "LIBVIRT_NSS_DEBUG" + void nssLog(nssLogPriority prio, const char *func,