diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2017-11-21 11:00:45 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2017-11-21 11:27:54 +0100 |
commit | 9a631a068e21fc193d81f1c421a0350c8aab52a6 (patch) | |
tree | b32be9096b86707b7b9a93fcec2608bfcb1968e4 | |
parent | 60f57ebe4aae91cf9a1ffef5cf58c6756310ff06 (diff) | |
download | NetworkManager-9a631a068e21fc193d81f1c421a0350c8aab52a6.tar.gz |
ifcfg-rh: sort bond options when writing a connection
Bond options are stored in a hash table and the order in which they
are returned by the API is not guaranteed. Sort them alphabetically so
that a connection will always be written in the same way, even if the
internal implementation of the hash table or the hashing function
changes, as it did in commit a6be2f4aa907 ("all: use nm_str_hash()
instead of g_str_hash()").
-rw-r--r-- | src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c index c4e65b4f0d..9292640960 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c @@ -1309,25 +1309,26 @@ write_bond_setting (NMConnection *connection, shvarFile *ifcfg, gboolean *wired, svUnsetValue (ifcfg, "BONDING_OPTS"); num_opts = nm_setting_bond_get_num_options (s_bond); - if (num_opts > 0) { - GString *str = g_string_sized_new (64); + if (num_opts) { + nm_auto_free_gstring GString *str = NULL; + gs_free const char **options = NULL; + const char *value; - for (i = 0; i < nm_setting_bond_get_num_options (s_bond); i++) { - const char *key, *value; - - if (!nm_setting_bond_get_option (s_bond, i, &key, &value)) - continue; + str = g_string_sized_new (64); + options = g_new (const char *, num_opts); + for (i = 0; i < num_opts; i++) + nm_setting_bond_get_option (s_bond, i, &options[i], &value); + g_qsort_with_data (options, num_opts, sizeof (const char *), + nm_strcmp_p_with_data, NULL); + for (i = 0; i < num_opts; i++) { if (str->len) g_string_append_c (str, ' '); - - g_string_append_printf (str, "%s=%s", key, value); + value = nm_setting_bond_get_option_by_name (s_bond, options[i]); + g_string_append_printf (str, "%s=%s", options[i], value); } - if (str->len) - svSetValueStr (ifcfg, "BONDING_OPTS", str->str); - - g_string_free (str, TRUE); + svSetValueStr (ifcfg, "BONDING_OPTS", str->str); } svSetValueStr (ifcfg, "TYPE", TYPE_BOND); |