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(a)redhat.com>
---
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 */
--
2.45.3