summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-10-11 17:57:06 +0200
committerMike Yuan <me@yhndnzj.com>2024-10-15 01:18:26 +0200
commitde41622bf39cfa01c8d79e2898b15e8a9bbc89ab (patch)
tree0cc2ac01c6a6bc0a9350466c5de57d8c3c6fe210 /src/core
parentshared/exec-util: modernize execute_strv() and friends a bit (diff)
downloadsystemd-de41622bf39cfa01c8d79e2898b15e8a9bbc89ab.tar.xz
systemd-de41622bf39cfa01c8d79e2898b15e8a9bbc89ab.zip
core/manager: minor cleanup for generator_path_any() and friends
Diffstat (limited to 'src/core')
-rw-r--r--src/core/manager.c58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/core/manager.c b/src/core/manager.c
index 456ad46135..373f4d66e7 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -4007,30 +4007,26 @@ void manager_send_reloading(Manager *m) {
m->ready_sent = false;
}
-static bool generator_path_any(const char* const* paths) {
- bool found = false;
+static bool generator_path_any(char * const *paths) {
- /* Optimize by skipping the whole process by not creating output directories
- * if no generators are found. */
- STRV_FOREACH(path, paths)
- if (access(*path, F_OK) == 0)
- found = true;
- else if (errno != ENOENT)
- log_warning_errno(errno, "Failed to open generator directory %s: %m", *path);
+ /* Optimize by skipping the whole process by not creating output directories if no generators are found. */
- return found;
+ STRV_FOREACH(i, paths) {
+ if (access(*i, F_OK) >= 0)
+ return true;
+ if (errno != ENOENT)
+ log_warning_errno(errno, "Failed to check if generator dir '%s' exists, assuming not: %m", *i);
+ }
+
+ return false;
}
static int manager_run_environment_generators(Manager *m) {
- char **tmp = NULL; /* this is only used in the forked process, no cleanup here */
_cleanup_strv_free_ char **paths = NULL;
- void* args[] = {
- [STDOUT_GENERATE] = &tmp,
- [STDOUT_COLLECT] = &tmp,
- [STDOUT_CONSUME] = &m->transient_environment,
- };
int r;
+ assert(m);
+
if (MANAGER_IS_TEST_RUN(m) && !(m->test_run_flags & MANAGER_TEST_RUN_ENV_GENERATORS))
return 0;
@@ -4038,9 +4034,16 @@ static int manager_run_environment_generators(Manager *m) {
if (!paths)
return log_oom();
- if (!generator_path_any((const char* const*) paths))
+ if (!generator_path_any(paths))
return 0;
+ char **tmp = NULL; /* this is only used in the forked process, no cleanup here */
+ void *args[_STDOUT_CONSUME_MAX] = {
+ [STDOUT_GENERATE] = &tmp,
+ [STDOUT_COLLECT] = &tmp,
+ [STDOUT_CONSUME] = &m->transient_environment,
+ };
+
WITH_UMASK(0022)
r = execute_directories((const char* const*) paths, DEFAULT_TIMEOUT_USEC, gather_environment,
args, NULL, m->transient_environment,
@@ -4117,17 +4120,12 @@ static int build_generator_environment(Manager *m, char ***ret) {
return 0;
}
-static int manager_execute_generators(Manager *m, char **paths, bool remount_ro) {
+static int manager_execute_generators(Manager *m, char * const *paths, bool remount_ro) {
_cleanup_strv_free_ char **ge = NULL;
- const char *argv[] = {
- NULL, /* Leave this empty, execute_directory() will fill something in */
- m->lookup_paths.generator,
- m->lookup_paths.generator_early,
- m->lookup_paths.generator_late,
- NULL,
- };
int r;
+ assert(m);
+
r = build_generator_environment(m, &ge);
if (r < 0)
return log_error_errno(r, "Failed to build generator environment: %m");
@@ -4144,6 +4142,14 @@ static int manager_execute_generators(Manager *m, char **paths, bool remount_ro)
log_warning_errno(r, "Read-only bind remount failed, ignoring: %m");
}
+ const char *argv[] = {
+ NULL, /* Leave this empty, execute_directory() will fill something in */
+ m->lookup_paths.generator,
+ m->lookup_paths.generator_early,
+ m->lookup_paths.generator_late,
+ NULL,
+ };
+
BLOCK_WITH_UMASK(0022);
return execute_directories(
(const char* const*) paths,
@@ -4168,7 +4174,7 @@ static int manager_run_generators(Manager *m) {
if (!paths)
return log_oom();
- if (!generator_path_any((const char* const*) paths))
+ if (!generator_path_any(paths))
return 0;
r = lookup_paths_mkdir_generator(&m->lookup_paths);