mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
Allow use of a private dbus bus connection
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>
This commit is contained in:
parent
2c9ccd1e0c
commit
0cb774f051
@ -1108,6 +1108,7 @@ virDBusHasSystemBus;
|
||||
virDBusMessageDecode;
|
||||
virDBusMessageEncode;
|
||||
virDBusMessageRead;
|
||||
virDBusSetSharedBus;
|
||||
|
||||
|
||||
# util/virdnsmasq.h
|
||||
|
@ -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,
|
||||
|
@ -31,6 +31,8 @@
|
||||
# endif
|
||||
# include "internal.h"
|
||||
|
||||
void virDBusSetSharedBus(bool shared);
|
||||
|
||||
DBusConnection *virDBusGetSystemBus(void);
|
||||
bool virDBusHasSystemBus(void);
|
||||
DBusConnection *virDBusGetSessionBus(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user