Blob Blame History Raw
From 00c107bc1ef5a9ab3ad04f15d87fa529c17efefb Mon Sep 17 00:00:00 2001
Message-Id: <00c107bc1ef5a9ab3ad04f15d87fa529c17efefb.1381871412.git.jdenemar@redhat.com>
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Mon, 14 Oct 2013 16:45:17 +0100
Subject: [PATCH] Allow use of a private dbus bus connection

For

  https://bugzilla.redhat.com/show_bug.cgi?id=998365

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>
(cherry picked from commit 0cb774f051a3549dd3968e6f48b36e6f93ac79fc)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 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 d9561b8..c91a9f9 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1298,6 +1298,7 @@ virDBusHasSystemBus;
 virDBusMessageDecode;
 virDBusMessageEncode;
 virDBusMessageRead;
+virDBusSetSharedBus;
 
 
 # util/virdnsmasq.h
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
index a2c4b4e..bcc5b1c 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);
@@ -1264,6 +1273,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.2