defs: rework CONF_DIRS_NULSTR() macro

The macro is generically useful for putting together search paths, hence
let's make it truly generic, by dropping the implicit ".d" appending it
does, and leave that to the caller. Also rename it from
CONF_DIRS_NULSTR() to CONF_PATHS_NULSTR(), since it's not strictly about
dirs that way, but any kind of file system path.

Also, mark CONF_DIR_SPLIT_USR() as internal macro by renaming it to
_CONF_PATHS_SPLIT_USR() so that the leading underscore indicates that
it's internal.
This commit is contained in:
Lennart Poettering 2015-11-10 15:57:21 +01:00
parent b1f044bbc4
commit 75eb615480
16 changed files with 41 additions and 35 deletions

View file

@ -76,17 +76,19 @@
#define NOTIFY_FD_MAX 768
#define NOTIFY_BUFFER_MAX PIPE_BUF
/* Return a nulstr for a standard cascade of configuration directories,
* suitable to pass to conf_files_list_nulstr or config_parse_many. */
#define CONF_DIRS_NULSTR(n) \
"/etc/" n ".d\0" \
"/run/" n ".d\0" \
"/usr/local/lib/" n ".d\0" \
"/usr/lib/" n ".d\0" \
CONF_DIR_SPLIT_USR(n)
#ifdef HAVE_SPLIT_USR
#define CONF_DIR_SPLIT_USR(n) "/lib/" n ".d\0"
#define _CONF_PATHS_SPLIT_USR(n) "/lib/" n "\0"
#else
#define CONF_DIR_SPLIT_USR(n)
#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()
* to implement drop-in directories for extending configuration
* files. */
#define CONF_PATHS_NULSTR(n) \
"/etc/" n "\0" \
"/run/" n "\0" \
"/usr/local/lib/" n "\0" \
"/usr/lib/" n "\0" \
_CONF_PATHS_SPLIT_USR(n)

View file

