render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
43fe83
From 00c107bc1ef5a9ab3ad04f15d87fa529c17efefb Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <00c107bc1ef5a9ab3ad04f15d87fa529c17efefb.1381871412.git.jdenemar@redhat.com>
43fe83
From: "Daniel P. Berrange" <berrange@redhat.com>
43fe83
Date: Mon, 14 Oct 2013 16:45:17 +0100
43fe83
Subject: [PATCH] Allow use of a private dbus bus connection
43fe83
43fe83
For
43fe83
43fe83
  https://bugzilla.redhat.com/show_bug.cgi?id=998365
43fe83
43fe83
The dbus_bus_get() function returns a shared bus connection that
43fe83
all libraries in a process can use. You are forbidden from calling
43fe83
close on this connection though, since you can never know if any
43fe83
other code might be using it.
43fe83
43fe83
Add an option to use private dbus bus connections, if the app
43fe83
wants to be able to close the connection.
43fe83
43fe83
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
43fe83
(cherry picked from commit 0cb774f051a3549dd3968e6f48b36e6f93ac79fc)
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/libvirt_private.syms |  1 +
43fe83
 src/util/virdbus.c       | 16 +++++++++++++++-
43fe83
 src/util/virdbus.h       |  2 ++
43fe83
 3 files changed, 18 insertions(+), 1 deletion(-)
43fe83
43fe83
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
43fe83
index d9561b8..c91a9f9 100644
43fe83
--- a/src/libvirt_private.syms
43fe83
+++ b/src/libvirt_private.syms
43fe83
@@ -1298,6 +1298,7 @@ virDBusHasSystemBus;
43fe83
 virDBusMessageDecode;
43fe83
 virDBusMessageEncode;
43fe83
 virDBusMessageRead;
43fe83
+virDBusSetSharedBus;
43fe83
 
43fe83
 
43fe83
 # util/virdnsmasq.h
43fe83
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
43fe83
index a2c4b4e..bcc5b1c 100644
43fe83
--- a/src/util/virdbus.c
43fe83
+++ b/src/util/virdbus.c
43fe83
@@ -32,6 +32,7 @@
43fe83
 
43fe83
 #ifdef WITH_DBUS
43fe83
 
43fe83
+static bool sharedBus = true;
43fe83
 static DBusConnection *systembus = NULL;
43fe83
 static DBusConnection *sessionbus = NULL;
43fe83
 static virOnceControl systemonce = VIR_ONCE_CONTROL_INITIALIZER;
43fe83
@@ -43,6 +44,11 @@ static dbus_bool_t virDBusAddWatch(DBusWatch *watch, void *data);
43fe83
 static void virDBusRemoveWatch(DBusWatch *watch, void *data);
43fe83
 static void virDBusToggleWatch(DBusWatch *watch, void *data);
43fe83
 
43fe83
+void virDBusSetSharedBus(bool shared)
43fe83
+{
43fe83
+    sharedBus = shared;
43fe83
+}
43fe83
+
43fe83
 static DBusConnection *virDBusBusInit(DBusBusType type, DBusError *dbuserr)
43fe83
 {
43fe83
     DBusConnection *bus;
43fe83
@@ -52,7 +58,10 @@ static DBusConnection *virDBusBusInit(DBusBusType type, DBusError *dbuserr)
43fe83
     dbus_threads_init_default();
43fe83
 
43fe83
     dbus_error_init(dbuserr);
43fe83
-    if (!(bus = dbus_bus_get(type, dbuserr)))
43fe83
+    bus = sharedBus ?
43fe83
+        dbus_bus_get(type, dbuserr) :
43fe83
+        dbus_bus_get_private(type, dbuserr);
43fe83
+    if (!bus)
43fe83
         return NULL;
43fe83
 
43fe83
     dbus_connection_set_exit_on_disconnect(bus, FALSE);
43fe83
@@ -1264,6 +1273,11 @@ int virDBusIsServiceEnabled(const char *name)
43fe83
 
43fe83
 
43fe83
 #else /* ! WITH_DBUS */
43fe83
+void virDBusSetSharedBus(bool shared ATTRIBUTE_UNUSED)
43fe83
+{
43fe83
+    /* nothing */
43fe83
+}
43fe83
+
43fe83
 DBusConnection *virDBusGetSystemBus(void)
43fe83
 {
43fe83
     virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
diff --git a/src/util/virdbus.h b/src/util/virdbus.h
43fe83
index 194a01a..125a405 100644
43fe83
--- a/src/util/virdbus.h
43fe83
+++ b/src/util/virdbus.h
43fe83
@@ -31,6 +31,8 @@
43fe83
 # endif
43fe83
 # include "internal.h"
43fe83
 
43fe83
+void virDBusSetSharedBus(bool shared);
43fe83
+
43fe83
 DBusConnection *virDBusGetSystemBus(void);
43fe83
 bool virDBusHasSystemBus(void);
43fe83
 DBusConnection *virDBusGetSessionBus(void);
43fe83
-- 
43fe83
1.8.3.2
43fe83