diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-17 12:59:40 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-17 20:38:15 +0900 |
commit | 753e38d9849a13ed58970161d89dc4a5834d835d (patch) | |
tree | 129915fe119a53a74545128ef9da01359ac3f2e7 /src/shared/exec-util.c | |
parent | fb0e5f12c6c4e09da8a942ca2a87e54bee4abc6f (diff) | |
download | systemd-753e38d9849a13ed58970161d89dc4a5834d835d.tar.gz |
exec-util: enumerate executables earlier
Then, return earlier if no executable found.
Diffstat (limited to 'src/shared/exec-util.c')
-rw-r--r-- | src/shared/exec-util.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index 1562911ec6..e44323e0e9 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -77,7 +77,7 @@ static int do_spawn(const char *path, char *argv[], int stdout_fd, pid_t *pid, b } static int do_execute( - const char* const* directories, + char* const* paths, usec_t timeout, gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX], void* const callback_args[_STDOUT_CONSUME_MAX], @@ -87,9 +87,8 @@ static int do_execute( ExecDirFlags flags) { _cleanup_hashmap_free_free_ Hashmap *pids = NULL; - _cleanup_strv_free_ char **paths = NULL; - int r; bool parallel_execution; + int r; /* We fork this all off from a child process so that we can somewhat cleanly make * use of SIGALRM to set a time limit. @@ -99,10 +98,6 @@ static int do_execute( */ parallel_execution = FLAGS_SET(flags, EXEC_DIR_PARALLEL) && !callbacks; - r = conf_files_list_strv(&paths, NULL, NULL, CONF_FILES_EXECUTABLE|CONF_FILES_REGULAR|CONF_FILES_FILTER_MASKED, directories); - if (r < 0) - return log_error_errno(r, "Failed to enumerate executables: %m"); - if (parallel_execution) { pids = hashmap_new(NULL); if (!pids) @@ -202,11 +197,19 @@ int execute_directories( char *envp[], ExecDirFlags flags) { + _cleanup_strv_free_ char **paths = NULL; _cleanup_close_ int fd = -EBADF; - int r; pid_t executor_pid; + int r; + + r = conf_files_list_strv(&paths, NULL, NULL, CONF_FILES_EXECUTABLE|CONF_FILES_REGULAR|CONF_FILES_FILTER_MASKED, directories); + if (r < 0) + return log_error_errno(r, "Failed to enumerate executables: %m"); - assert(!strv_isempty((char**) directories)); + if (strv_isempty(paths)) { + log_debug("No executables found."); + return 0; + } if (callbacks) { assert(callback_args); @@ -233,7 +236,7 @@ int execute_directories( if (r < 0) return r; if (r == 0) { - r = do_execute(directories, timeout, callbacks, callback_args, fd, argv, envp, flags); + r = do_execute(paths, timeout, callbacks, callback_args, fd, argv, envp, flags); _exit(r < 0 ? EXIT_FAILURE : r); } |