various: use new config loader instead of config_parse_config_file()

This means the main config file is loaded also from /run and /usr.

We should load the main config file from all the places where we load drop-ins.

I realize I had a giant blind spot: I always assumed that we load config files
from /etc, /run, /usr/local/lib, /usr/lib. But it turns out that we only used
those paths for drop-ins. For the main config file, we only looked in /etc. The
docs actually partially described this behaviour, i.e. most SYNOPSIS sections
and some parts of the text, but not others.

This is strange, because 6495361c7d was completely
bogus with the behaviour before this patch. We had a huge discussion before it
was merged, and clearly nobody noticed this. Similarly, in the previous version
of the current pull request, we had a long discussion about the appropriate
order of directories, and apparently nobody noticed that there was no order,
because only looked in one directory. So the blind spot seems to have been
shared.

Also, systemd-analyze cat-config behaved incorrectly, i.e. its behaviour matches
the new behaviour.

Possibly, in the future it'll make it easier to add support for --root.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2024-02-22 10:50:05 +01:00
parent e7e52ff9b6
commit 6378f257e7
16 changed files with 97 additions and 103 deletions

View File

@ -736,11 +736,12 @@ static int parse_config_file(void) {
};
if (arg_runtime_scope == RUNTIME_SCOPE_SYSTEM)
(void) config_parse_config_file("systemd/system.conf",
"Manager\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN,
NULL);
(void) config_parse_standard_file_with_dropins(
"systemd/system.conf",
"Manager\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN,
/* userdata= */ NULL);
else {
_cleanup_strv_free_ char **files = NULL, **dirs = NULL;
int r;

View File

@ -178,7 +178,7 @@ static int parse_config(void) {
int r;
r = config_parse_config_file(
r = config_parse_standard_file_with_dropins(
"systemd/coredump.conf",
"Coredump\0",
config_item_table_lookup,

View File

@ -9,9 +9,12 @@ int manager_parse_config_file(Manager *m) {
assert(m);
return config_parse_config_file("systemd/homed.conf", "Home\0",
config_item_perf_lookup, homed_gperf_lookup,
CONFIG_PARSE_WARN, m);
return config_parse_standard_file_with_dropins(
"systemd/homed.conf",
"Home\0",
config_item_perf_lookup, homed_gperf_lookup,
CONFIG_PARSE_WARN,
m);
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_default_storage, user_storage, UserStorage, "Failed to parse default storage setting");

View File

@ -746,9 +746,12 @@ static int parse_config(void) {
{}
};
return config_parse_config_file("systemd/journal-remote.conf", "Remote\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN, NULL);
return config_parse_standard_file_with_dropins(
"systemd/journal-remote.conf",
"Remote\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN,
/* userdata= */ NULL);
}
static int help(void) {

View File

@ -531,9 +531,12 @@ static int parse_config(void) {
{}
};
return config_parse_config_file("systemd/journal-upload.conf", "Upload\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN, NULL);
return config_parse_standard_file_with_dropins(
"systemd/journal-upload.conf",
"Upload\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN,
/* userdata= */ NULL);
}
static int help(void) {

View File

@ -1893,9 +1893,12 @@ static int server_parse_config_file(Server *s) {
else
conf_file = "systemd/journald.conf";
return config_parse_config_file(conf_file, "Journal\0",
config_item_perf_lookup, journald_gperf_lookup,
CONFIG_PARSE_WARN, s);
return config_parse_standard_file_with_dropins(
conf_file,
"Journal\0",
config_item_perf_lookup, journald_gperf_lookup,
CONFIG_PARSE_WARN,
/* userdata= */ s);
}
static int server_dispatch_sync(sd_event_source *es, usec_t t, void *userdata) {

View File

@ -82,9 +82,12 @@ void manager_reset_config(Manager *m) {
int manager_parse_config_file(Manager *m) {
assert(m);
return config_parse_config_file("systemd/logind.conf", "Login\0",
config_item_perf_lookup, logind_gperf_lookup,
CONFIG_PARSE_WARN, m);
return config_parse_standard_file_with_dropins(
"systemd/logind.conf",
"Login\0",
config_item_perf_lookup, logind_gperf_lookup,
CONFIG_PARSE_WARN,
/* userdata= */ m);
}
int manager_add_device(Manager *m, const char *sysfs, bool master, Device **ret_device) {

View File

@ -14,14 +14,15 @@ int manager_parse_config_file(Manager *m) {
assert(m);
r = config_parse_config_file("systemd/networkd.conf",
"Network\0"
"DHCPv4\0"
"DHCPv6\0"
"DHCP\0",
config_item_perf_lookup, networkd_gperf_lookup,
CONFIG_PARSE_WARN,
m);
r = config_parse_standard_file_with_dropins(
"systemd/networkd.conf",
"Network\0"
"DHCPv4\0"
"DHCPv6\0"
"DHCP\0",
config_item_perf_lookup, networkd_gperf_lookup,
CONFIG_PARSE_WARN,
/* userdata= */ m);
if (r < 0)
return r;

View File

@ -31,9 +31,12 @@ static int parse_config(void) {
{}
};
return config_parse_config_file("systemd/oomd.conf", "OOM\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN, NULL);
return config_parse_standard_file_with_dropins(
"systemd/oomd.conf",
"OOM\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN,
/* userdata= */ NULL);
}
static int help(void) {

View File

@ -77,9 +77,12 @@ static int parse_config(void) {
{}
};
return config_parse_config_file("systemd/pstore.conf", "PStore\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN, NULL);
return config_parse_standard_file_with_dropins(
"systemd/pstore.conf",
"PStore\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN,
/* userdata= */ NULL);
}
/* File list handling - PStoreEntry is the struct and

View File

@ -570,9 +570,12 @@ int manager_parse_config_file(Manager *m) {
assert(m);
r = config_parse_config_file("systemd/resolved.conf", "Resolve\0",
config_item_perf_lookup, resolved_gperf_lookup,
CONFIG_PARSE_WARN, m);
r = config_parse_standard_file_with_dropins(
"systemd/resolved.conf",
"Resolve\0",
config_item_perf_lookup, resolved_gperf_lookup,
CONFIG_PARSE_WARN,
/* userdata= */ m);
if (r < 0)
return r;

View File

@ -595,54 +595,6 @@ static int config_parse_many_files(
return 0;
}
/* 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(
const char *conf_file,
const char *sections,
ConfigItemLookup lookup,
const void *table,
ConfigParseFlags flags,
void *userdata) {
_cleanup_strv_free_ char **dropins = NULL, **dropin_dirs = NULL;
char **conf_paths = CONF_PATHS_STRV("");
int r;
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, conf_file, ".d");
if (!d) {
if (flags & CONFIG_PARSE_WARN)
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;
const char *sysconf_file = strjoina(SYSCONF_DIR, "/", conf_file);
return config_parse_many_files(NULL, STRV_MAKE_CONST(sysconf_file), dropins,
sections, lookup, table, flags, userdata, NULL);
}
/* Parse each config file in the directories specified as strv. */
int config_parse_many(
const char* const* conf_files,

View File

@ -93,14 +93,6 @@ int config_parse(
void *userdata,
struct stat *ret_stat); /* possibly NULL */
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);
int config_parse_many(
const char* const* conf_files, /* possibly empty */
const char* const* conf_file_dirs,
@ -125,6 +117,25 @@ int config_parse_standard_file_with_dropins_full(
Hashmap **ret_stats_by_path, /* possibly NULL */
char ***ret_dropin_files); /* possibly NULL */
static inline int config_parse_standard_file_with_dropins(
const char *main_file, /* A path like "systemd/frobnicator.conf" */
const char *sections, /* nulstr */
ConfigItemLookup lookup,
const void *table,
ConfigParseFlags flags,
void *userdata) {
return config_parse_standard_file_with_dropins_full(
/* root= */ NULL,
main_file,
sections,
lookup,
table,
flags,
userdata,
/* ret_stats_by_path= */ NULL,
/* ret_dropin_files= */ NULL);
}
int config_get_stats_by_path(
const char *suffix,
const char *root,

View File

@ -145,9 +145,12 @@ int parse_sleep_config(SleepConfig **ret) {
{}
};
(void) config_parse_config_file("systemd/sleep.conf", "Sleep\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN, NULL);
(void) config_parse_standard_file_with_dropins(
"systemd/sleep.conf",
"Sleep\0",
config_item_table_lookup, items,
CONFIG_PARSE_WARN,
/* userdata= */ NULL);
/* use default values unless set */
sc->allow[SLEEP_SUSPEND] = allow_suspend != 0;

View File

@ -28,11 +28,10 @@ int udev_parse_config_full(const ConfigTableItem config_table[]) {
assert(config_table);
r = config_parse_config_file(
r = config_parse_standard_file_with_dropins(
"udev/udev.conf",
/* sections = */ NULL,
config_item_table_lookup,
config_table,
config_item_table_lookup, config_table,
CONFIG_PARSE_WARN,
/* userdata = */ NULL);
if (r == -ENOENT)

View File

@ -102,9 +102,12 @@ int manager_parse_config_file(Manager *m) {
assert(m);
r = config_parse_config_file("systemd/timesyncd.conf", "Time\0",
config_item_perf_lookup, timesyncd_gperf_lookup,
CONFIG_PARSE_WARN, m);
r = config_parse_standard_file_with_dropins(
"systemd/timesyncd.conf",
"Time\0",
config_item_perf_lookup, timesyncd_gperf_lookup,
CONFIG_PARSE_WARN,
/* userdata= */ m);
if (r < 0)
return r;