Blob Blame History Raw
From 583eba38280628da9c645d402483f9fd0927005a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com>
Date: Thu, 10 Apr 2014 13:25:41 +0200
Subject: [PATCH] core: sort connections in descending timestamp order on
 take-over (rh #1067712)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When assuming the connections on restart we want to prefer more-recently-used
connections. That's why we have to sort connections according to timestamps in
descending order. That means connections used more recently (higher timestamp)
go before connections with lower timestamp.

https://bugzilla.redhat.com/show_bug.cgi?id=1067712

Signed-off-by: Jiří Klimeš <jklimes@redhat.com>
---
 src/nm-manager.c           | 2 +-
 src/settings/nm-settings.c | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/nm-manager.c b/src/nm-manager.c
index d3d660c..f991b04 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -1706,7 +1706,7 @@ get_existing_connection (NMManager *manager, NMDevice *device)
 	 * When no configured connection matches the generated connection, we keep
 	 * the generated connection instead.
 	 */
-	connections = g_slist_sort (connections, nm_settings_sort_connections);
+	connections = g_slist_reverse (g_slist_sort (connections, nm_settings_sort_connections));
 	matched = nm_utils_match_connection (connections,
 	                                     connection,
 	                                     nm_device_has_carrier (device),
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index 852fa6d..b4d9c22 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -1685,7 +1685,11 @@ nm_settings_device_removed (NMSettings *self, NMDevice *device, gboolean quittin
 
 /***************************************************************/
 
-/* GCompareFunc helper for sorting "best" connections */
+/* GCompareFunc helper for sorting "best" connections.
+ * The function sorts connections in ascending timestamp order.
+ * That means an older connection (lower timestamp) goes before
+ * a newer one.
+ */
 gint
 nm_settings_sort_connections (gconstpointer a, gconstpointer b)
 {
-- 
1.7.11.7