diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index d25c6f2be0..6602d730b9 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -175,8 +175,9 @@ nwfilterStateInitialize(bool privileged, DBusConnection *sysbus = NULL; #if WITH_DBUS - if (virDBusHasSystemBus()) - sysbus = virDBusGetSystemBus(); + if (virDBusHasSystemBus() && + !(sysbus = virDBusGetSystemBus())) + return -1; #endif /* WITH_DBUS */ if (VIR_ALLOC(driverState) < 0) diff --git a/src/util/virdbus.c b/src/util/virdbus.c index dc4ace0ea4..4e4c267126 100644 --- a/src/util/virdbus.c +++ b/src/util/virdbus.c @@ -111,14 +111,29 @@ virDBusGetSystemBus(void) } +/** + * virDBusHasSystemBus: + * + * Check if dbus system bus is running. This does not + * imply that we have a connection. DBus might be running + * and refusing connections due to its client limit. The + * latter must be treated as a fatal error. + * + * Return false if dbus is not available, true if probably available. + */ bool virDBusHasSystemBus(void) { if (virDBusGetSystemBusInternal()) return true; - VIR_DEBUG("System DBus not available: %s", NULLSTR(systemdbuserr.message)); - return false; + if (systemdbuserr.name && + (STREQ(systemdbuserr.name, "org.freedesktop.DBus.Error.FileNotFound") || + STREQ(systemdbuserr.name, "org.freedesktop.DBus.Error.NoServer"))) { + VIR_DEBUG("System DBus not available: %s", NULLSTR(systemdbuserr.message)); + return false; + } + return true; } @@ -1257,7 +1272,8 @@ int virDBusIsServiceEnabled(const char *name) if (!virDBusHasSystemBus()) return -2; - conn = virDBusGetSystemBus(); + if (!(conn = virDBusGetSystemBus())) + return -1; if (virDBusCallMethod(conn, &reply, diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 1ba37ccdfe..503fff752b 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -169,7 +169,8 @@ int virSystemdCreateMachine(const char *name, if (ret < 0) return ret; - conn = virDBusGetSystemBus(); + if (!(conn = virDBusGetSystemBus())) + return -1; ret = -1; if (!(machinename = virSystemdMakeMachineName(name, drivername, privileged))) @@ -267,7 +268,8 @@ int virSystemdTerminateMachine(const char *name, if (ret < 0) return ret; - conn = virDBusGetSystemBus(); + if (!(conn = virDBusGetSystemBus())) + return -1; ret = -1; if (!(machinename = virSystemdMakeMachineName(name, drivername, privileged)))