diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a958d94436..c25a61fe8b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1294,6 +1294,7 @@ virConfWriteMem; virDBusCallMethod; virDBusGetSessionBus; virDBusGetSystemBus; +virDBusHasSystemBus; virDBusMessageDecode; virDBusMessageEncode; virDBusMessageRead; diff --git a/src/util/virdbus.c b/src/util/virdbus.c index e88dc267b9..62c31bea81 100644 --- a/src/util/virdbus.c +++ b/src/util/virdbus.c @@ -73,7 +73,8 @@ static void virDBusSystemBusInit(void) systembus = virDBusBusInit(DBUS_BUS_SYSTEM, &systemdbuserr); } -DBusConnection *virDBusGetSystemBus(void) +static DBusConnection * +virDBusGetSystemBusInternal(void) { if (virOnce(&systemonce, virDBusSystemBusInit) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -81,14 +82,34 @@ DBusConnection *virDBusGetSystemBus(void) return NULL; } - if (!systembus) { + return systembus; +} + + +DBusConnection * +virDBusGetSystemBus(void) +{ + DBusConnection *bus; + + if (!(bus = virDBusGetSystemBusInternal())) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to get DBus system bus connection: %s"), systemdbuserr.message ? systemdbuserr.message : "watch setup failed"); return NULL; } - return systembus; + return bus; +} + + +bool +virDBusHasSystemBus(void) +{ + if (virDBusGetSystemBusInternal()) + return true; + + VIR_DEBUG("System DBus not available: %s", NULLSTR(systemdbuserr.message)); + return false; } @@ -1195,6 +1216,15 @@ DBusConnection *virDBusGetSystemBus(void) return NULL; } + +bool +virDBusHasSystemBus(void) +{ + VIR_DEBUG("DBus support not compiled into this binary"); + return false; +} + + DBusConnection *virDBusGetSessionBus(void) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/util/virdbus.h b/src/util/virdbus.h index 39de479ff9..a5aab568f6 100644 --- a/src/util/virdbus.h +++ b/src/util/virdbus.h @@ -32,6 +32,7 @@ # include "internal.h" DBusConnection *virDBusGetSystemBus(void); +bool virDBusHasSystemBus(void); DBusConnection *virDBusGetSessionBus(void); int virDBusCallMethod(DBusConnection *conn,