mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
systemd: avoid string comparisons on dbus error messages
Add a virDBusErrorIsUnknownMethod helper so that callers don't need todo string comparisons themselves to detect standard error names.
This commit is contained in:
parent
d13b586a91
commit
2d8b59c060
@ -1244,6 +1244,7 @@ virDBusCreateMethod;
|
|||||||
virDBusCreateMethodV;
|
virDBusCreateMethodV;
|
||||||
virDBusCreateReply;
|
virDBusCreateReply;
|
||||||
virDBusCreateReplyV;
|
virDBusCreateReplyV;
|
||||||
|
virDBusErrorIsUnknownMethod;
|
||||||
virDBusGetSessionBus;
|
virDBusGetSessionBus;
|
||||||
virDBusGetSystemBus;
|
virDBusGetSystemBus;
|
||||||
virDBusHasSystemBus;
|
virDBusHasSystemBus;
|
||||||
|
@ -1894,3 +1894,12 @@ void virDBusMessageUnref(DBusMessage *msg ATTRIBUTE_UNUSED)
|
|||||||
/* nothing */
|
/* nothing */
|
||||||
}
|
}
|
||||||
#endif /* ! WITH_DBUS */
|
#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);
|
||||||
|
}
|
||||||
|
@ -74,4 +74,6 @@ void virDBusMessageUnref(DBusMessage *msg);
|
|||||||
|
|
||||||
int virDBusIsServiceEnabled(const char *name);
|
int virDBusIsServiceEnabled(const char *name);
|
||||||
int virDBusIsServiceRegistered(const char *name);
|
int virDBusIsServiceRegistered(const char *name);
|
||||||
|
|
||||||
|
bool virDBusErrorIsUnknownMethod(virErrorPtr err);
|
||||||
#endif /* __VIR_DBUS_H__ */
|
#endif /* __VIR_DBUS_H__ */
|
||||||
|
@ -281,8 +281,7 @@ int virSystemdCreateMachine(const char *name,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (error.level == VIR_ERR_ERROR) {
|
if (error.level == VIR_ERR_ERROR) {
|
||||||
if (STREQ_NULLABLE("org.freedesktop.DBus.Error.UnknownMethod",
|
if (virDBusErrorIsUnknownMethod(&error)) {
|
||||||
error.str1)) {
|
|
||||||
VIR_INFO("CreateMachineWithNetwork isn't supported, switching "
|
VIR_INFO("CreateMachineWithNetwork isn't supported, switching "
|
||||||
"to legacy CreateMachine method for systemd-machined");
|
"to legacy CreateMachine method for systemd-machined");
|
||||||
virResetError(&error);
|
virResetError(&error);
|
||||||
|
Loading…
Reference in New Issue
Block a user