From 3ecb57fdc46833f2377fa86e045cd0f8461eaab9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 19 Oct 2017 11:22:14 +0200 Subject: [PATCH] settings: get rid of callback arguments for nm_settings_connection_delete() --- src/devices/bluetooth/nm-bluez-device.c | 2 +- src/nm-checkpoint.c | 2 +- src/nm-manager.c | 6 +- src/settings/nm-settings-connection.c | 57 ++++++------------- src/settings/nm-settings-connection.h | 9 +-- src/settings/nm-settings.c | 2 +- .../plugins/ifupdown/nms-ifupdown-plugin.c | 2 +- 7 files changed, 26 insertions(+), 54 deletions(-) diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c index 573cb44e78..182527d9f5 100644 --- a/src/devices/bluetooth/nm-bluez-device.c +++ b/src/devices/bluetooth/nm-bluez-device.c @@ -1219,7 +1219,7 @@ dispose (GObject *object) if (to_delete) { nm_log_dbg (LOGD_BT, "bluez[%s] removing Bluetooth connection for NAP device: '%s' (%s)", priv->path, nm_connection_get_id (to_delete), nm_connection_get_uuid (to_delete)); - nm_settings_connection_delete (NM_SETTINGS_CONNECTION (to_delete), NULL, NULL); + nm_settings_connection_delete (NM_SETTINGS_CONNECTION (to_delete), NULL); g_object_unref (to_delete); } diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c index 2bf1844e82..028d3b5930 100644 --- a/src/nm-checkpoint.c +++ b/src/nm-checkpoint.c @@ -342,7 +342,7 @@ next_dev: nm_settings_connection_get_uuid (con))) { _LOGD ("rollback: deleting new connection %s", nm_settings_connection_get_uuid (con)); - nm_settings_connection_delete (con, NULL, NULL); + nm_settings_connection_delete (con, NULL); } } } diff --git a/src/nm-manager.c b/src/nm-manager.c index a876fcb119..46756cef7a 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -339,7 +339,7 @@ active_connection_remove (NMManager *self, NMActiveConnection *active) if (nm_settings_has_connection (priv->settings, connection)) { _LOGD (LOGD_DEVICE, "assumed connection disconnected. Deleting generated connection '%s' (%s)", nm_settings_connection_get_id (connection), nm_settings_connection_get_uuid (connection)); - nm_settings_connection_delete (connection, NULL, NULL); + nm_settings_connection_delete (connection, NULL); } g_object_unref (connection); } @@ -1990,7 +1990,7 @@ recheck_assume_connection (NMManager *self, if (generated) { _LOG2D (LOGD_DEVICE, device, "assume: deleting generated connection after assuming failed"); - nm_settings_connection_delete (connection, NULL, NULL); + nm_settings_connection_delete (connection, NULL); } else { if (nm_device_sys_iface_state_get (device) == NM_DEVICE_SYS_IFACE_STATE_ASSUME) nm_device_sys_iface_state_set (device, NM_DEVICE_SYS_IFACE_STATE_EXTERNAL); @@ -4056,7 +4056,7 @@ activation_add_done (NMSettings *settings, g_assert (error); _internal_activation_failed (self, active, error->message); if (new_connection) - nm_settings_connection_delete (new_connection, NULL, NULL); + nm_settings_connection_delete (new_connection, NULL); g_dbus_method_invocation_return_gerror (context, error); nm_audit_log_connection_op (NM_AUDIT_OP_CONN_ADD_ACTIVATE, NULL, diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 8ef9f32228..79e8458968 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -663,33 +663,31 @@ remove_entry_from_db (NMSettingsConnection *self, const char* db_name) g_key_file_free (key_file); } -void +gboolean nm_settings_connection_delete (NMSettingsConnection *self, - NMSettingsConnectionDeleteFunc callback, - gpointer user_data) + GError **error) { gs_unref_object NMSettingsConnection *self_keep_alive = NULL; - gs_free_error GError *error = NULL; NMSettingsConnectionClass *klass; NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); NMConnection *for_agents; - g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self)); + g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE); klass = NM_SETTINGS_CONNECTION_GET_CLASS (self); self_keep_alive = g_object_ref (self); if (!klass->delete) { - g_set_error (&error, + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "delete not supported"); - goto out; + return FALSE; } if (!klass->delete (self, - &error)) - goto out; + error)) + return FALSE; set_visible (self, FALSE); @@ -708,10 +706,7 @@ nm_settings_connection_delete (NMSettingsConnection *self, remove_entry_from_db (self, "seen-bssids"); nm_settings_connection_signal_remove (self, FALSE); - -out: - if (callback) - callback (self, error, user_data); + return TRUE; } @@ -1514,11 +1509,6 @@ typedef struct { char *audit_args; } UpdateInfo; -typedef struct { - GDBusMethodInvocation *context; - NMAuthSubject *subject; -} CallbackInfo; - static void has_some_secrets_cb (NMSetting *setting, const char *key, @@ -1812,23 +1802,6 @@ impl_settings_connection_save (NMSettingsConnection *self, settings_connection_update_helper (self, context, NULL, TRUE); } -static void -con_delete_cb (NMSettingsConnection *self, - GError *error, - gpointer user_data) -{ - CallbackInfo *info = user_data; - - if (error) - g_dbus_method_invocation_return_gerror (info->context, error); - else - g_dbus_method_invocation_return_value (info->context, NULL); - - nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, self, - !error, NULL, info->subject, error ? error->message : NULL); - g_free (info); -} - static void delete_auth_cb (NMSettingsConnection *self, GDBusMethodInvocation *context, @@ -1836,7 +1809,7 @@ delete_auth_cb (NMSettingsConnection *self, GError *error, gpointer data) { - CallbackInfo *info; + gs_free_error GError *local = NULL; if (error) { nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, self, FALSE, NULL, subject, @@ -1845,11 +1818,15 @@ delete_auth_cb (NMSettingsConnection *self, return; } - info = g_malloc0 (sizeof (*info)); - info->context = context; - info->subject = subject; + nm_settings_connection_delete (self, &local); - nm_settings_connection_delete (self, con_delete_cb, info); + nm_audit_log_connection_op (NM_AUDIT_OP_CONN_DELETE, self, + !local, NULL, subject, local ? local->message : NULL); + + if (local) + g_dbus_method_invocation_return_gerror (context, local); + else + g_dbus_method_invocation_return_value (context, NULL); } static const char * diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index 3a38fa650d..c1e368a298 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -94,10 +94,6 @@ typedef struct _NMSettingsConnectionCallId *NMSettingsConnectionCallId; typedef struct _NMSettingsConnectionClass NMSettingsConnectionClass; -typedef void (*NMSettingsConnectionDeleteFunc) (NMSettingsConnection *self, - GError *error, - gpointer user_data); - struct _NMSettingsConnectionPrivate; struct _NMSettingsConnection { @@ -138,9 +134,8 @@ gboolean nm_settings_connection_replace_settings (NMSettingsConnection *self, const char *log_diff_name, GError **error); -void nm_settings_connection_delete (NMSettingsConnection *self, - NMSettingsConnectionDeleteFunc callback, - gpointer user_data); +gboolean nm_settings_connection_delete (NMSettingsConnection *self, + GError **error); typedef void (*NMSettingsConnectionSecretsFunc) (NMSettingsConnection *self, NMSettingsConnectionCallId call_id, diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 5f83d840c3..e2b467a24c 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -1773,7 +1773,7 @@ nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean quittin * remains up and can be assumed if NM starts again. */ if (quitting == FALSE) - nm_settings_connection_delete (connection, NULL, NULL); + nm_settings_connection_delete (connection, NULL); } } diff --git a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c index 161298ed0e..e8483f962a 100644 --- a/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c +++ b/src/settings/plugins/ifupdown/nms-ifupdown-plugin.c @@ -411,7 +411,7 @@ init (NMSettingsPlugin *config) exported = g_hash_table_lookup (priv->connections, block->name); if (exported) { nm_log_info (LOGD_SETTINGS, "deleting %s from connections", block->name); - nm_settings_connection_delete (NM_SETTINGS_CONNECTION (exported), NULL, NULL); + nm_settings_connection_delete (NM_SETTINGS_CONNECTION (exported), NULL); g_hash_table_remove (priv->connections, block->name); }