# 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" \
{}
};
- _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)
{}
};
- 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) {
#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");
{}
};
- 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) {
{}
};
- 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) {
}
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) {
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) {
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;
{}
};
- 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) {
{}
};
- 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
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;
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(
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 */
{}
};
- (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;
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;