diff options
author | alexlzhu <alexlzhu@devvm2387.atn0.facebook.com> | 2021-07-08 17:10:47 -0700 |
---|---|---|
committer | Chris Down <chris@chrisdown.name> | 2021-09-28 14:52:27 +0100 |
commit | 8c35c10d20ff7b369bfff3fbbb92a43ca2fd5938 (patch) | |
tree | be87626fe62937be49a7b3388d75d44623ed2c5d /src/basic/path-util.c | |
parent | 5b32e48f6e3753600b9f6c44446b313294270f48 (diff) | |
download | systemd-8c35c10d20ff7b369bfff3fbbb92a43ca2fd5938.tar.gz |
core: Add ExecSearchPath parameter to specify the directory relative to which binaries executed by Exec*= should be found
Currently there does not exist a way to specify a path relative to which
all binaries executed by Exec should be found. The only way is to
specify the absolute path.
This change implements the functionality to specify a path relative to which
binaries executed by Exec*= can be found.
Closes #6308
Diffstat (limited to 'src/basic/path-util.c')
-rw-r--r-- | src/basic/path-util.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/basic/path-util.c b/src/basic/path-util.c index a21981616b..eee07b6ea5 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -682,8 +682,8 @@ static int find_executable_impl(const char *name, const char *root, char **ret_f return 0; } -int find_executable_full(const char *name, const char *root, bool use_path_envvar, char **ret_filename, int *ret_fd) { - int last_error, r; +int find_executable_full(const char *name, const char *root, char **exec_search_path, bool use_path_envvar, char **ret_filename, int *ret_fd) { + int last_error = -ENOENT, r = 0; const char *p = NULL; assert(name); @@ -698,7 +698,27 @@ int find_executable_full(const char *name, const char *root, bool use_path_envva if (!p) p = DEFAULT_PATH; - last_error = -ENOENT; + if (exec_search_path) { + char **element; + + STRV_FOREACH(element, exec_search_path) { + _cleanup_free_ char *full_path = NULL; + if (!path_is_absolute(*element)) + continue; + full_path = path_join(*element, name); + if (!full_path) + return -ENOMEM; + + r = find_executable_impl(full_path, root, ret_filename, ret_fd); + if (r < 0) { + if (r != -EACCES) + last_error = r; + continue; + } + return 0; + } + return last_error; + } /* Resolve a single-component name to a full path */ for (;;) { |