summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-11-22 12:46:58 +0100
committerThomas Haller <thaller@redhat.com>2017-11-22 12:49:58 +0100
commit5b8270339114998710a358bd5adc978169f72a08 (patch)
treeb847d8d17054c423b4fea71b79f88504e116d81b
parentced093c9457371ce9580656bf88828eb6217821b (diff)
downloadNetworkManager-th/user-block-autoactivate-rh1401515.tar.gz
core: merge nm_settings_get_connections_sorted() with nm_settings_get_connections_clone()th/user-block-autoactivate-rh1401515
-rw-r--r--src/devices/wifi/nm-device-wifi.c4
-rw-r--r--src/nm-checkpoint.c4
-rw-r--r--src/nm-manager.c40
-rw-r--r--src/nm-policy.c4
-rw-r--r--src/settings/nm-settings.c33
-rw-r--r--src/settings/nm-settings.h7
6 files changed, 42 insertions, 50 deletions
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index 5e92f47b76..c9e4aab2e4 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -1428,8 +1428,8 @@ build_hidden_probe_list (NMDeviceWifi *self)
connections = nm_settings_get_connections_clone (nm_device_get_settings ((NMDevice *) self),
&len,
- hidden_filter_func,
- NULL);
+ hidden_filter_func, NULL,
+ NULL, NULL);
if (!connections[0])
return NULL;
diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c
index 54b577642e..0390255ddc 100644
--- a/src/nm-checkpoint.c
+++ b/src/nm-checkpoint.c
@@ -335,7 +335,9 @@ next_dev:
guint i;
g_return_val_if_fail (priv->connection_uuids, NULL);
- list = nm_settings_get_connections_sorted (nm_settings_get (), NULL);
+ list = nm_settings_get_connections_clone (nm_settings_get (), NULL,
+ NULL, NULL,
+ nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
for (i = 0; list[i]; i++) {
con = list[i];
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 1ab6e39e01..f45771ca37 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -511,26 +511,16 @@ _get_activatable_connections_filter (NMSettings *settings,
return !active_connection_find_first (user_data, connection, NULL, NM_ACTIVE_CONNECTION_STATE_DEACTIVATING);
}
-/* Filter out connections that are already active.
- * nm_settings_get_connections_sorted() returns sorted list. We need to preserve the
- * order so that we didn't change auto-activation order (recent timestamps
- * are first).
- * Caller is responsible for freeing the returned list with g_slist_free().
- */
NMSettingsConnection **
nm_manager_get_activatable_connections (NMManager *manager, guint *out_len, gboolean sort)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
- NMSettingsConnection **connections;
- guint len;
- connections = nm_settings_get_connections_clone (priv->settings, &len,
- _get_activatable_connections_filter,
- manager);
- if (sort && len > 1)
- g_qsort_with_data (connections, len, sizeof (connections[0]), nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
- NM_SET_OUT (out_len, len);
- return connections;
+ return nm_settings_get_connections_clone (priv->settings, out_len,
+ _get_activatable_connections_filter,
+ manager,
+ sort ? nm_settings_connection_cmp_autoconnect_priority_p_with_data : NULL,
+ NULL);
}
static NMActiveConnection *
@@ -1392,7 +1382,9 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
}
/* Create backing resources if the device has any autoconnect connections */
- connections = nm_settings_get_connections_sorted (priv->settings, NULL);
+ connections = nm_settings_get_connections_clone (priv->settings, NULL,
+ NULL, NULL,
+ nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
for (i = 0; connections[i]; i++) {
NMConnection *candidate = NM_CONNECTION (connections[i]);
NMSettingConnection *s_con;
@@ -1436,7 +1428,9 @@ retry_connections_for_parent_device (NMManager *self, NMDevice *device)
g_return_if_fail (device);
- connections = nm_settings_get_connections_sorted (priv->settings, NULL);
+ connections = nm_settings_get_connections_clone (priv->settings, NULL,
+ NULL, NULL,
+ nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
for (i = 0; connections[i]; i++) {
NMConnection *candidate = NM_CONNECTION (connections[i]);
gs_free_error GError *error = NULL;
@@ -3022,7 +3016,9 @@ find_slaves (NMManager *manager,
* even if a slave was already active, it might be deactivated during
* master reactivation.
*/
- all_connections = nm_settings_get_connections_sorted (priv->settings, &n_all_connections);
+ all_connections = nm_settings_get_connections_clone (priv->settings, &n_all_connections,
+ NULL, NULL,
+ nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
for (i = 0; i < n_all_connections; i++) {
NMSettingsConnection *master_connection = NULL;
NMDevice *master_device = NULL, *slave_device;
@@ -4167,7 +4163,9 @@ impl_manager_add_and_activate_connection (NMManager *self,
gs_free NMSettingsConnection **connections = NULL;
guint i, len;
- connections = nm_settings_get_connections_sorted (priv->settings, &len);
+ connections = nm_settings_get_connections_clone (priv->settings, &len,
+ NULL, NULL,
+ nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
all_connections = NULL;
for (i = len; i > 0; ) {
i--;
@@ -5226,7 +5224,9 @@ nm_manager_start (NMManager *self, GError **error)
* connection-added signals thus devices have to be created manually.
*/
_LOGD (LOGD_CORE, "creating virtual devices...");
- connections = nm_settings_get_connections_sorted (priv->settings, NULL);
+ connections = nm_settings_get_connections_clone (priv->settings, NULL,
+ NULL, NULL,
+ nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
for (i = 0; connections[i]; i++)
connection_changed (self, NM_CONNECTION (connections[i]));
diff --git a/src/nm-policy.c b/src/nm-policy.c
index f92dddbfb3..fb500585de 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -1570,7 +1570,9 @@ activate_slave_connections (NMPolicy *self, NMDevice *device)
internal_activation = subject && nm_auth_subject_is_internal (subject);
}
- connections = nm_settings_get_connections_sorted (priv->settings, NULL);
+ connections = nm_settings_get_connections_clone (priv->settings, NULL,
+ NULL, NULL,
+ nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
for (i = 0; connections[i]; i++) {
NMConnection *slave;
NMSettingConnection *s_slave_con;
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index 4eeee31554..d52592dd60 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -431,6 +431,9 @@ nm_settings_get_connections (NMSettings *self, guint *out_len)
* @out_len: (allow-none): optional output argument
* @func: caller-supplied function for filtering connections
* @func_data: caller-supplied data passed to @func
+ * @sort_compare_func: (allow-none): optional function pointer for
+ * sorting the returned list.
+ * @sort_data: user data for @sort_compare_func.
*
* Returns: (transfer container) (element-type NMSettingsConnection):
* an NULL terminated array of #NMSettingsConnection objects that were
@@ -443,7 +446,9 @@ NMSettingsConnection **
nm_settings_get_connections_clone (NMSettings *self,
guint *out_len,
NMSettingsConnectionFilterFunc func,
- gpointer func_data)
+ gpointer func_data,
+ GCompareDataFunc sort_compare_func,
+ gpointer sort_data)
{
NMSettingsConnection *const*list_cached;
NMSettingsConnection **list;
@@ -471,31 +476,15 @@ nm_settings_get_connections_clone (NMSettings *self,
} else
memcpy (list, list_cached, sizeof (list[0]) * ((gsize) len + 1));
+ if ( len > 1
+ && sort_compare_func) {
+ g_qsort_with_data (list, len, sizeof (NMSettingsConnection *),
+ sort_compare_func, sort_data);
+ }
NM_SET_OUT (out_len, len);
return list;
}
-/* Returns a list of NMSettingsConnections.
- * The list is sorted in the order suitable for auto-connecting, i.e.
- * first go connections with autoconnect=yes and most recent timestamp.
- * Caller must free the list with g_free(), but not the list items.
- */
-NMSettingsConnection **
-nm_settings_get_connections_sorted (NMSettings *self, guint *out_len)
-{
- NMSettingsConnection **connections;
- guint len;
-
- g_return_val_if_fail (NM_IS_SETTINGS (self), NULL);
-
- connections = nm_settings_get_connections_clone (self, &len, NULL, NULL);
- if (len > 1)
- g_qsort_with_data (connections, len, sizeof (NMSettingsConnection *), nm_settings_connection_cmp_autoconnect_priority_p_with_data, NULL);
-
- NM_SET_OUT (out_len, len);
- return connections;
-}
-
NMSettingsConnection *
nm_settings_get_connection_by_path (NMSettings *self, const char *path)
{
diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h
index eede76b029..0e01f6b5fd 100644
--- a/src/settings/nm-settings.h
+++ b/src/settings/nm-settings.h
@@ -100,10 +100,9 @@ NMSettingsConnection *const* nm_settings_get_connections (NMSettings *settings,
NMSettingsConnection **nm_settings_get_connections_clone (NMSettings *self,
guint *out_len,
NMSettingsConnectionFilterFunc func,
- gpointer func_data);
-
-NMSettingsConnection **nm_settings_get_connections_sorted (NMSettings *self,
- guint *out_len);
+ gpointer func_data,
+ GCompareDataFunc sort_compare_func,
+ gpointer sort_data);
NMSettingsConnection *nm_settings_add_connection (NMSettings *settings,
NMConnection *connection,