constants: drop duplicated CONF_PATHS defines

Follow-up for b0d3095fd6.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-12-14 10:52:34 +01:00
parent 8f43182847
commit 76d75d8b7b
5 changed files with 9 additions and 26 deletions

View file

@ -67,18 +67,12 @@
"/usr/local/lib/" n "\0" \
"/usr/lib/" n "\0"
#define CONF_PATHS_USR(n) \
#define CONF_PATHS(n) \
"/etc/" n, \
"/run/" n, \
"/usr/local/lib/" n, \
"/usr/lib/" n
#define CONF_PATHS(n) \
CONF_PATHS_USR(n)
#define CONF_PATHS_USR_STRV(n) \
STRV_MAKE(CONF_PATHS_USR(n))
#define CONF_PATHS_STRV(n) \
STRV_MAKE(CONF_PATHS(n))

View file

@ -17,7 +17,7 @@ static int environment_dirs(char ***ret) {
_cleanup_free_ char *c = NULL;
int r;
dirs = strv_new(CONF_PATHS_USR("environment.d"));
dirs = strv_new(CONF_PATHS("environment.d"));
if (!dirs)
return -ENOMEM;

View file

@ -7997,7 +7997,7 @@ static int run(int argc, char *argv[]) {
if (!d)
return log_oom();
r = search_and_access(d, F_OK, NULL, CONF_PATHS_USR_STRV("systemd/repart/definitions"), &dp);
r = search_and_access(d, F_OK, NULL, CONF_PATHS_STRV("systemd/repart/definitions"), &dp);
if (r < 0)
return log_error_errno(r, "DDI type '%s' is not defined: %m", arg_make_ddi);

View file

@ -3218,8 +3218,8 @@ static int split_pattern_into_name_and_instances(const char *pattern, char **out
}
static int presets_find_config(RuntimeScope scope, const char *root_dir, char ***files) {
static const char* const system_dirs[] = {CONF_PATHS("systemd/system-preset"), NULL};
static const char* const user_dirs[] = {CONF_PATHS_USR("systemd/user-preset"), NULL};
static const char* const system_dirs[] = { CONF_PATHS("systemd/system-preset"), NULL };
static const char* const user_dirs[] = { CONF_PATHS("systemd/user-preset"), NULL };
const char* const* dirs;
assert(scope >= 0);

View file

@ -316,11 +316,10 @@ static int guess_type(const char **name, char ***prefixes, bool *is_collection,
*/
_cleanup_free_ char *n = NULL;
bool usr = false, run = false, coll = false;
bool run = false, coll = false;
const char *ext = ".conf";
/* This is static so that the array doesn't get deallocated when we exit the function */
static const char* const std_prefixes[] = { CONF_PATHS(""), NULL };
static const char* const usr_prefixes[] = { CONF_PATHS_USR(""), NULL };
static const char* const run_prefixes[] = { "/run/", NULL };
if (path_equal(*name, "environment.d"))
@ -332,20 +331,13 @@ static int guess_type(const char **name, char ***prefixes, bool *is_collection,
if (!n)
return log_oom();
/* All systemd-style config files should support the /usr-/etc-/run split and
* dropins. Let's add a blanket rule that allows us to support them without keeping
* an explicit list. */
if (path_startswith(n, "systemd") && endswith(n, ".conf"))
usr = true;
delete_trailing_chars(n, "/");
/* We assume systemd-style config files support the /usr-/run-/etc split and dropins. */
if (endswith(n, ".d"))
coll = true;
if (path_equal(n, "environment"))
usr = true;
if (path_equal(n, "udev/hwdb.d"))
ext = ".hwdb";
else if (path_equal(n, "udev/rules.d"))
@ -363,10 +355,7 @@ static int guess_type(const char **name, char ***prefixes, bool *is_collection,
ext = ".preset";
}
if (path_equal(n, "systemd/user-preset"))
usr = true;
*prefixes = (char**) (usr ? usr_prefixes : run ? run_prefixes : std_prefixes);
*prefixes = (char**) (run ? run_prefixes : std_prefixes);
*is_collection = coll;
*extension = ext;
return 0;