From 0bbdc6b0fc3ca7425bb4e289571b014561b609d1 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 16 Nov 2009 16:14:50 -0800 Subject: [PATCH] system-settings: generalize nm_sysconfig_connection_update() a bit So that it can be the sole location where secrets caching happens. --- src/system-settings/nm-sysconfig-connection.c | 19 ++++++++++--------- src/system-settings/nm-sysconfig-connection.h | 5 +++-- .../plugins/ifcfg-rh/nm-ifcfg-connection.c | 5 +---- system-settings/plugins/ifcfg-rh/plugin.c | 1 + .../plugins/ifcfg-suse/nm-suse-connection.c | 6 ++---- .../plugins/keyfile/nm-keyfile-connection.c | 5 +---- system-settings/plugins/keyfile/plugin.c | 1 + 7 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/system-settings/nm-sysconfig-connection.c b/src/system-settings/nm-sysconfig-connection.c index 167c86d26f..976a5272f3 100644 --- a/src/system-settings/nm-sysconfig-connection.c +++ b/src/system-settings/nm-sysconfig-connection.c @@ -57,6 +57,7 @@ ignore_cb (NMSettingsConnectionInterface *connection, gboolean nm_sysconfig_connection_update (NMSysconfigConnection *self, NMConnection *new, + gboolean signal_update, GError **error) { GHashTable *new_settings; @@ -71,9 +72,11 @@ nm_sysconfig_connection_update (NMSysconfigConnection *self, new_settings = nm_connection_to_hash (new); g_assert (new_settings); if (nm_connection_replace_settings (NM_CONNECTION (self), new_settings, error)) { - nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (self), - ignore_cb, - NULL); + if (signal_update) { + nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (self), + ignore_cb, + NULL); + } success = TRUE; } g_hash_table_destroy (new_settings); @@ -282,7 +285,6 @@ pk_update_cb (GObject *object, GAsyncResult *result, gpointer user_data) NMSysconfigConnectionPrivate *priv; PolkitAuthorizationResult *pk_result; GError *error = NULL; - GHashTable *settings; /* If our NMSysconfigConnection is already gone, do nothing */ if (call->disposed) { @@ -322,19 +324,18 @@ pk_update_cb (GObject *object, GAsyncResult *result, gpointer user_data) } /* Update our settings internally so the update() call will save the new - * ones. + * ones. We don't let nm_sysconfig_connection_update() handle the update + * signal since we need our own callback after the update is done. */ - settings = nm_connection_to_hash (call->connection); - if (!nm_connection_replace_settings (NM_CONNECTION (self), settings, &error)) { + if (!nm_sysconfig_connection_update (self, call->connection, FALSE, &error)) { /* Shouldn't really happen since we've already validated the settings */ dbus_g_method_return_error (call->context, error); g_error_free (error); polkit_call_free (call); goto out; } - g_hash_table_destroy (settings); - /* Caller is authenticated, now we can finally try to update */ + /* Caller is authenticated, now we can finally try to commit the update */ nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (self), con_update_cb, call); diff --git a/src/system-settings/nm-sysconfig-connection.h b/src/system-settings/nm-sysconfig-connection.h index 3eeb1e5519..0431dc95c2 100644 --- a/src/system-settings/nm-sysconfig-connection.h +++ b/src/system-settings/nm-sysconfig-connection.h @@ -43,11 +43,12 @@ typedef struct { GType nm_sysconfig_connection_get_type (void); -/* Called by a system-settings plugin to update a connection when the - * connection's backing storage has changed. +/* Called by a system-settings plugin to update a connection is out of sync + * with it's backing storage. */ gboolean nm_sysconfig_connection_update (NMSysconfigConnection *self, NMConnection *new_settings, + gboolean signal_update, GError **error); G_END_DECLS diff --git a/system-settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/system-settings/plugins/ifcfg-rh/nm-ifcfg-connection.c index 68f9640331..cb8371e731 100644 --- a/system-settings/plugins/ifcfg-rh/nm-ifcfg-connection.c +++ b/system-settings/plugins/ifcfg-rh/nm-ifcfg-connection.c @@ -108,7 +108,6 @@ nm_ifcfg_connection_new (const char *filename, char *unmanaged = NULL; char *keyfile = NULL; NMInotifyHelper *ih; - GHashTable *settings; g_return_val_if_fail (filename != NULL, NULL); @@ -126,9 +125,7 @@ nm_ifcfg_connection_new (const char *filename, } /* Update our settings with what was read from the file */ - settings = nm_connection_to_hash (tmp); - nm_connection_replace_settings (NM_CONNECTION (object), settings, NULL); - g_hash_table_destroy (settings); + nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (object), tmp, FALSE, NULL); g_object_unref (tmp); priv = NM_IFCFG_CONNECTION_GET_PRIVATE (object); diff --git a/system-settings/plugins/ifcfg-rh/plugin.c b/system-settings/plugins/ifcfg-rh/plugin.c index a5543ee908..9961c34355 100644 --- a/system-settings/plugins/ifcfg-rh/plugin.c +++ b/system-settings/plugins/ifcfg-rh/plugin.c @@ -283,6 +283,7 @@ connection_changed_handler (SCPluginIfcfg *plugin, if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (connection), NM_CONNECTION (new), + TRUE, &error)) { PLUGIN_WARN (IFCFG_PLUGIN_NAME, " error updating: %s", (error && error->message) ? error->message : "(unknown)"); diff --git a/system-settings/plugins/ifcfg-suse/nm-suse-connection.c b/system-settings/plugins/ifcfg-suse/nm-suse-connection.c index 72f5d683af..d776fecf94 100644 --- a/system-settings/plugins/ifcfg-suse/nm-suse-connection.c +++ b/system-settings/plugins/ifcfg-suse/nm-suse-connection.c @@ -59,6 +59,7 @@ file_changed (GFileMonitor *monitor, if (new) { if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (self), NM_CONNECTION (new), + TRUE, &error)) { g_warning ("%s: '%s' / '%s' invalid: %d", __func__, @@ -87,7 +88,6 @@ nm_suse_connection_new (const char *iface, NMDeviceType dev_type) GFileMonitor *monitor; NMSuseConnection *exported; NMSuseConnectionPrivate *priv; - GHashTable *settings; NMSettingConnection *s_con; g_return_val_if_fail (iface != NULL, NULL); @@ -112,9 +112,7 @@ nm_suse_connection_new (const char *iface, NMDeviceType dev_type) } /* Update our settings with what was read from the file */ - settings = nm_connection_to_hash (tmp); - nm_connection_replace_settings (NM_CONNECTION (exported), settings, NULL); - g_hash_table_destroy (settings); + nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (exported), tmp, FALSE, NULL); g_object_unref (tmp); priv = NM_SUSE_CONNECTION_GET_PRIVATE (exported); diff --git a/system-settings/plugins/keyfile/nm-keyfile-connection.c b/system-settings/plugins/keyfile/nm-keyfile-connection.c index 2b12da7591..b64c2f906e 100644 --- a/system-settings/plugins/keyfile/nm-keyfile-connection.c +++ b/system-settings/plugins/keyfile/nm-keyfile-connection.c @@ -131,7 +131,6 @@ constructor (GType type, NMKeyfileConnectionPrivate *priv; NMSettingConnection *s_con; NMConnection *tmp; - GHashTable *settings; object = G_OBJECT_CLASS (nm_keyfile_connection_parent_class)->constructor (type, n_construct_params, construct_params); @@ -148,9 +147,7 @@ constructor (GType type, return NULL; } - settings = nm_connection_to_hash (tmp); - nm_connection_replace_settings (NM_CONNECTION (object), settings, NULL); - g_hash_table_destroy (settings); + nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (object), tmp, FALSE, NULL); g_object_unref (tmp); /* if for some reason the connection didn't have a UUID, add one */ diff --git a/system-settings/plugins/keyfile/plugin.c b/system-settings/plugins/keyfile/plugin.c index 9b82a8b05a..40f0960ff8 100644 --- a/system-settings/plugins/keyfile/plugin.c +++ b/system-settings/plugins/keyfile/plugin.c @@ -130,6 +130,7 @@ update_connection_settings (NMKeyfileConnection *orig, if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (orig), NM_CONNECTION (new), + TRUE, &error)) { g_warning ("%s: '%s' / '%s' invalid: %d", __func__,