]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nss: Make logging conditional on an envvar
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 18 Jun 2025 06:57:46 +0000 (08:57 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 18 Jul 2025 13:05:41 +0000 (15:05 +0200)
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 <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
docs/nss.rst
tools/nss/libvirt_nss_log.c
tools/nss/libvirt_nss_log.h

index be137d987b17e729d76a95b3b3ec30ec97f92a9d..b84861b1eb0b3256f3f00c7944f99ff789ba02ee 100644 (file)
@@ -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
 ------------
 
index 672a17054200d4877de005f524d41b6fead70fc5..5365cf7a9640dec5ebe9c8999988a0a56e09d7e0 100644 (file)
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
+#include <stdlib.h>
 
 #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);
index d99d88e711652de8c4c30cade9e271795815989b..70a87fec7162fd506cf60066267f9fa22ba937c0 100644 (file)
@@ -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,