shared/conf-parser: add function which implements the standard config file set

Also allow config_parse_many() to be called for config files without
sections. The test uses such a file.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-03-07 19:14:36 +01:00
parent d8a91c6b9f
commit e7e52ff9b6
3 changed files with 155 additions and 1 deletions
+44 -1
View File
@@ -662,7 +662,6 @@ int config_parse_many(
assert(conf_file_dirs);
assert(dropin_dirname);
assert(sections);
assert(table);
r = conf_files_list_dropins(&files, dropin_dirname, root, conf_file_dirs);
@@ -679,6 +678,50 @@ int config_parse_many(
return 0;
}
int config_parse_standard_file_with_dropins_full(
const char *root,
const char *main_file, /* A path like "systemd/frobnicator.conf" */
const char *sections,
ConfigItemLookup lookup,
const void *table,
ConfigParseFlags flags,
void *userdata,
Hashmap **ret_stats_by_path,
char ***ret_dropin_files) {
const char* const *conf_paths = (const char* const*) CONF_PATHS_STRV("");
_cleanup_strv_free_ char **configs = NULL;
int r;
/* Build the list of main config files */
r = strv_extend_strv_biconcat(&configs, root, conf_paths, main_file);
if (r < 0) {
if (flags & CONFIG_PARSE_WARN)
log_oom();
return r;
}
_cleanup_free_ char *dropin_dirname = strjoin(main_file, ".d");
if (!dropin_dirname) {
if (flags & CONFIG_PARSE_WARN)
log_oom();
return -ENOMEM;
}
return config_parse_many(
(const char* const*) configs,
conf_paths,
dropin_dirname,
root,
sections,
lookup,
table,
flags,
userdata,
ret_stats_by_path,
ret_dropin_files);
}
static int dropins_get_stats_by_path(
const char* conf_file,
const char* const* conf_file_dirs,
+11
View File
@@ -114,6 +114,17 @@ int config_parse_many(
Hashmap **ret_stats_by_path, /* possibly NULL */
char ***ret_drop_in_files); /* possibly NULL */
int config_parse_standard_file_with_dropins_full(
const char *root,
const char *main_file, /* A path like "systemd/frobnicator.conf" */
const char *sections,
ConfigItemLookup lookup,
const void *table,
ConfigParseFlags flags,
void *userdata,
Hashmap **ret_stats_by_path, /* possibly NULL */
char ***ret_dropin_files); /* possibly NULL */
int config_get_stats_by_path(
const char *suffix,
const char *root,