
On Mon, Aug 19, 2013 at 12:32:05PM +0200, Peter Krempa wrote:
Some systems may not use DBus in their system. Add a method to check if the system bus is available that doesn't print error messages so that code can later check for this condition and use an alternative approach. --- src/libvirt_private.syms | 1 + src/util/virdbus.c | 34 +++++++++++++++++++++++++++++++--- src/util/virdbus.h | 1 + 3 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a958d94..c25a61f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1294,6 +1294,7 @@ virConfWriteMem; virDBusCallMethod; virDBusGetSessionBus; virDBusGetSystemBus; +virDBusHasSystemBus; virDBusMessageDecode; virDBusMessageEncode; virDBusMessageRead; diff --git a/src/util/virdbus.c b/src/util/virdbus.c index e88dc26..1ef78ce 100644 --- a/src/util/virdbus.c +++ b/src/util/virdbus.c @@ -73,7 +73,8 @@ static void virDBusSystemBusInit(void) systembus = virDBusBusInit(DBUS_BUS_SYSTEM, &systemdbuserr); }
-DBusConnection *virDBusGetSystemBus(void) +static DBusConnection +*virDBusGetSystemBusInternal(void) { if (virOnce(&systemonce, virDBusSystemBusInit) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -81,14 +82,33 @@ DBusConnection *virDBusGetSystemBus(void) return NULL; }
- if (!systembus) { + return systembus; +} + + +DBusConnection *virDBusGetSystemBus(void) +{ + DBusConnection *bus; + + if (!(bus = virDBusGetSystemBusInternal())) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to get DBus system bus connection: %s"), systemdbuserr.message ? systemdbuserr.message : "watch setup failed"); return NULL; }
- return systembus; + return bus; +} + + +DBusConnection *virDBusHasSystemBus(void) +{ + DBusConnection *bus; + + if (!(bus = virDBusGetSystemBusInternal())) + VIR_DEBUG("System DBus not available: %s", NULLSTR(systemdbuserr.message)); + + return bus; }
@@ -1195,6 +1215,14 @@ DBusConnection *virDBusGetSystemBus(void) return NULL; }
+ +DBusConnection *virDBusHasSystemBus(void) +{ + VIR_DEBUG("DBus support not compiled into this binary"); + return NULL; +} + + DBusConnection *virDBusGetSessionBus(void) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/util/virdbus.h b/src/util/virdbus.h index 39de479..63908fe 100644 --- a/src/util/virdbus.h +++ b/src/util/virdbus.h @@ -32,6 +32,7 @@ # include "internal.h"
DBusConnection *virDBusGetSystemBus(void); +DBusConnection *virDBusHasSystemBus(void);
This should be a returning a 'bool' IMHO. eg usage would be if (virDBusHasSystemBus()) { DBusConnection conn = virDBusGetSystemBus() ....dbus code path... } else { ... non-dbus code path... } Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|