From cf6d38177fd9e25e3cf0b8b0047bd95e80164ec4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 9 Nov 2022 15:54:35 +0100 Subject: glib-aux: drop duplicate _nm_dbus_error_has_name() for nm_dbus_error_is() --- src/core/nm-dispatcher.c | 2 +- src/core/supplicant/nm-supplicant-interface.c | 2 +- src/core/supplicant/nm-supplicant-manager.c | 4 +-- src/libnm-glib-aux/nm-dbus-aux.c | 42 ++++++--------------------- src/libnm-glib-aux/nm-dbus-aux.h | 2 -- 5 files changed, 13 insertions(+), 39 deletions(-) diff --git a/src/core/nm-dispatcher.c b/src/core/nm-dispatcher.c index d6dd9bfa9d..ab361faa7b 100644 --- a/src/core/nm-dispatcher.c +++ b/src/core/nm-dispatcher.c @@ -429,7 +429,7 @@ dispatcher_done_cb(GObject *source, GAsyncResult *result, gpointer user_data) if (!ret) { NMLogLevel log_level = LOGL_DEBUG; - if (_nm_dbus_error_has_name(error, "org.freedesktop.systemd1.LoadFailed")) { + if (nm_dbus_error_is(error, "org.freedesktop.systemd1.LoadFailed")) { g_dbus_error_strip_remote_error(error); log_level = LOGL_WARN; } diff --git a/src/core/supplicant/nm-supplicant-interface.c b/src/core/supplicant/nm-supplicant-interface.c index 5b5d86229c..18525724f4 100644 --- a/src/core/supplicant/nm-supplicant-interface.c +++ b/src/core/supplicant/nm-supplicant-interface.c @@ -2647,7 +2647,7 @@ scan_request_cb(GObject *source, GAsyncResult *result, gpointer user_data) _LOGD("request-scan: request cancelled"); else { if (error) { - if (_nm_dbus_error_has_name(error, "fi.w1.wpa_supplicant1.Interface.ScanError")) + if (nm_dbus_error_is(error, "fi.w1.wpa_supplicant1.Interface.ScanError")) _LOGD("request-scan: could not get scan request result: %s", error->message); else { g_dbus_error_strip_remote_error(error); diff --git a/src/core/supplicant/nm-supplicant-manager.c b/src/core/supplicant/nm-supplicant-manager.c index 2ec7db237a..f6927500dd 100644 --- a/src/core/supplicant/nm-supplicant-manager.c +++ b/src/core/supplicant/nm-supplicant-manager.c @@ -450,7 +450,7 @@ _create_iface_dbus_call_get_interface_cb(GObject *source, GAsyncResult *result, char ifname[NMP_IFNAMSIZ]; if (handle->create_iface_try_count < CREATE_IFACE_TRY_COUNT_MAX - && _nm_dbus_error_has_name(error, NM_WPAS_ERROR_UNKNOWN_IFACE) + && nm_dbus_error_is(error, NM_WPAS_ERROR_UNKNOWN_IFACE) && nm_platform_if_indextoname(NM_PLATFORM_GET, handle->ifindex, ifname)) { /* Before, supplicant told us the interface existed. Was there a race? * Try again. */ @@ -500,7 +500,7 @@ _create_iface_dbus_call_create_interface_cb(GObject *source, nm_assert(handle->self); TRUE; }) - && _nm_dbus_error_has_name(error, NM_WPAS_ERROR_EXISTS_ERROR) + && nm_dbus_error_is(error, NM_WPAS_ERROR_EXISTS_ERROR) && nm_platform_if_indextoname(NM_PLATFORM_GET, handle->ifindex, ifname)) { self = handle->self; _LOGT("create-iface[" NM_HASH_OBFUSCATE_PTR_FMT diff --git a/src/libnm-glib-aux/nm-dbus-aux.c b/src/libnm-glib-aux/nm-dbus-aux.c index 32e87fe0ee..ffa0f84035 100644 --- a/src/libnm-glib-aux/nm-dbus-aux.c +++ b/src/libnm-glib-aux/nm-dbus-aux.c @@ -414,6 +414,12 @@ _nm_dbus_error_is(GError *error, ...) gs_free char *dbus_error = NULL; const char *name; va_list ap; + gboolean found = FALSE; + + /* This should only be used for "foreign" D-Bus errors (eg, errors + * from BlueZ or wpa_supplicant). All NetworkManager D-Bus errors + * should be properly mapped by gdbus to one of the domains/codes in + * nm-errors.h. */ dbus_error = g_dbus_error_get_remote_error(error); if (!dbus_error) @@ -422,13 +428,13 @@ _nm_dbus_error_is(GError *error, ...) va_start(ap, error); while ((name = va_arg(ap, const char *))) { if (nm_streq(dbus_error, name)) { - va_end(ap); - return TRUE; + found = TRUE; + break; } } va_end(ap); - return FALSE; + return found; } /*****************************************************************************/ @@ -731,33 +737,3 @@ _nm_dbus_connection_call_finish(GDBusConnection *dbus_connection, nm_clear_pointer(&variant, g_variant_unref); return variant; } - -/** - * _nm_dbus_error_has_name: - * @error: (allow-none): a #GError, or %NULL - * @dbus_error_name: a D-Bus error name - * - * Checks if @error is set and corresponds to the D-Bus error @dbus_error_name. - * - * This should only be used for "foreign" D-Bus errors (eg, errors - * from BlueZ or wpa_supplicant). All NetworkManager D-Bus errors - * should be properly mapped by gdbus to one of the domains/codes in - * nm-errors.h. - * - * Returns: %TRUE or %FALSE - */ -gboolean -_nm_dbus_error_has_name(GError *error, const char *dbus_error_name) -{ - gboolean has_name = FALSE; - - if (error && g_dbus_error_is_remote_error(error)) { - char *error_name; - - error_name = g_dbus_error_get_remote_error(error); - has_name = !g_strcmp0(error_name, dbus_error_name); - g_free(error_name); - } - - return has_name; -} diff --git a/src/libnm-glib-aux/nm-dbus-aux.h b/src/libnm-glib-aux/nm-dbus-aux.h index dbc0e6e257..f7fc4294ae 100644 --- a/src/libnm-glib-aux/nm-dbus-aux.h +++ b/src/libnm-glib-aux/nm-dbus-aux.h @@ -312,6 +312,4 @@ GVariant *_nm_dbus_connection_call_finish(GDBusConnection *dbus_connection, const GVariantType *reply_type, GError **error); -gboolean _nm_dbus_error_has_name(GError *error, const char *dbus_error_name); - #endif /* __NM_DBUS_AUX_H__ */ -- cgit v1.2.1