shared/conf-parser: collapse pkgdir and conf_file args into one

This essentially reverts 5656cdfeea. I find it
much easier to understand what is going on when the
path-relative-to-the-search-path is passed in full, instead of being constructed
from two parts, with one of the parts being implicit in some places.

Also, we call 'systemd-analyze cat-config <path>' with <path> with the same
meaning, so this makes the internal and external APIs more consistent.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-03-07 18:49:44 +01:00
parent 76d75d8b7b
commit e5abff372d
16 changed files with 24 additions and 36 deletions
+4 -6
View File
@@ -600,9 +600,8 @@ static int config_parse_many_files(
/* Parse one main config file located in /etc/$pkgdir and its drop-ins, which is what all systemd daemons
* do. */
int config_parse_config_file_full(
int config_parse_config_file(
const char *conf_file,
const char *pkgdir,
const char *sections,
ConfigItemLookup lookup,
const void *table,
@@ -614,7 +613,6 @@ int config_parse_config_file_full(
int r;
assert(conf_file);
assert(pkgdir);
/* build the dropin dir list */
dropin_dirs = new0(char*, strv_length(conf_paths) + 1);
@@ -628,10 +626,10 @@ int config_parse_config_file_full(
STRV_FOREACH(p, conf_paths) {
char *d;
d = strjoin(*p, pkgdir, "/", conf_file, ".d");
d = strjoin(*p, conf_file, ".d");
if (!d) {
if (flags & CONFIG_PARSE_WARN)
return log_oom();
log_oom();
return -ENOMEM;
}
@@ -642,7 +640,7 @@ int config_parse_config_file_full(
if (r < 0)
return r;
const char *sysconf_file = strjoina(SYSCONF_DIR, "/", pkgdir, "/", conf_file);
const char *sysconf_file = strjoina(SYSCONF_DIR, "/", conf_file);
return config_parse_many_files(STRV_MAKE_CONST(sysconf_file), dropins,
sections, lookup, table, flags, userdata, NULL);
+2 -13
View File
@@ -93,25 +93,14 @@ int config_parse(
void *userdata,
struct stat *ret_stat); /* possibly NULL */
int config_parse_config_file_full(
const char *conf_file,
const char *pkgdir,
int config_parse_config_file(
const char *conf_file, /* a path like "systemd/frobnicator.conf" */
const char *sections, /* nulstr */
ConfigItemLookup lookup,
const void *table,
ConfigParseFlags flags,
void *userdata);
static inline int config_parse_config_file(
const char *conf_file,
const char *sections, /* nulstr */
ConfigItemLookup lookup,
const void *table,
ConfigParseFlags flags,
void *userdata) {
return config_parse_config_file_full(conf_file, "systemd", sections, lookup, table, flags, userdata);
}
int config_parse_many(
const char* const* conf_files, /* possibly empty */
const char* const* conf_file_dirs,
+1 -1
View File
@@ -145,7 +145,7 @@ int parse_sleep_config(SleepConfig **ret) {
{}
};
(void) config_parse_config_file("sleep.conf", "Sleep\0",
(void) config_parse_config_file("systemd/sleep.conf", "Sleep\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN, NULL);
+2 -3
View File
@@ -28,9 +28,8 @@ int udev_parse_config_full(const ConfigTableItem config_table[]) {
assert(config_table);
r = config_parse_config_file_full(
"udev.conf",
"udev",
r = config_parse_config_file(
"udev/udev.conf",
/* sections = */ NULL,
config_item_table_lookup,
config_table,