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
This commit is contained in:
alexlzhu
2021-09-28 14:52:27 +01:00
committed by Chris Down
parent 5b32e48f6e
commit 8c35c10d20
27 changed files with 360 additions and 13 deletions
+23 -3
View File
@@ -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 (;;) {
+2 -2
View File
@@ -99,9 +99,9 @@ int path_strv_make_absolute_cwd(char **l);
char** path_strv_resolve(char **l, const char *root);
char** path_strv_resolve_uniq(char **l, const char *root);
int find_executable_full(const char *name, const char *root, bool use_path_envvar, char **ret_filename, int *ret_fd);
int find_executable_full(const char *name, const char *root, char **exec_search_path, bool use_path_envvar, char **ret_filename, int *ret_fd);
static inline int find_executable(const char *name, char **ret_filename) {
return find_executable_full(name, /* root= */ NULL, true, ret_filename, NULL);
return find_executable_full(name, /* root= */ NULL, NULL, true, ret_filename, NULL);
}
bool paths_check_timestamp(const char* const* paths, usec_t *paths_ts_usec, bool update);