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 <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Michal Privoznik 2025-02-12 12:25:42 +01:00
parent 0428c69b09
commit 715bfc5e54

View 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);
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 */