mirror of
https://github.com/systemd/systemd.git
synced 2026-07-14 11:30:45 +00:00
core/manager: minor cleanup for generator_path_any() and friends
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user