From: Zbigniew Jędrzejewski-Szmek Date: Thu, 22 Feb 2024 09:50:05 +0000 (+0100) Subject: various: use new config loader instead of config_parse_config_file() X-Git-Tag: v256-rc1~601^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6378f257e7e7856abc32cd9b5cb33bc4c63903be;p=thirdparty%2Fsystemd.git 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 6495361c7d5e8bf640841d1292ef6cfe1ea244cf 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. --- diff --git a/src/core/main.c b/src/core/main.c index c7aec5df3b7..d5c3bf0e461 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -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; diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 4478dd1be29..b87bc52bde7 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -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, diff --git a/src/home/homed-conf.c b/src/home/homed-conf.c index 7fec29651de..3f74096b648 100644 --- a/src/home/homed-conf.c +++ b/src/home/homed-conf.c @@ -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"); diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c index 221b544fbcb..91cb2eefaa7 100644 --- a/src/journal-remote/journal-remote-main.c +++ b/src/journal-remote/journal-remote-main.c @@ -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) { diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 6d080d73701..327b7bacd75 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -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) { diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index fa340da4bb1..508263046cd 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -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) { diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 50346089bad..e09bb9f2def 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -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) { diff --git a/src/network/networkd-conf.c b/src/network/networkd-conf.c index af8d04b4a5d..0f7015eb254 100644 --- a/src/network/networkd-conf.c +++ b/src/network/networkd-conf.c @@ -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; diff --git a/src/oom/oomd.c b/src/oom/oomd.c index a88f57da0a5..4f8c12bd543 100644 --- a/src/oom/oomd.c +++ b/src/oom/oomd.c @@ -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) { diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index 529193c9e92..e2dfc4d1a1e 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -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 diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index f88f2954375..b648c3e5203 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -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; diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 3e3e19b67fc..74ba6e6d4ca 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -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, diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index d3c65bbf92f..254d6cb70bc 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -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, diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 19b75a706dd..c96f8485ddd 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -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; diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 205afc57233..0014b7236f5 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -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) diff --git a/src/timesync/timesyncd-conf.c b/src/timesync/timesyncd-conf.c index 66f3d177e9a..4b1d4ddbfe4 100644 --- a/src/timesync/timesyncd-conf.c +++ b/src/timesync/timesyncd-conf.c @@ -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;