[network-manager-applet: 4/7] team: make algorithm for choosing new team_num deterministic



commit 148d15ad83286fba828a2fcfedb1fddf38570726
Author: Thomas Haller <thaller redhat com>
Date:   Wed Sep 18 10:16:51 2013 +0200

    team: make algorithm for choosing new team_num deterministic
    
    The previous algorithm for choosing the team_num is not deterministic.
    
    It does neither choose one of
    (a) MAX(existing team_nums) + 1
    (b) MIN(unused team_nums)
    
    What it actually chooses depends on the order how the existing
    connections are returned. For example:
    [0 2] => 1
    [2 0] => 3
    
    Change it to use (a).
    
    Signed-off-by: Thomas Haller <thaller redhat com>

 src/connection-editor/page-team.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
---
diff --git a/src/connection-editor/page-team.c b/src/connection-editor/page-team.c
index 8229440..1b19507 100644
--- a/src/connection-editor/page-team.c
+++ b/src/connection-editor/page-team.c
@@ -220,7 +220,7 @@ team_connection_new (GtkWindow *parent,
                      gpointer user_data)
 {
        NMConnection *connection;
-       int team_num, max_team_num, num;
+       int team_num, num;
        GSList *connections, *iter;
        NMConnection *conn2;
        NMSettingTeam *s_team;
@@ -235,7 +235,7 @@ team_connection_new (GtkWindow *parent,
        nm_connection_add_setting (connection, nm_setting_team_new ());
 
        /* Find an available interface name */
-       team_num = max_team_num = 0;
+       team_num = 0;
        connections = nm_remote_settings_list_connections (settings);
        for (iter = connections; iter; iter = iter->next) {
                conn2 = iter->data;
@@ -250,10 +250,8 @@ team_connection_new (GtkWindow *parent,
                        continue;
 
                num = atoi (iface + 4);
-               if (num > max_team_num)
-                       max_team_num = num;
-               if (num == team_num)
-                       team_num = max_team_num + 1;
+               if (team_num <= num)
+                       team_num = num + 1;
        }
        g_slist_free (connections);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]