various: use new config loader instead of config_parse_config_file()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 22 Feb 2024 09:50:05 +0000 (10:50 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Mar 2024 18:14:36 +0000 (19:14 +0100)
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.

16 files changed:
src/core/main.c
src/coredump/coredump.c
src/home/homed-conf.c
src/journal-remote/journal-remote-main.c
src/journal-remote/journal-upload.c
src/journal/journald-server.c
src/login/logind-core.c
src/network/networkd-conf.c
src/oom/oomd.c
src/pstore/pstore.c
src/resolve/resolved-conf.c
src/shared/conf-parser.c
src/shared/conf-parser.h
src/shared/sleep-config.c
src/shared/udev-util.c
src/timesync/timesyncd-conf.c

index c7aec5df3b7ccb9f830dfe2897c845c36b03073e..d5c3bf0e46157d221815af5102332d63d6b20748 100644 (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;
index 4478dd1be29b506aa338c9b2126c8f18f6754e4b..b87bc52bde70cba181321347344188bbb2cd6d6b 100644 (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,
index 7fec29651deeb3ceeea04d5943287c2451057782..3f74096b648c6d8778df10aee79fccba9cacae99 100644 (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");
index 221b544fbcbf9b0ff3941a64716dd16836a03127..91cb2eefaa79a33ca458486573acefeb75d13c3d 100644 (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) {
index 6d080d73701aee1a646e041255fa14dd65e6b1a3..327b7bacd75417f629cc2a816133a703db109f57 100644 (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) {
index fa340da4bb1af955e9b8d04c56e0393c2b72d2bd..508263046cdfc6683bcd073c74551f086dece748 100644 (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) {
index 50346089bad58110b1af0d278bb08b15855f6200..e09bb9f2def27c6164d1eb10739385e5fbad219e 100644 (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) {
index af8d04b4a5d9ce9938d7f71cf88eb28dda2f4048..0f7015eb2545666235de7c6db12adbf5fd23b37a 100644 (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;
 
index a88f57da0a51e36134f718a6301c751cd9d5d19b..4f8c12bd543266c6c8baf0e559f2daea373293fd 100644 (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) {
index 529193c9e9217fdf763cece495a4e13efad50c92..e2dfc4d1a1ef7437587b24315e55dc3ba9ca0deb 100644 (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
index f88f29543756ebaa1629814a724f3acf80811537..b648c3e520342d3556ca27d58896adb8b90c16f7 100644 (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;
 
index 3e3e19b67fc18d10adff19ad35953b2ad9a3b3e6..74ba6e6d4cac8b238edea28eb00234958ae9d4b5 100644 (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,
index d3c65bbf92f937895da96d8df5c9ab8230797003..254d6cb70bc133e97c6a63a9760637eed003d5b6 100644 (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,
index 19b75a706dd580c1a1163f1b094653bef99ae310..c96f8485ddd5433b66536468f2f1198af84f6598 100644 (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;
index 205afc57233f7a0215e9d183c2b9817c5c38448b..0014b7236f5a566c9cfcf0cd9293c8923afc5f9c 100644 (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)
index 66f3d177e9acc45ab9ae31af0adb87b2476968ed..4b1d4ddbfe42dd4825d6ecc96f45fddd1e70d498 100644 (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;