]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
remote_daemon: Silence DBus errors
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 12 Feb 2025 11:25:42 +0000 (12:25 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 13 Feb 2025 14:20:34 +0000 (15:20 +0100)
When a daemon (like libvirtd, virtqemud, etc.) is started as an
unprivileged user (which is exactly how KubeVirt does it), then
it tries to register on both session and system DBus-es so that
it can shut itself down (e.g. when system is powering off or user
logs out). It's worth noting that this is just opportunistic and
if no DBus is available then no error is reported.

Or at least that's what we thought. Because the way our
virGDBusGetSessionBus() and virGDBusGetSystemBus() are written an
error is actually reported every time the daemon starts.

Use virGDBusHasSessionBus() and virGDBusHasSystemBus() to check
if corresponding bus is available.

Resolves: https://issues.redhat.com/browse/RHEL-79088
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
src/remote/remote_daemon.c

index d44a36500080ebae4049013a6c0347eb1988a002..d90355c0d26aa39f51517284edf2361ac311b9a0 100644 (file)
@@ -631,23 +631,27 @@ static void daemonRunStateInit(void *opaque)
     /* Tie the non-privileged daemons to the session/shutdown lifecycle */
     if (!virNetDaemonIsPrivileged(dmn)) {
 
-        sessionBus = virGDBusGetSessionBus();
-        if (sessionBus != NULL)
-            g_dbus_connection_add_filter(sessionBus,
-                                         handleSessionMessageFunc, dmn, NULL);
-
-        systemBus = virGDBusGetSystemBus();
-        if (systemBus != NULL)
-            g_dbus_connection_signal_subscribe(systemBus,
-                                               "org.freedesktop.login1",
-                                               "org.freedesktop.login1.Manager",
-                                               "PrepareForShutdown",
-                                               NULL,
-                                               NULL,
-                                               G_DBUS_SIGNAL_FLAGS_NONE,
-                                               handleSystemMessageFunc,
-                                               dmn,
-                                               NULL);
+        if (virGDBusHasSessionBus()) {
+            sessionBus = virGDBusGetSessionBus();
+            if (sessionBus != NULL)
+                g_dbus_connection_add_filter(sessionBus,
+                                             handleSessionMessageFunc, dmn, NULL);
+        }
+
+        if (virGDBusHasSystemBus()) {
+            systemBus = virGDBusGetSystemBus();
+            if (systemBus != NULL)
+                g_dbus_connection_signal_subscribe(systemBus,
+                                                   "org.freedesktop.login1",
+                                                   "org.freedesktop.login1.Manager",
+                                                   "PrepareForShutdown",
+                                                   NULL,
+                                                   NULL,
+                                                   G_DBUS_SIGNAL_FLAGS_NONE,
+                                                   handleSystemMessageFunc,
+                                                   dmn,
+                                                   NULL);
+        }
     }
 
     /* Only now accept clients from network */