render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
43fe83
From 2781384efc02836d14b5f7169ba2c4025fd08144 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <2781384efc02836d14b5f7169ba2c4025fd08144.1381871412.git.jdenemar@redhat.com>
43fe83
From: Peter Krempa <pkrempa@redhat.com>
43fe83
Date: Mon, 14 Oct 2013 16:45:11 +0100
43fe83
Subject: [PATCH] virdbus: Add virDBusHasSystemBus()
43fe83
43fe83
For
43fe83
43fe83
  https://bugzilla.redhat.com/show_bug.cgi?id=1018730
43fe83
43fe83
Some systems may not use DBus in their system. Add a method to check if
43fe83
the system bus is available that doesn't print error messages so that
43fe83
code can later check for this condition and use an alternative approach.
43fe83
43fe83
(cherry picked from commit 2398dd3d3ea2e060318abd3d9346ad65df910803)
43fe83
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/libvirt_private.syms |  1 +
43fe83
 src/util/virdbus.c       | 36 +++++++++++++++++++++++++++++++++---
43fe83
 src/util/virdbus.h       |  1 +
43fe83
 3 files changed, 35 insertions(+), 3 deletions(-)
43fe83
43fe83
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
43fe83
index e6c23e4..47e989c 100644
43fe83
--- a/src/libvirt_private.syms
43fe83
+++ b/src/libvirt_private.syms
43fe83
@@ -1294,6 +1294,7 @@ virConfWriteMem;
43fe83
 virDBusCallMethod;
43fe83
 virDBusGetSessionBus;
43fe83
 virDBusGetSystemBus;
43fe83
+virDBusHasSystemBus;
43fe83
 virDBusMessageDecode;
43fe83
 virDBusMessageEncode;
43fe83
 virDBusMessageRead;
43fe83
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
43fe83
index e88dc26..62c31be 100644
43fe83
--- a/src/util/virdbus.c
43fe83
+++ b/src/util/virdbus.c
43fe83
@@ -73,7 +73,8 @@ static void virDBusSystemBusInit(void)
43fe83
     systembus = virDBusBusInit(DBUS_BUS_SYSTEM, &systemdbuserr);
43fe83
 }
43fe83
 
43fe83
-DBusConnection *virDBusGetSystemBus(void)
43fe83
+static DBusConnection *
43fe83
+virDBusGetSystemBusInternal(void)
43fe83
 {
43fe83
     if (virOnce(&systemonce, virDBusSystemBusInit) < 0) {
43fe83
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
43fe83
@@ -81,14 +82,34 @@ DBusConnection *virDBusGetSystemBus(void)
43fe83
         return NULL;
43fe83
     }
43fe83
 
43fe83
-    if (!systembus) {
43fe83
+    return systembus;
43fe83
+}
43fe83
+
43fe83
+
43fe83
+DBusConnection *
43fe83
+virDBusGetSystemBus(void)
43fe83
+{
43fe83
+    DBusConnection *bus;
43fe83
+
43fe83
+    if (!(bus = virDBusGetSystemBusInternal())) {
43fe83
         virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
                        _("Unable to get DBus system bus connection: %s"),
43fe83
                        systemdbuserr.message ? systemdbuserr.message : "watch setup failed");
43fe83
         return NULL;
43fe83
     }
43fe83
 
43fe83
-    return systembus;
43fe83
+    return bus;
43fe83
+}
43fe83
+
43fe83
+
43fe83
+bool
43fe83
+virDBusHasSystemBus(void)
43fe83
+{
43fe83
+    if (virDBusGetSystemBusInternal())
43fe83
+        return true;
43fe83
+
43fe83
+    VIR_DEBUG("System DBus not available: %s", NULLSTR(systemdbuserr.message));
43fe83
+    return false;
43fe83
 }
43fe83
 
43fe83
 
43fe83
@@ -1195,6 +1216,15 @@ DBusConnection *virDBusGetSystemBus(void)
43fe83
     return NULL;
43fe83
 }
43fe83
 
43fe83
+
43fe83
+bool
43fe83
+virDBusHasSystemBus(void)
43fe83
+{
43fe83
+    VIR_DEBUG("DBus support not compiled into this binary");
43fe83
+    return false;
43fe83
+}
43fe83
+
43fe83
+
43fe83
 DBusConnection *virDBusGetSessionBus(void)
43fe83
 {
43fe83
     virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
diff --git a/src/util/virdbus.h b/src/util/virdbus.h
43fe83
index 39de479..a5aab56 100644
43fe83
--- a/src/util/virdbus.h
43fe83
+++ b/src/util/virdbus.h
43fe83
@@ -32,6 +32,7 @@
43fe83
 # include "internal.h"
43fe83
 
43fe83
 DBusConnection *virDBusGetSystemBus(void);
43fe83
+bool virDBusHasSystemBus(void);
43fe83
 DBusConnection *virDBusGetSessionBus(void);
43fe83
 
43fe83
 int virDBusCallMethod(DBusConnection *conn,
43fe83
-- 
43fe83
1.8.3.2
43fe83