@ -37,7 +37,7 @@
#include "strv.h"
#include "util.h"
static const char conf_file_dirs[] = CONF_DIRS_NULSTR("binfmt");
static const char conf_file_dirs[] = CONF_PATHS_NULSTR("binfmt.d");
static int delete_rule(const char *rule) {
_cleanup_free_ char *x = NULL, *fn = NULL;

View file

@ -95,8 +95,6 @@ static void signal_handler(int sig) {
exiting = 1;
}
#define BOOTCHART_CONF "/etc/systemd/bootchart.conf"
#define BOOTCHART_MAX (16*1024*1024)
static void parse_conf(void) {
@ -117,8 +115,8 @@ static void parse_conf(void) {
{ NULL, NULL, NULL, 0, NULL }
};
config_parse_many(BOOTCHART_CONF,
CONF_DIRS_NULSTR("systemd/bootchart.conf"),
config_parse_many(PKGSYSCONFDIR "/bootchart.conf",
CONF_PATHS_NULSTR("systemd/bootchart.conf.d"),
NULL, config_item_table_lookup, items, true, NULL);
if (init != NULL)

View file

@ -682,8 +682,14 @@ static int parse_config_file(void) {
const char *fn, *conf_dirs_nulstr;
fn = arg_running_as == MANAGER_SYSTEM ? PKGSYSCONFDIR "/system.conf" : PKGSYSCONFDIR "/user.conf";
conf_dirs_nulstr = arg_running_as == MANAGER_SYSTEM ? CONF_DIRS_NULSTR("systemd/system.conf") : CONF_DIRS_NULSTR("systemd/user.conf");
fn = arg_running_as == MANAGER_SYSTEM ?
PKGSYSCONFDIR "/system.conf" :
PKGSYSCONFDIR "/user.conf";
conf_dirs_nulstr = arg_running_as == MANAGER_SYSTEM ?
CONF_PATHS_NULSTR("systemd/system.conf.d") :
CONF_PATHS_NULSTR("systemd/user.conf.d");
config_parse_many(fn, conf_dirs_nulstr, "Manager\0",
config_item_table_lookup, items, false, NULL);

View file

@ -1188,7 +1188,7 @@ static int parse_config(void) {
{}};
return config_parse_many(PKGSYSCONFDIR "/journal-remote.conf",
CONF_DIRS_NULSTR("systemd/journal-remote.conf"),
CONF_PATHS_NULSTR("systemd/journal-remote.conf.d"),
"Remote\0", config_item_table_lookup, items,
false, NULL);
}

View file

@ -542,7 +542,7 @@ static int parse_config(void) {
{}};
return config_parse_many(PKGSYSCONFDIR "/journal-upload.conf",
CONF_DIRS_NULSTR("systemd/journal-upload.conf"),
CONF_PATHS_NULSTR("systemd/journal-upload.conf.d"),
"Upload\0", config_item_table_lookup, items,
false, NULL);
}

View file

@ -126,8 +126,8 @@ static int parse_config(void) {
{}
};
return config_parse_many("/etc/systemd/coredump.conf",
CONF_DIRS_NULSTR("systemd/coredump.conf"),
return config_parse_many(PKGSYSCONFDIR "/coredump.conf",
CONF_PATHS_NULSTR("systemd/coredump.conf.d"),
"Coredump\0",
config_item_table_lookup, items,
false, NULL);

View file

@ -1360,8 +1360,8 @@ static int server_parse_proc_cmdline(Server *s) {
static int server_parse_config_file(Server *s) {
assert(s);
return config_parse_many("/etc/systemd/journald.conf",
CONF_DIRS_NULSTR("systemd/journald.conf"),
return config_parse_many(PKGSYSCONFDIR "/journald.conf",
CONF_PATHS_NULSTR("systemd/journald.conf.d"),
"Journal\0",
config_item_perf_lookup, journald_gperf_lookup,
false, s);

View file

@ -1102,8 +1102,8 @@ static int manager_run(Manager *m) {
static int manager_parse_config_file(Manager *m) {
assert(m);
return config_parse_many("/etc/systemd/logind.conf",
CONF_DIRS_NULSTR("systemd/logind.conf"),
return config_parse_many(PKGSYSCONFDIR "/logind.conf",
CONF_PATHS_NULSTR("systemd/logind.conf.d"),
"Login\0",
config_item_perf_lookup, logind_gperf_lookup,
false, m);

View file

@ -38,7 +38,7 @@
static char **arg_proc_cmdline_modules = NULL;
static const char conf_file_dirs[] = CONF_DIRS_NULSTR("modules-load");
static const char conf_file_dirs[] = CONF_PATHS_NULSTR("modules-load.d");
static void systemd_kmod_log(void *data, int priority, const char *file, int line,
const char *fn, const char *format, va_list args) {

View file

@ -150,8 +150,8 @@ int config_parse_support(
int manager_parse_config_file(Manager *m) {
assert(m);
return config_parse_many("/etc/systemd/resolved.conf",
CONF_DIRS_NULSTR("systemd/resolved.conf"),
return config_parse_many(PKGSYSCONFDIR "/resolved.conf",
CONF_PATHS_NULSTR("systemd/resolved.conf.d"),
"Resolve\0",
config_item_perf_lookup, resolved_gperf_lookup,
false, m);

View file

@ -54,7 +54,7 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states) {
};
config_parse_many(PKGSYSCONFDIR "/sleep.conf",
CONF_DIRS_NULSTR("systemd/sleep.conf"),
CONF_PATHS_NULSTR("systemd/sleep.conf.d"),
"Sleep\0", config_item_table_lookup, items,
false, NULL);

View file

@ -41,7 +41,7 @@
static char **arg_prefixes = NULL;
static const char conf_file_dirs[] = CONF_DIRS_NULSTR("sysctl");
static const char conf_file_dirs[] = CONF_PATHS_NULSTR("sysctl.d");
static int apply_all(Hashmap *sysctl_options) {
char *property, *value;

View file

@ -72,7 +72,7 @@ typedef struct Item {
static char *arg_root = NULL;
static const char conf_file_dirs[] = CONF_DIRS_NULSTR("sysusers");
static const char conf_file_dirs[] = CONF_PATHS_NULSTR("sysusers.d");
static Hashmap *users = NULL, *groups = NULL;
static Hashmap *todo_uids = NULL, *todo_gids = NULL;

View file

@ -100,8 +100,8 @@ int config_parse_servers(
int manager_parse_config_file(Manager *m) {
assert(m);
return config_parse_many("/etc/systemd/timesyncd.conf",
CONF_DIRS_NULSTR("systemd/timesyncd.conf"),
return config_parse_many(PKGSYSCONFDIR "/timesyncd.conf",
CONF_PATHS_NULSTR("systemd/timesyncd.conf.d"),
"Time\0",
config_item_perf_lookup, timesyncd_gperf_lookup,
false, m);

View file

@ -159,7 +159,7 @@ static char **arg_include_prefixes = NULL;
static char **arg_exclude_prefixes = NULL;
static char *arg_root = NULL;
static const char conf_file_dirs[] = CONF_DIRS_NULSTR("tmpfiles");
static const char conf_file_dirs[] = CONF_PATHS_NULSTR("tmpfiles.d");
#define MAX_DEPTH 256