]> xenbits.xensource.com Git - libvirt.git/commitdiff
Allow use of a private dbus bus connection
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 11 Oct 2013 14:28:39 +0000 (15:28 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 14 Oct 2013 09:31:01 +0000 (10:31 +0100)
The dbus_bus_get() function returns a shared bus connection that
all libraries in a process can use. You are forbidden from calling
close on this connection though, since you can never know if any
other code might be using it.

Add an option to use private dbus bus connections, if the app
wants to be able to close the connection.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/libvirt_private.syms
src/util/virdbus.c
src/util/virdbus.h

index 844ca29d7abeee99047cd2b015768b4b212a9f5e..b2b1fa811bc40693f2cd8ec7f395c642e0114e96 100644 (file)
@@ -1108,6 +1108,7 @@ virDBusHasSystemBus;
 virDBusMessageDecode;
 virDBusMessageEncode;
 virDBusMessageRead;
+virDBusSetSharedBus;
 
 
 # util/virdnsmasq.h
index 3bd339a9d79704d41e0f426daec55ff459e998b7..3c6007eb5aaac47fe36d39ef1a93756e8f84e121 100644 (file)
@@ -32,6 +32,7 @@
 
 #ifdef WITH_DBUS
 
+static bool sharedBus = true;
 static DBusConnection *systembus = NULL;
 static DBusConnection *sessionbus = NULL;
 static virOnceControl systemonce = VIR_ONCE_CONTROL_INITIALIZER;
@@ -43,6 +44,11 @@ static dbus_bool_t virDBusAddWatch(DBusWatch *watch, void *data);
 static void virDBusRemoveWatch(DBusWatch *watch, void *data);
 static void virDBusToggleWatch(DBusWatch *watch, void *data);
 
+void virDBusSetSharedBus(bool shared)
+{
+    sharedBus = shared;
+}
+
 static DBusConnection *virDBusBusInit(DBusBusType type, DBusError *dbuserr)
 {
     DBusConnection *bus;
@@ -52,7 +58,10 @@ static DBusConnection *virDBusBusInit(DBusBusType type, DBusError *dbuserr)
     dbus_threads_init_default();
 
     dbus_error_init(dbuserr);
-    if (!(bus = dbus_bus_get(type, dbuserr)))
+    bus = sharedBus ?
+        dbus_bus_get(type, dbuserr) :
+        dbus_bus_get_private(type, dbuserr);
+    if (!bus)
         return NULL;
 
     dbus_connection_set_exit_on_disconnect(bus, FALSE);
@@ -1281,6 +1290,11 @@ int virDBusIsServiceEnabled(const char *name)
 
 
 #else /* ! WITH_DBUS */
+void virDBusSetSharedBus(bool shared ATTRIBUTE_UNUSED)
+{
+    /* nothing */
+}
+
 DBusConnection *virDBusGetSystemBus(void)
 {
     virReportError(VIR_ERR_INTERNAL_ERROR,
index 194a01abbad7d9f3fd5d40ec57084fc258e167cf..125a405f06d7bbaba5bdf041a867ec4780a30909 100644 (file)
@@ -31,6 +31,8 @@
 # endif
 # include "internal.h"
 
+void virDBusSetSharedBus(bool shared);
+
 DBusConnection *virDBusGetSystemBus(void);
 bool virDBusHasSystemBus(void);
 DBusConnection *virDBusGetSessionBus(void);