From 715bfc5e5454d1a98fffe00f9ad3803f388d7414 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 12 Feb 2025 12:25:42 +0100 Subject: [PATCH] remote_daemon: Silence DBus errors 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 Reviewed-by: Andrea Bolognani --- src/remote/remote_daemon.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index d44a365000..d90355c0d2 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -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); + if (virGDBusHasSessionBus()) { + 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 (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 */