]> xenbits.xensource.com Git - libvirt.git/commitdiff
systemd: avoid string comparisons on dbus error messages
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 22 Jan 2015 16:50:33 +0000 (16:50 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 26 Jan 2015 09:14:04 +0000 (09:14 +0000)
Add a virDBusErrorIsUnknownMethod helper so that callers
don't need todo string comparisons themselves to detect
standard error names.

src/libvirt_private.syms
src/util/virdbus.c
src/util/virdbus.h
src/util/virsystemd.c

index 528e93c20ea94b64cb0eb35445a1f79f8815f3df..a8cd87f7ff76f12a88a676464715a5168acfec70 100644 (file)
@@ -1244,6 +1244,7 @@ virDBusCreateMethod;
 virDBusCreateMethodV;
 virDBusCreateReply;
 virDBusCreateReplyV;
+virDBusErrorIsUnknownMethod;
 virDBusGetSessionBus;
 virDBusGetSystemBus;
 virDBusHasSystemBus;
index 3522ae02e2bc256616ff8aaa68ad5a38b125f628..1cf1eef39ad84f8ec7760690b2a4770c238636c1 100644 (file)
@@ -1894,3 +1894,12 @@ void virDBusMessageUnref(DBusMessage *msg ATTRIBUTE_UNUSED)
     /* nothing */
 }
 #endif /* ! WITH_DBUS */
+
+bool virDBusErrorIsUnknownMethod(virErrorPtr err)
+{
+    return err->domain == VIR_FROM_DBUS &&
+        err->code == VIR_ERR_DBUS_SERVICE &&
+        err->level == VIR_ERR_ERROR &&
+        STREQ_NULLABLE("org.freedesktop.DBus.Error.UnknownMethod",
+                       err->str1);
+}
index e2b8d2b1bc1f98f038558552051d44fa885b27f9..9e86538d5a7a3ac050d9ede7d3add5892181ca79 100644 (file)
@@ -74,4 +74,6 @@ void virDBusMessageUnref(DBusMessage *msg);
 
 int virDBusIsServiceEnabled(const char *name);
 int virDBusIsServiceRegistered(const char *name);
+
+bool virDBusErrorIsUnknownMethod(virErrorPtr err);
 #endif /* __VIR_DBUS_H__ */
index 6de265be5918552b5534d603fbed38140a957db8..3ac399a1b44bebd43414abb16b94a0d7d82f95e0 100644 (file)
@@ -281,8 +281,7 @@ int virSystemdCreateMachine(const char *name,
             goto cleanup;
 
         if (error.level == VIR_ERR_ERROR) {
-            if (STREQ_NULLABLE("org.freedesktop.DBus.Error.UnknownMethod",
-                               error.str1)) {
+            if (virDBusErrorIsUnknownMethod(&error)) {
                 VIR_INFO("CreateMachineWithNetwork isn't supported, switching "
                          "to legacy CreateMachine method for systemd-machined");
                 virResetError(&error);