summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2023-01-27 11:32:27 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-03-13 19:31:21 +0100
commit07e0ffc8234b8212a6509fe6dbc1811be03fc3ae (patch)
treec6e3c15a443bad9f9f6c9c2f220e3fa352cc0f35 /src
parentMerge pull request #26781 from mrc0mmand/tests-again (diff)
downloadsystemd-07e0ffc8234b8212a6509fe6dbc1811be03fc3ae.tar.xz
systemd-07e0ffc8234b8212a6509fe6dbc1811be03fc3ae.zip
conf: replace config_parse_many_nulstr() with config_parse_config_file()
All daemons use a similar scheme to read their main config files and theirs drop-ins. The main config files are always stored in /etc/systemd directory and it's easy enough to construct the name of the drop-in directories based on the name of the main config file. Hence the new helper does that internally, which allows to reduce and simplify the args passed previously to config_parse_many_nulstr(). Besides the overall code simplification it results: 16 files changed, 87 insertions(+), 159 deletions(-) it allows to identify clearly the locations in the code where configuration files are parsed.
Diffstat (limited to 'src')
-rw-r--r--src/basic/constants.h6
-rw-r--r--src/core/main.c33
-rw-r--r--src/coredump/coredump.c11
-rw-r--r--src/home/homed-conf.c17
-rw-r--r--src/journal-remote/journal-remote-main.c11
-rw-r--r--src/journal-remote/journal-upload.c11
-rw-r--r--src/journal/journald-server.c32
-rw-r--r--src/login/logind-core.c10
-rw-r--r--src/network/networkd-conf.c19
-rw-r--r--src/oom/oomd.c11
-rw-r--r--src/pstore/pstore.c11
-rw-r--r--src/resolve/resolved-conf.c11
-rw-r--r--src/shared/conf-parser.c45
-rw-r--r--src/shared/conf-parser.h8
-rw-r--r--src/shared/sleep-config.c11
-rw-r--r--src/timesync/timesyncd-conf.c11
16 files changed, 100 insertions, 158 deletions
diff --git a/src/basic/constants.h b/src/basic/constants.h
index 3e935f1bca..3f96786da9 100644
--- a/src/basic/constants.h
+++ b/src/basic/constants.h
@@ -67,10 +67,8 @@
# define _CONF_PATHS_SPLIT_USR(n)
#endif
-/* Return a nulstr for a standard cascade of configuration paths,
- * suitable to pass to conf_files_list_nulstr() or config_parse_many_nulstr()
- * to implement drop-in directories for extending configuration
- * files. */
+/* Return a nulstr for a standard cascade of configuration paths, suitable to pass to
+ * conf_files_list_nulstr() to implement drop-in directories for extending configuration files. */
#define CONF_PATHS_NULSTR(n) \
"/etc/" n "\0" \
"/run/" n "\0" \
diff --git a/src/core/main.c b/src/core/main.c
index 3f63150f31..5f8f251e9a 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -704,33 +704,32 @@ static int parse_config_file(void) {
{}
};
- _cleanup_strv_free_ char **files = NULL, **dirs = NULL;
- const char *suffix;
- int r;
-
if (arg_runtime_scope == RUNTIME_SCOPE_SYSTEM)
- suffix = "system.conf.d";
+ (void) config_parse_config_file("system.conf",
+ "Manager\0",
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN,
+ NULL);
else {
+ _cleanup_strv_free_ char **files = NULL, **dirs = NULL;
+ int r;
+
assert(arg_runtime_scope == RUNTIME_SCOPE_USER);
r = manager_find_user_config_paths(&files, &dirs);
if (r < 0)
return log_error_errno(r, "Failed to determine config file paths: %m");
- suffix = "user.conf.d";
+ (void) config_parse_many(
+ (const char* const*) files,
+ (const char* const*) dirs,
+ "user.conf.d",
+ "Manager\0",
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN,
+ NULL, NULL, NULL);
}
- (void) config_parse_many(
- (const char* const*) (files ?: STRV_MAKE(PKGSYSCONFDIR "/system.conf")),
- (const char* const*) (dirs ?: CONF_PATHS_STRV("systemd")),
- suffix,
- "Manager\0",
- config_item_table_lookup, items,
- CONFIG_PARSE_WARN,
- NULL,
- NULL,
- NULL);
-
/* Traditionally "0" was used to turn off the default unit timeouts. Fix this up so that we use
* USEC_INFINITY like everywhere else. */
if (arg_default_timeout_start_usec <= 0)
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
index d5d1f49d08..e715fd232b 100644
--- a/src/coredump/coredump.c
+++ b/src/coredump/coredump.c
@@ -171,14 +171,9 @@ static int parse_config(void) {
{}
};
- return config_parse_many_nulstr(
- PKGSYSCONFDIR "/coredump.conf",
- CONF_PATHS_NULSTR("systemd/coredump.conf.d"),
- "Coredump\0",
- config_item_table_lookup, items,
- CONFIG_PARSE_WARN,
- NULL,
- NULL);
+ return config_parse_config_file("coredump.conf", "Coredump\0",
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN, NULL);
}
static uint64_t storage_size_max(void) {
diff --git a/src/home/homed-conf.c b/src/home/homed-conf.c
index 429a6e3c55..ffa4bb3bd7 100644
--- a/src/home/homed-conf.c
+++ b/src/home/homed-conf.c
@@ -6,23 +6,12 @@
#include "homed-conf.h"
int manager_parse_config_file(Manager *m) {
- int r;
assert(m);
- r = config_parse_many_nulstr(
- PKGSYSCONFDIR "/homed.conf",
- CONF_PATHS_NULSTR("systemd/homed.conf.d"),
- "Home\0",
- config_item_perf_lookup, homed_gperf_lookup,
- CONFIG_PARSE_WARN,
- m,
- NULL);
- if (r < 0)
- return r;
-
- return 0;
-
+ return config_parse_config_file("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 e620b60a31..956c96c5e3 100644
--- a/src/journal-remote/journal-remote-main.c
+++ b/src/journal-remote/journal-remote-main.c
@@ -769,14 +769,9 @@ static int parse_config(void) {
{}
};
- return config_parse_many_nulstr(
- PKGSYSCONFDIR "/journal-remote.conf",
- CONF_PATHS_NULSTR("systemd/journal-remote.conf.d"),
- "Remote\0",
- config_item_table_lookup, items,
- CONFIG_PARSE_WARN,
- NULL,
- NULL);
+ return config_parse_config_file("journal-remote.conf", "Remote\0",
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN, NULL);
}
static int help(void) {
diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c
index fc55f13bab..e42516c799 100644
--- a/src/journal-remote/journal-upload.c
+++ b/src/journal-remote/journal-upload.c
@@ -568,14 +568,9 @@ static int parse_config(void) {
{}
};
- return config_parse_many_nulstr(
- PKGSYSCONFDIR "/journal-upload.conf",
- CONF_PATHS_NULSTR("systemd/journal-upload.conf.d"),
- "Upload\0",
- config_item_table_lookup, items,
- CONFIG_PARSE_WARN,
- NULL,
- NULL);
+ return config_parse_config_file("journal-upload.conf", "Upload\0",
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN, NULL);
}
static int help(void) {
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 3e3b6d44d6..a8958fcb0c 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1853,36 +1853,16 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
}
static int server_parse_config_file(Server *s) {
- int r;
+ const char *conf_file = "journald.conf";
assert(s);
- if (s->namespace) {
- const char *namespaced, *dropin_dirname;
-
- /* If we are running in namespace mode, load the namespace specific configuration file, and nothing else */
- namespaced = strjoina(PKGSYSCONFDIR "/journald@", s->namespace, ".conf");
- dropin_dirname = strjoina("journald@", s->namespace, ".conf.d");
-
- r = config_parse_many(
- STRV_MAKE_CONST(namespaced),
- (const char* const*) CONF_PATHS_STRV("systemd"),
- dropin_dirname,
- "Journal\0",
- config_item_perf_lookup, journald_gperf_lookup,
- CONFIG_PARSE_WARN, s, NULL, NULL);
- if (r < 0)
- return r;
-
- return 0;
- }
+ if (s->namespace)
+ conf_file = strjoina("journald@", s->namespace, ".conf");
- return config_parse_many_nulstr(
- PKGSYSCONFDIR "/journald.conf",
- CONF_PATHS_NULSTR("systemd/journald.conf.d"),
- "Journal\0",
- config_item_perf_lookup, journald_gperf_lookup,
- CONFIG_PARSE_WARN, s, NULL);
+ return config_parse_config_file(conf_file, "Journal\0",
+ config_item_perf_lookup, journald_gperf_lookup,
+ CONFIG_PARSE_WARN, 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 7d4ff6c98b..618850feba 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -78,13 +78,9 @@ void manager_reset_config(Manager *m) {
int manager_parse_config_file(Manager *m) {
assert(m);
- return config_parse_many_nulstr(
- PKGSYSCONFDIR "/logind.conf",
- CONF_PATHS_NULSTR("systemd/logind.conf.d"),
- "Login\0",
- config_item_perf_lookup, logind_gperf_lookup,
- CONFIG_PARSE_WARN, m,
- NULL);
+ return config_parse_config_file("logind.conf", "Login\0",
+ config_item_perf_lookup, logind_gperf_lookup,
+ CONFIG_PARSE_WARN, 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 f73b2d43c7..063732a3b4 100644
--- a/src/network/networkd-conf.c
+++ b/src/network/networkd-conf.c
@@ -14,17 +14,14 @@ int manager_parse_config_file(Manager *m) {
assert(m);
- r = config_parse_many_nulstr(
- PKGSYSCONFDIR "/networkd.conf",
- CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
- "Network\0"
- "DHCPv4\0"
- "DHCPv6\0"
- "DHCP\0",
- config_item_perf_lookup, networkd_gperf_lookup,
- CONFIG_PARSE_WARN,
- m,
- NULL);
+ r = config_parse_config_file("networkd.conf",
+ "Network\0"
+ "DHCPv4\0"
+ "DHCPv6\0"
+ "DHCP\0",
+ config_item_perf_lookup, networkd_gperf_lookup,
+ CONFIG_PARSE_WARN,
+ m);
if (r < 0)
return r;
diff --git a/src/oom/oomd.c b/src/oom/oomd.c
index 2d6819daee..28405e2f64 100644
--- a/src/oom/oomd.c
+++ b/src/oom/oomd.c
@@ -31,14 +31,9 @@ static int parse_config(void) {
{}
};
- return config_parse_many_nulstr(PKGSYSCONFDIR "/oomd.conf",
- CONF_PATHS_NULSTR("systemd/oomd.conf.d"),
- "OOM\0",
- config_item_table_lookup,
- items,
- CONFIG_PARSE_WARN,
- NULL,
- NULL);
+ return config_parse_config_file("oomd.conf", "OOM\0",
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN, NULL);
}
static int help(void) {
diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c
index e8c2145060..fa6d6ec0e9 100644
--- a/src/pstore/pstore.c
+++ b/src/pstore/pstore.c
@@ -77,14 +77,9 @@ static int parse_config(void) {
{}
};
- return config_parse_many_nulstr(
- PKGSYSCONFDIR "/pstore.conf",
- CONF_PATHS_NULSTR("systemd/pstore.conf.d"),
- "PStore\0",
- config_item_table_lookup, items,
- CONFIG_PARSE_WARN,
- NULL,
- NULL);
+ return config_parse_config_file("pstore.conf", "PStore\0",
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN, NULL);
}
/* File list handling - PStoreEntry is the struct and
diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c
index d6929984e9..70a6f99450 100644
--- a/src/resolve/resolved-conf.c
+++ b/src/resolve/resolved-conf.c
@@ -563,14 +563,9 @@ int manager_parse_config_file(Manager *m) {
assert(m);
- r = config_parse_many_nulstr(
- PKGSYSCONFDIR "/resolved.conf",
- CONF_PATHS_NULSTR("systemd/resolved.conf.d"),
- "Resolve\0",
- config_item_perf_lookup, resolved_gperf_lookup,
- CONFIG_PARSE_WARN,
- m,
- NULL);
+ r = config_parse_config_file("resolved.conf", "Resolve\0",
+ config_item_perf_lookup, resolved_gperf_lookup,
+ CONFIG_PARSE_WARN, m);
if (r < 0)
return r;
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 29051ca0e3..138a3a8cc9 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -533,27 +533,52 @@ static int config_parse_many_files(
return 0;
}
-/* Parse each config file in the directories specified as nulstr. */
-int config_parse_many_nulstr(
+/* Parse one main config file located in /etc/systemd and its drop-ins, which is what all systemd daemons
+ * do. */
+int config_parse_config_file(
const char *conf_file,
- const char *conf_file_dirs,
const char *sections,
ConfigItemLookup lookup,
const void *table,
ConfigParseFlags flags,
- void *userdata,
- Hashmap **ret_stats_by_path) {
+ void *userdata) {
- _cleanup_strv_free_ char **files = NULL;
+ _cleanup_strv_free_ char **dropins = NULL, **dropin_dirs = NULL;
+ char **conf_paths = CONF_PATHS_STRV("");
int r;
- r = conf_files_list_nulstr(&files, ".conf", NULL, 0, conf_file_dirs);
+ 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, "systemd/", conf_file, ".d");
+ if (!d) {
+ if (flags & CONFIG_PARSE_WARN)
+ return 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;
- return config_parse_many_files(STRV_MAKE_CONST(conf_file),
- files, sections, lookup, table, flags, userdata,
- ret_stats_by_path);
+ const char *sysconf_file = strjoina(PKGSYSCONFDIR, "/", conf_file);
+
+ return config_parse_many_files(STRV_MAKE_CONST(sysconf_file), dropins,
+ sections, lookup, table, flags, userdata, NULL);
}
static int config_get_dropin_files(
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index e1765f5874..e5aeeac687 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -93,15 +93,13 @@ int config_parse(
void *userdata,
struct stat *ret_stat); /* possibly NULL */
-int config_parse_many_nulstr(
- const char *conf_file, /* possibly NULL */
- const char *conf_file_dirs, /* nulstr */
+int config_parse_config_file(
+ const char *conf_file,
const char *sections, /* nulstr */
ConfigItemLookup lookup,
const void *table,
ConfigParseFlags flags,
- void *userdata,
- Hashmap **ret_stats_by_path); /* possibly NULL */
+ void *userdata);
int config_parse_many(
const char* const* conf_files, /* possibly empty */
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index 1eb00717ca..2e3b47ddca 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -93,14 +93,9 @@ int parse_sleep_config(SleepConfig **ret_sleep_config) {
{}
};
- (void) config_parse_many_nulstr(
- PKGSYSCONFDIR "/sleep.conf",
- CONF_PATHS_NULSTR("systemd/sleep.conf.d"),
- "Sleep\0",
- config_item_table_lookup, items,
- CONFIG_PARSE_WARN,
- NULL,
- NULL);
+ (void) config_parse_config_file("sleep.conf", "Sleep\0",
+ config_item_table_lookup, items,
+ CONFIG_PARSE_WARN, NULL);
/* use default values unless set */
sc->allow[SLEEP_SUSPEND] = allow_suspend != 0;
diff --git a/src/timesync/timesyncd-conf.c b/src/timesync/timesyncd-conf.c
index 3e6cb43597..9c0b6f7ce1 100644
--- a/src/timesync/timesyncd-conf.c
+++ b/src/timesync/timesyncd-conf.c
@@ -102,14 +102,9 @@ int manager_parse_config_file(Manager *m) {
assert(m);
- r = config_parse_many_nulstr(
- PKGSYSCONFDIR "/timesyncd.conf",
- CONF_PATHS_NULSTR("systemd/timesyncd.conf.d"),
- "Time\0",
- config_item_perf_lookup, timesyncd_gperf_lookup,
- CONFIG_PARSE_WARN,
- m,
- NULL);
+ r = config_parse_config_file("timesyncd.conf", "Time\0",
+ config_item_perf_lookup, timesyncd_gperf_lookup,
+ CONFIG_PARSE_WARN, m);
if (r < 0)
return r;