From ae15c5abe0bb2d8bd5fd3502721288bcb1a85d59 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 13 Jun 2021 15:52:34 -0400 Subject: spawn: Allow NULL envp for the current environment --- exec.c | 2 +- spawn.c | 5 +++++ spawn.h | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index bc01808..431fcbe 100644 --- a/exec.c +++ b/exec.c @@ -374,7 +374,7 @@ static int bfs_exec_spawn(const struct bfs_exec *execbuf) { } } - pid = bfs_spawn(execbuf->argv[0], &ctx, execbuf->argv, environ); + pid = bfs_spawn(execbuf->argv[0], &ctx, execbuf->argv, NULL); fail: error = errno; bfs_spawn_destroy(&ctx); diff --git a/spawn.c b/spawn.c index 4879e12..82beca5 100644 --- a/spawn.c +++ b/spawn.c @@ -217,6 +217,11 @@ fail: } pid_t bfs_spawn(const char *exe, const struct bfs_spawn *ctx, char **argv, char **envp) { + extern char **environ; + if (!envp) { + envp = environ; + } + // Use a pipe to report errors from the child int pipefd[2]; if (pipe_cloexec(pipefd) != 0) { diff --git a/spawn.h b/spawn.h index a2c23fd..16815bb 100644 --- a/spawn.h +++ b/spawn.h @@ -100,7 +100,8 @@ int bfs_spawn_addsetrlimit(struct bfs_spawn *ctx, int resource, const struct rli * @param argv * The arguments for the new process. * @param envp - * The environment variables for the new process. + * The environment variables for the new process (NULL for the current + * environment. * @return * The PID of the new process, or -1 on error. */ -- cgit v1.2.3