diff options
author | Thomas Haller <thaller@redhat.com> | 2016-10-23 11:42:51 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-10-23 11:42:51 +0200 |
commit | 3248b387a29ff35fedd9cdfb9f784c985298d428 (patch) | |
tree | e58ed1ca0fa775bfb139d259632a948c16773816 | |
parent | 4b965d0cf685d4cd2d329439671ae11b46482ce3 (diff) | |
parent | b5aec6b7e768cffaa47d2d9311280ab5cf668d67 (diff) | |
download | NetworkManager-3248b387a29ff35fedd9cdfb9f784c985298d428.tar.gz |
config: merge branch 'th/run-conf.d-bgo773069'
https://bugzilla.gnome.org/show_bug.cgi?id=773069
-rw-r--r-- | src/nm-config.c | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/src/nm-config.c b/src/nm-config.c index 46fce99820..39593850f7 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" @@ -926,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, @@ -934,12 +953,12 @@ 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; 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); @@ -952,36 +971,46 @@ 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]; - /* 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; } - 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++; + } + + 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)) + 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 @@ -1000,39 +1029,17 @@ 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; - return keyfile; + } + NM_SET_OUT (out_config_main_file, g_steal_pointer (&o_config_main_file)); + return g_steal_pointer (&keyfile); } static gboolean |