From cccf570355c9ffcf34cea5f70e5714765ab002fe Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Fri, 14 Feb 2020 22:43:38 +0100 Subject: core: Move environment generator path lookup into path-lookup.c --- src/core/manager.c | 26 ++++++-------------------- src/shared/path-lookup.c | 14 ++++++++++++++ src/shared/path-lookup.h | 1 + 3 files changed, 21 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/core/manager.c b/src/core/manager.c index 25afdbea04..38f7ba1eb8 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -3826,25 +3826,9 @@ static bool generator_path_any(const char* const* paths) { return found; } -static const char *const system_env_generator_binary_paths[] = { - "/run/systemd/system-environment-generators", - "/etc/systemd/system-environment-generators", - "/usr/local/lib/systemd/system-environment-generators", - SYSTEM_ENV_GENERATOR_PATH, - NULL -}; - -static const char *const user_env_generator_binary_paths[] = { - "/run/systemd/user-environment-generators", - "/etc/systemd/user-environment-generators", - "/usr/local/lib/systemd/user-environment-generators", - USER_ENV_GENERATOR_PATH, - NULL -}; - static int manager_run_environment_generators(Manager *m) { char **tmp = NULL; /* this is only used in the forked process, no cleanup here */ - const char *const *paths; + _cleanup_strv_free_ char **paths = NULL; void* args[] = { [STDOUT_GENERATE] = &tmp, [STDOUT_COLLECT] = &tmp, @@ -3855,13 +3839,15 @@ static int manager_run_environment_generators(Manager *m) { if (MANAGER_IS_TEST_RUN(m) && !(m->test_run_flags & MANAGER_TEST_RUN_ENV_GENERATORS)) return 0; - paths = MANAGER_IS_SYSTEM(m) ? system_env_generator_binary_paths : user_env_generator_binary_paths; + paths = env_generator_binary_paths(MANAGER_IS_SYSTEM(m)); + if (!paths) + return log_oom(); - if (!generator_path_any(paths)) + if (!generator_path_any((const char* const*) paths)) return 0; RUN_WITH_UMASK(0022) - r = execute_directories(paths, DEFAULT_TIMEOUT_USEC, gather_environment, + r = execute_directories((const char* const*) paths, DEFAULT_TIMEOUT_USEC, gather_environment, args, NULL, m->transient_environment, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS); return r; } diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index 5b16209745..c98d699424 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -837,3 +837,17 @@ char **generator_binary_paths(UnitFileScope scope) { assert_not_reached("Hmm, unexpected scope."); } } + +char **env_generator_binary_paths(bool is_system) { + + if (is_system) + return strv_new("/run/systemd/system-environment-generators", + "/etc/systemd/system-environment-generators", + "/usr/local/lib/systemd/system-environment-generators", + SYSTEM_ENV_GENERATOR_PATH); + else + return strv_new("/run/systemd/user-environment-generators", + "/etc/systemd/user-environment-generators", + "/usr/local/lib/systemd/user-environment-generators", + USER_ENV_GENERATOR_PATH); +} diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h index f0762d248a..b99e918144 100644 --- a/src/shared/path-lookup.h +++ b/src/shared/path-lookup.h @@ -72,3 +72,4 @@ void lookup_paths_flush_generator(LookupPaths *p); void lookup_paths_free(LookupPaths *p); char **generator_binary_paths(UnitFileScope scope); +char **env_generator_binary_paths(bool is_system); -- cgit v1.2.3