From feff60ef3e6471699d1d3bd5fe6514897a5fc120 Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre Date: Tue, 14 Jun 2016 15:01:20 +0300 Subject: [PATCH 1/4] config: read /run/NetworkManager/conf.d files This is useful for configuration that gets auto-generated from another source. These are then not primary configuration files and thus should not be put into /etc. This mirrors the structure of udev rules or systemd units, which can also be in /usr, /run/, or /etc/. Signed-off-by: Mathieu Trudel-Lapierre https://bugzilla.gnome.org/show_bug.cgi?id=773069 --- src/nm-config.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/nm-config.c b/src/nm-config.c index 46fce99820..78c59a5410 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -36,6 +36,7 @@ #define DEFAULT_CONFIG_DIR NMCONFDIR "/conf.d" #define DEFAULT_CONFIG_MAIN_FILE_OLD NMCONFDIR "/nm-system-settings.conf" #define DEFAULT_SYSTEM_CONFIG_DIR NMLIBDIR "/conf.d" +#define RUN_CONFIG_DIR NMRUNDIR "/conf.d" #define DEFAULT_NO_AUTO_DEFAULT_FILE NMSTATEDIR "/no-auto-default.state" #define DEFAULT_INTERN_CONFIG_FILE NMSTATEDIR "/NetworkManager-intern.conf" #define DEFAULT_STATE_FILE NMSTATEDIR "/NetworkManager.state" @@ -937,6 +938,7 @@ read_entire_config (const NMConfigCmdLineOptions *cli, GKeyFile *keyfile; gs_unref_ptrarray GPtrArray *system_confs = NULL; gs_unref_ptrarray GPtrArray *confs = NULL; + gs_unref_ptrarray GPtrArray *run_confs = NULL; guint i; gs_free char *o_config_main_file = NULL; GString *str; @@ -952,6 +954,7 @@ read_entire_config (const NMConfigCmdLineOptions *cli, system_confs = _get_config_dir_files (system_config_dir); confs = _get_config_dir_files (config_dir); + run_confs = _get_config_dir_files (RUN_CONFIG_DIR); for (i = 0; i < system_confs->len; ) { const char *filename = system_confs->pdata[i]; @@ -969,6 +972,22 @@ read_entire_config (const NMConfigCmdLineOptions *cli, i++; } + for (i = 0; i < run_confs->len; ) { + const char *filename = run_confs->pdata[i]; + + /* if a same named file exists in config_dir, skip it. */ + if (_nm_utils_strv_find_first ((char **) confs->pdata, confs->len, filename) >= 0) { + g_ptr_array_remove_index (run_confs, i); + continue; + } + + if (!read_config (keyfile, FALSE, RUN_CONFIG_DIR, filename, error)) { + g_key_file_free (keyfile); + return NULL; + } + i++; + } + /* First read the base config file */ if (!read_base_config (keyfile, cli ? cli->config_main_file : NULL, &o_config_main_file, error)) { g_key_file_free (keyfile); From 49fcfcdfae02bcca2e7a062bb5e8b7ba33998c46 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 21 Jun 2016 17:22:12 +0200 Subject: [PATCH 2/4] config: skip shadowed run-config files in read_entire_config() https://bugzilla.gnome.org/show_bug.cgi?id=773069 --- src/nm-config.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nm-config.c b/src/nm-config.c index 78c59a5410..229c2e85a5 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -959,8 +959,9 @@ read_entire_config (const NMConfigCmdLineOptions *cli, for (i = 0; i < system_confs->len; ) { const char *filename = system_confs->pdata[i]; - /* if a same named file exists in config_dir, skip it. */ - if (_nm_utils_strv_find_first ((char **) confs->pdata, confs->len, filename) >= 0) { + /* if a same named file exists in config_dir or RUN_CONFIG_DIR, skip it. */ + if (_nm_utils_strv_find_first ((char **) confs->pdata, confs->len, filename) >= 0 || + _nm_utils_strv_find_first ((char **) run_confs->pdata, run_confs->len, filename) >= 0) { g_ptr_array_remove_index (system_confs, i); continue; } From f8c4a33f258dadd9bed4b6da7c8c917da1a9b6c3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 23 Oct 2016 10:21:44 +0200 Subject: [PATCH 3/4] config: add run-configs to description string --- src/nm-config.c | 57 ++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/src/nm-config.c b/src/nm-config.c index 229c2e85a5..fbd71a8db4 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -927,6 +927,24 @@ _get_config_dir_files (const char *config_dir) return confs; } +static void +_confs_to_description (GString *str, const GPtrArray *confs, const char *name) +{ + guint i; + + if (!confs->len) + return; + + for (i = 0; i < confs->len; i++) { + if (i == 0) + g_string_append_printf (str, " (%s: ", name); + else + g_string_append (str, ", "); + g_string_append (str, confs->pdata[i]); + } + g_string_append (str, ")"); +} + static GKeyFile * read_entire_config (const NMConfigCmdLineOptions *cli, const char *config_dir, @@ -941,7 +959,6 @@ read_entire_config (const NMConfigCmdLineOptions *cli, gs_unref_ptrarray GPtrArray *run_confs = NULL; guint i; gs_free char *o_config_main_file = NULL; - GString *str; g_return_val_if_fail (config_dir, NULL); g_return_val_if_fail (system_config_dir, NULL); @@ -1020,38 +1037,16 @@ read_entire_config (const NMConfigCmdLineOptions *cli, if (cli && cli->connectivity_response && cli->connectivity_response[0]) g_key_file_set_string (keyfile, NM_CONFIG_KEYFILE_GROUP_CONNECTIVITY, "response", cli->connectivity_response); - str = g_string_new (o_config_main_file); - if (system_confs->len > 0) { - for (i = 0; i < system_confs->len; i++) { - if (i == 0) - g_string_append (str, " (lib: "); - else - g_string_append (str, ", "); - g_string_append (str, system_confs->pdata[i]); - } - g_string_append (str, ")"); - } - if (confs->len > 0) { - for (i = 0; i < confs->len; i++) { - if (i == 0) - g_string_append (str, " (etc: "); - else - g_string_append (str, ", "); - g_string_append (str, confs->pdata[i]); - } - g_string_append (str, ")"); - } + if (out_config_description) { + GString *str; - if (out_config_main_file) - *out_config_main_file = o_config_main_file; - else - g_free (o_config_main_file); - if (out_config_description) + str = g_string_new (o_config_main_file); + _confs_to_description (str, system_confs, "lib"); + _confs_to_description (str, run_confs, "run"); + _confs_to_description (str, confs, "etc"); *out_config_description = g_string_free (str, FALSE); - else - g_string_free (str, TRUE); - - o_config_main_file = NULL; + } + NM_SET_OUT (out_config_main_file, g_steal_pointer (&o_config_main_file)); return keyfile; } From b5aec6b7e768cffaa47d2d9311280ab5cf668d67 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 23 Oct 2016 10:29:51 +0200 Subject: [PATCH 4/4] config: cleanup ownership handling of @keyfile in read_entire_config() --- src/nm-config.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/nm-config.c b/src/nm-config.c index fbd71a8db4..39593850f7 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -953,7 +953,7 @@ read_entire_config (const NMConfigCmdLineOptions *cli, char **out_config_description, GError **error) { - GKeyFile *keyfile; + gs_unref_keyfile GKeyFile *keyfile = NULL; gs_unref_ptrarray GPtrArray *system_confs = NULL; gs_unref_ptrarray GPtrArray *confs = NULL; gs_unref_ptrarray GPtrArray *run_confs = NULL; @@ -983,10 +983,8 @@ read_entire_config (const NMConfigCmdLineOptions *cli, continue; } - if (!read_config (keyfile, FALSE, system_config_dir, filename, error)) { - g_key_file_free (keyfile); + if (!read_config (keyfile, FALSE, system_config_dir, filename, error)) return NULL; - } i++; } @@ -999,26 +997,20 @@ read_entire_config (const NMConfigCmdLineOptions *cli, continue; } - if (!read_config (keyfile, FALSE, RUN_CONFIG_DIR, filename, error)) { - g_key_file_free (keyfile); + if (!read_config (keyfile, FALSE, RUN_CONFIG_DIR, filename, error)) return NULL; - } i++; } /* First read the base config file */ - if (!read_base_config (keyfile, cli ? cli->config_main_file : NULL, &o_config_main_file, error)) { - g_key_file_free (keyfile); + if (!read_base_config (keyfile, cli ? cli->config_main_file : NULL, &o_config_main_file, error)) return NULL; - } g_assert (o_config_main_file); for (i = 0; i < confs->len; i++) { - if (!read_config (keyfile, FALSE, config_dir, confs->pdata[i], error)) { - g_key_file_free (keyfile); + if (!read_config (keyfile, FALSE, config_dir, confs->pdata[i], error)) return NULL; - } } /* Merge settings from command line. They overwrite everything read from @@ -1047,7 +1039,7 @@ read_entire_config (const NMConfigCmdLineOptions *cli, *out_config_description = g_string_free (str, FALSE); } NM_SET_OUT (out_config_main_file, g_steal_pointer (&o_config_main_file)); - return keyfile; + return g_steal_pointer (&keyfile); } static gboolean