]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virinhibitor: Suppress reporting an error when D-Bus is unavailable in virInhibitorAc...
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 10 Apr 2025 08:20:02 +0000 (10:20 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 10 Apr 2025 10:40:38 +0000 (12:40 +0200)
At the beginning of virInhibitorAcquire() the system D-Bus
connection is obtained by calling virGDBusGetSystemBus(). If
there's no D-Bus available then an debug message is printed out
and function returns early. Problem is, in case of no D-Bus an
error message was reported by virGDBusGetSystemBus() and thus
logs were polluted which may mislead users.

Just check whether D-Bus is available first (by calling
virGDBusHasSystemBus()). If it is then virGDBusGetSystemBus()
should return a valid connection. Nevertheless, respect previous
logic and don't propagate error to the caller, just return 0.

Resolves: https://issues.redhat.com/browse/RHEL-79088
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/util/virinhibitor.c

index a95021de5ab92f850f9baa5b32929f23c59a3757..6796938936ea51b6cab98a546fab8de0215523d4 100644 (file)
@@ -70,11 +70,14 @@ virInhibitorAcquire(const char *what,
     VIR_DEBUG("what=%s who=%s why=%s mode=%s",
               NULLSTR(what), NULLSTR(who), NULLSTR(why), NULLSTR(mode));
 
-    if (!(systemBus = virGDBusGetSystemBus())) {
+    if (!virGDBusHasSystemBus()) {
         VIR_DEBUG("system dbus not available, skipping system inhibitor");
         return 0;
     }
 
+    if (!(systemBus = virGDBusGetSystemBus()))
+        return 0;
+
     if (virSystemdHasLogind() < 0) {
         VIR_DEBUG("logind not available, skipping system inhibitor");
         return 0;