summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-04-16 15:31:10 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-04-16 19:40:12 +0900
commit8521338f95142203cb29c85113c13f9301fcee6a (patch)
tree220a2e423810a0f0a7fe656f8cc650b8e2181c4d
parentf384ce1187299978ae2a9c6d4f7eeff4f89dec9d (diff)
downloadsystemd-8521338f95142203cb29c85113c13f9301fcee6a.tar.gz
exec-util: make execute_strv() optionally take root directory
Preparation for rewriting kernel-install in C.
-rw-r--r--src/shared/exec-util.c8
-rw-r--r--src/shared/exec-util.h1
2 files changed, 6 insertions, 3 deletions
diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c
index 56f16188e1..735334719b 100644
--- a/src/shared/exec-util.c
+++ b/src/shared/exec-util.c
@@ -80,6 +80,7 @@ static int do_spawn(const char *path, char *argv[], int stdout_fd, pid_t *pid, b
static int do_execute(
char* const* paths,
+ const char *root,
usec_t timeout,
gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX],
void* const callback_args[_STDOUT_CONSUME_MAX],
@@ -121,7 +122,7 @@ static int do_execute(
_cleanup_close_ int fd = -EBADF;
pid_t pid;
- t = strdup(*path);
+ t = path_join(root, *path);
if (!t)
return log_oom();
@@ -207,6 +208,7 @@ static int do_execute(
int execute_strv(
const char *name,
char* const* paths,
+ const char *root,
usec_t timeout,
gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX],
void* const callback_args[_STDOUT_CONSUME_MAX],
@@ -243,7 +245,7 @@ int execute_strv(
if (r < 0)
return r;
if (r == 0) {
- r = do_execute(paths, timeout, callbacks, callback_args, fd, argv, envp, flags);
+ r = do_execute(paths, root, timeout, callbacks, callback_args, fd, argv, envp, flags);
_exit(r < 0 ? EXIT_FAILURE : r);
}
@@ -295,7 +297,7 @@ int execute_directories(
return log_error_errno(r, "Failed to extract file name from '%s': %m", directories[0]);
}
- return execute_strv(name, paths, timeout, callbacks, callback_args, argv, envp, flags);
+ return execute_strv(name, paths, NULL, timeout, callbacks, callback_args, argv, envp, flags);
}
static int gather_environment_generate(int fd, void *arg) {
diff --git a/src/shared/exec-util.h b/src/shared/exec-util.h
index 91dbe3f3b4..b99336ee3b 100644
--- a/src/shared/exec-util.h
+++ b/src/shared/exec-util.h
@@ -34,6 +34,7 @@ typedef enum ExecCommandFlags {
int execute_strv(
const char *name,
char* const* paths,
+ const char *root,
usec_t timeout,
gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX],
void* const callback_args[_STDOUT_CONSUME_MAX],