]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virdbus: Add virDBusHasSystemBus()
authorPeter Krempa <pkrempa@redhat.com>
Mon, 19 Aug 2013 09:24:04 +0000 (11:24 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 19 Aug 2013 14:27:51 +0000 (16:27 +0200)
Some systems may not use DBus in their system. Add a method to check if
the system bus is available that doesn't print error messages so that
code can later check for this condition and use an alternative approach.

src/libvirt_private.syms
src/util/virdbus.c
src/util/virdbus.h

index a958d94436874c5a20962fba2fd951a5a3a333c4..c25a61fe8bb93c92eca36136395007291fdadc81 100644 (file)
@@ -1294,6 +1294,7 @@ virConfWriteMem;
 virDBusCallMethod;
 virDBusGetSessionBus;
 virDBusGetSystemBus;
+virDBusHasSystemBus;
 virDBusMessageDecode;
 virDBusMessageEncode;
 virDBusMessageRead;
index e88dc267b910e64a617563ce565163556dcd8267..62c31bea810e64caa990c58d2911e35b2cca53f8 100644 (file)
@@ -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,
index 39de479ff9ab0ca05fe7ad9218765958773b9345..a5aab568f65fe4e113fe863d6ac6bb9c94f00ca9 100644 (file)
@@ -32,6 +32,7 @@
 # include "internal.h"
 
 DBusConnection *virDBusGetSystemBus(void);
+bool virDBusHasSystemBus(void);
 DBusConnection *virDBusGetSessionBus(void);
 
 int virDBusCallMethod(DBusConnection *conn,