summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-07-07 17:36:12 +0200
committerThomas Haller <thaller@redhat.com>2014-08-14 01:11:10 +0200
commita005cd558a534760e7138343f11cbed3c048d68e (patch)
treed1dd7a7253bed15386f4d4858814cc324925dfdf
parent364f15380cdf4097ef8930edf359d3fc932fd25d (diff)
downloadNetworkManager-th/bgo696936_normalize_settings-2.tar.gz
**ADJUST COMMIT MESSAGE BEFORE MERGING** libnm-util: properly disconnect "notify" signal for settings in NMConnectionth/bgo696936_normalize_settings-2
When removing/replacing a NMSetting in an NMConnection, we have to disconnect setting_changed_cb() from the "notify" signal. Backport commit 5f730d3d3223bd664892ccca5cd35e95c9fe873f from libnm-core. Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--libnm-util/nm-connection.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index 7e26309c57..e59f8f50a6 100644
--- a/libnm-util/nm-connection.c
+++ b/libnm-util/nm-connection.c
@@ -185,12 +185,23 @@ setting_changed_cb (NMSetting *setting,
g_signal_emit (self, signals[CHANGED], 0);
}
+static gboolean
+_setting_release (gpointer key, gpointer value, gpointer user_data)
+{
+ g_signal_handlers_disconnect_by_func (user_data, setting_changed_cb, value);
+ return TRUE;
+}
+
static void
_nm_connection_add_setting (NMConnection *connection, NMSetting *setting)
{
- g_hash_table_insert (NM_CONNECTION_GET_PRIVATE (connection)->settings,
- (gpointer) G_OBJECT_TYPE_NAME (setting),
- setting);
+ NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
+ const char *name = G_OBJECT_TYPE_NAME (setting);
+ NMSetting *s_old;
+
+ if ((s_old = g_hash_table_lookup (priv->settings, (gpointer) name)))
+ g_signal_handlers_disconnect_by_func (s_old, setting_changed_cb, connection);
+ g_hash_table_insert (priv->settings, (gpointer) name, setting);
/* Listen for property changes so we can emit the 'changed' signal */
g_signal_connect (setting, "notify", (GCallback) setting_changed_cb, connection);
}
@@ -347,7 +358,7 @@ hash_to_connection (NMConnection *connection, GHashTable *new, GError **error)
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
if ((changed = g_hash_table_size (priv->settings) > 0))
- g_hash_table_remove_all (priv->settings);
+ g_hash_table_foreach_remove (priv->settings, _setting_release, connection);
g_hash_table_iter_init (&iter, new);
while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting_hash)) {
@@ -435,7 +446,7 @@ nm_connection_replace_settings_from_connection (NMConnection *connection,
priv = NM_CONNECTION_GET_PRIVATE (connection);
if ((changed = g_hash_table_size (priv->settings) > 0))
- g_hash_table_remove_all (priv->settings);
+ g_hash_table_foreach_remove (priv->settings, _setting_release, connection);
if (g_hash_table_size (NM_CONNECTION_GET_PRIVATE (new_connection)->settings)) {
g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (new_connection)->settings);
@@ -1494,7 +1505,7 @@ nm_connection_duplicate (NMConnection *connection)
g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting))
- nm_connection_add_setting (dup, nm_setting_duplicate (setting));
+ _nm_connection_add_setting (dup, nm_setting_duplicate (setting));
return dup;
}
@@ -2048,14 +2059,8 @@ dispose (GObject *object)
{
NMConnection *self = NM_CONNECTION (object);
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (self);
- GHashTableIter iter;
- NMSetting *setting;
- g_hash_table_iter_init (&iter, priv->settings);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting)) {
- g_signal_handlers_disconnect_by_func (setting, setting_changed_cb, self);
- g_hash_table_iter_remove (&iter);
- }
+ g_hash_table_foreach_remove (priv->settings, _setting_release, self);
G_OBJECT_CLASS (nm_connection_parent_class)->dispose (object);
}
@@ -2066,6 +2071,7 @@ finalize (GObject *object)
NMConnection *connection = NM_CONNECTION (object);
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
+ g_assert (g_hash_table_size (priv->settings) == 0);
g_hash_table_destroy (priv->settings);
g_free (priv->path);