[PATCH 1/3] Allow use of a private dbus bus connection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

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@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virdbus.c       | 16 +++++++++++++++-
 src/util/virdbus.h       |  2 ++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 844ca29..b2b1fa8 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1108,6 +1108,7 @@ virDBusHasSystemBus;
 virDBusMessageDecode;
 virDBusMessageEncode;
 virDBusMessageRead;
+virDBusSetSharedBus;
 
 
 # util/virdnsmasq.h
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
index 3bd339a..3c6007e 100644
--- a/src/util/virdbus.c
+++ b/src/util/virdbus.c
@@ -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,
diff --git a/src/util/virdbus.h b/src/util/virdbus.h
index 194a01a..125a405 100644
--- a/src/util/virdbus.h
+++ b/src/util/virdbus.h
@@ -31,6 +31,8 @@
 # endif
 # include "internal.h"
 
+void virDBusSetSharedBus(bool shared);
+
 DBusConnection *virDBusGetSystemBus(void);
 bool virDBusHasSystemBus(void);
 DBusConnection *virDBusGetSessionBus(void);
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]