From feff60ef3e6471699d1d3bd5fe6514897a5fc120 Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre Date: Tue, 14 Jun 2016 15:01:20 +0300 Subject: [PATCH] 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);