summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-05-05 08:28:04 +0200
committerThomas Haller <thaller@redhat.com>2020-05-07 14:08:33 +0200
commitf588dabb4f3c116c58b6d79aeac5af8c4e220c32 (patch)
treec7fd3c1157c76101b59acac5c1a705064b8cbcfb
parent5cdb636301f934aaa7dbf39340d721e438f76c7d (diff)
downloadNetworkManager-f588dabb4f3c116c58b6d79aeac5af8c4e220c32.tar.gz
settings: ensure that "plugins-=ifcfg-rh" works with the default plugins
On Fedora/RHEL, the default for main.plugins is "ifcfg-rh". You would expect that a single configuration file [main] plugins-=ifcfg-rh would result in an empty list of plugins (which subsequently gets completed with "keyfile"). That didn't happen due to a bug. Fix it.
-rw-r--r--src/nm-config-data.c7
-rw-r--r--src/nm-config.c20
2 files changed, 19 insertions, 8 deletions
diff --git a/src/nm-config-data.c b/src/nm-config-data.c
index 29dafa14ed..4d85bebf2e 100644
--- a/src/nm-config-data.c
+++ b/src/nm-config-data.c
@@ -12,6 +12,7 @@
#include "devices/nm-device.h"
#include "nm-core-internal.h"
#include "nm-keyfile/nm-keyfile-internal.h"
+#include "nm-keyfile/nm-keyfile-utils.h"
/*****************************************************************************/
@@ -215,6 +216,7 @@ nm_config_data_get_value_int64 (const NMConfigData *self, const char *group, con
char **
nm_config_data_get_plugins (const NMConfigData *self, gboolean allow_default)
{
+ gs_free_error GError *error = NULL;
const NMConfigDataPrivate *priv;
char **list;
@@ -222,8 +224,9 @@ nm_config_data_get_plugins (const NMConfigData *self, gboolean allow_default)
priv = NM_CONFIG_DATA_GET_PRIVATE (self);
- list = g_key_file_get_string_list (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, NULL);
- if (!list && allow_default) {
+ list = g_key_file_get_string_list (priv->keyfile, NM_CONFIG_KEYFILE_GROUP_MAIN, "plugins", NULL, &error);
+ if ( nm_keyfile_error_is_not_found (error)
+ && allow_default) {
gs_unref_keyfile GKeyFile *kf = nm_config_create_keyfile ();
/* let keyfile split the default string according to its own escaping rules. */
diff --git a/src/nm-config.c b/src/nm-config.c
index 9a16aa0374..9cee2da702 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -15,6 +15,7 @@
#include "NetworkManagerUtils.h"
#include "nm-core-internal.h"
#include "nm-keyfile/nm-keyfile-internal.h"
+#include "nm-keyfile/nm-keyfile-utils.h"
#define DEFAULT_CONFIG_MAIN_FILE NMCONFDIR "/NetworkManager.conf"
#define DEFAULT_CONFIG_DIR NMCONFDIR "/conf.d"
@@ -977,7 +978,7 @@ read_config (GKeyFile *keyfile, gboolean is_base_config,
gsize key_len;
key = keys[k];
- g_assert (key && *key);
+ nm_assert (key && *key);
if ( _HAS_PREFIX (key, NM_CONFIG_KEYFILE_KEYPREFIX_WAS)
|| _HAS_PREFIX (key, NM_CONFIG_KEYFILE_KEYPREFIX_SET)) {
@@ -996,6 +997,7 @@ read_config (GKeyFile *keyfile, gboolean is_base_config,
&& (last_char == '+' || last_char == '-')) {
gs_free char *base_key = g_strndup (key, key_len - 1);
gboolean is_string_list;
+ gboolean old_val_was_set = FALSE;
is_string_list = _setting_is_string_list (group, base_key);
@@ -1007,13 +1009,19 @@ read_config (GKeyFile *keyfile, gboolean is_base_config,
gs_free char **new_val = NULL;
if (is_string_list) {
- old_val = g_key_file_get_string_list (keyfile, group, base_key, NULL, NULL);
+ gs_free_error GError *old_error = NULL;
+
+ old_val = g_key_file_get_string_list (keyfile, group, base_key, NULL, &old_error);
new_val = g_key_file_get_string_list (kf, group, key, NULL, NULL);
- if (!old_val && !g_key_file_has_key (keyfile, group, base_key, NULL)) {
- /* we must fill the unspecified value with the compile-time default. */
- if (nm_streq (group, NM_CONFIG_KEYFILE_GROUP_MAIN) && nm_streq (base_key, "plugins")) {
+ if ( nm_streq (group, NM_CONFIG_KEYFILE_GROUP_MAIN)
+ && nm_streq (base_key, "plugins")) {
+ old_val_was_set = !nm_keyfile_error_is_not_found (old_error);
+ if ( !old_val
+ && !old_val_was_set) {
+ /* we must fill the unspecified value with the compile-time default. */
g_key_file_set_value (keyfile, group, base_key, NM_CONFIG_DEFAULT_MAIN_PLUGINS);
old_val = g_key_file_get_string_list (keyfile, group, base_key, NULL, NULL);
+ old_val_was_set = TRUE;
}
}
} else {
@@ -1059,7 +1067,7 @@ read_config (GKeyFile *keyfile, gboolean is_base_config,
g_key_file_set_value (keyfile, group, base_key, specs_joined);
}
} else {
- if (is_string_list)
+ if (is_string_list && !old_val_was_set)
g_key_file_remove_key (keyfile, group, base_key, NULL);
else
g_key_file_set_value (keyfile, group, base_key, "");