Add a virDBusErrorIsUnknownMethod helper so that callers
don't need todo string comparisons themselves to detect
standard error names.
---
src/libvirt_private.syms | 1 +
src/util/virdbus.c | 9 +++++++++
src/util/virdbus.h | 2 ++
src/util/virsystemd.c | 3 +--
4 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 528e93c..a8cd87f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1244,6 +1244,7 @@ virDBusCreateMethod;
virDBusCreateMethodV;
virDBusCreateReply;
virDBusCreateReplyV;
+virDBusErrorIsUnknownMethod;
virDBusGetSessionBus;
virDBusGetSystemBus;
virDBusHasSystemBus;
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
index 3522ae0..1cf1eef 100644
--- a/src/util/virdbus.c
+++ b/src/util/virdbus.c
@@ -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);
+}
diff --git a/src/util/virdbus.h b/src/util/virdbus.h
index e2b8d2b..9e86538 100644
--- a/src/util/virdbus.h
+++ b/src/util/virdbus.h
@@ -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__ */
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 6de265b..3ac399a 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -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);
--
2.1.0