diff options
author | Franck Bui <fbui@suse.com> | 2023-01-27 11:32:27 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-13 19:31:21 +0100 |
commit | 07e0ffc8234b8212a6509fe6dbc1811be03fc3ae (patch) | |
tree | c6e3c15a443bad9f9f6c9c2f220e3fa352cc0f35 /src/shared/conf-parser.c | |
parent | Merge pull request #26781 from mrc0mmand/tests-again (diff) | |
download | systemd-07e0ffc8234b8212a6509fe6dbc1811be03fc3ae.tar.xz systemd-07e0ffc8234b8212a6509fe6dbc1811be03fc3ae.zip |
conf: replace config_parse_many_nulstr() with config_parse_config_file()
All daemons use a similar scheme to read their main config files and theirs
drop-ins. The main config files are always stored in /etc/systemd directory and
it's easy enough to construct the name of the drop-in directories based on the
name of the main config file.
Hence the new helper does that internally, which allows to reduce and simplify
the args passed previously to config_parse_many_nulstr().
Besides the overall code simplification it results:
16 files changed, 87 insertions(+), 159 deletions(-)
it allows to identify clearly the locations in the code where configuration
files are parsed.
Diffstat (limited to 'src/shared/conf-parser.c')
-rw-r--r-- | src/shared/conf-parser.c | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 29051ca0e3..138a3a8cc9 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -533,27 +533,52 @@ static int config_parse_many_files( return 0; } -/* Parse each config file in the directories specified as nulstr. */ -int config_parse_many_nulstr( +/* Parse one main config file located in /etc/systemd and its drop-ins, which is what all systemd daemons + * do. */ +int config_parse_config_file( const char *conf_file, - const char *conf_file_dirs, const char *sections, ConfigItemLookup lookup, const void *table, ConfigParseFlags flags, - void *userdata, - Hashmap **ret_stats_by_path) { + void *userdata) { - _cleanup_strv_free_ char **files = NULL; + _cleanup_strv_free_ char **dropins = NULL, **dropin_dirs = NULL; + char **conf_paths = CONF_PATHS_STRV(""); int r; - r = conf_files_list_nulstr(&files, ".conf", NULL, 0, conf_file_dirs); + assert(conf_file); + + /* build the dropin dir list */ + dropin_dirs = new0(char*, strv_length(conf_paths) + 1); + if (!dropin_dirs) { + if (flags & CONFIG_PARSE_WARN) + return log_oom(); + return -ENOMEM; + } + + size_t i = 0; + STRV_FOREACH(p, conf_paths) { + char *d; + + d = strjoin(*p, "systemd/", conf_file, ".d"); + if (!d) { + if (flags & CONFIG_PARSE_WARN) + return log_oom(); + return -ENOMEM; + } + + dropin_dirs[i++] = d; + } + + r = conf_files_list_strv(&dropins, ".conf", NULL, 0, (const char**) dropin_dirs); if (r < 0) return r; - return config_parse_many_files(STRV_MAKE_CONST(conf_file), - files, sections, lookup, table, flags, userdata, - ret_stats_by_path); + const char *sysconf_file = strjoina(PKGSYSCONFDIR, "/", conf_file); + + return config_parse_many_files(STRV_MAKE_CONST(sysconf_file), dropins, + sections, lookup, table, flags, userdata, NULL); } static int config_get_dropin_files( |