diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-09-07 13:06:32 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-09-07 13:06:32 +0200 |
commit | 8bed8a0e1dbaa5df29a386f13768c5df84c2cceb (patch) | |
tree | ac0663d41a471e7d3e325b1b4fa7eef01bcc51f7 /src | |
parent | doc: fix a typo (diff) | |
download | cimple-8bed8a0e1dbaa5df29a386f13768c5df84c2cceb.tar.gz cimple-8bed8a0e1dbaa5df29a386f13768c5df84c2cceb.zip |
ci: set some environment variables
Diffstat (limited to 'src')
-rw-r--r-- | src/ci.c | 7 | ||||
-rw-r--r-- | src/process.c | 21 | ||||
-rw-r--r-- | src/process.h | 4 |
3 files changed, 21 insertions, 11 deletions
@@ -16,12 +16,17 @@ static const char *ci_scripts[] = { "./ci", NULL, }; + +static const char *ci_env[] = { + "CI=y", + "CIMPLE=y", +}; /* clang-format on */ static int ci_run_script(const char *script, struct proc_output *result) { const char *args[] = {script, NULL}; - return proc_capture(args, result); + return proc_capture(args, ci_env, result); } int ci_run(struct proc_output *result) diff --git a/src/process.c b/src/process.c index 1a4b032..6ef9f8f 100644 --- a/src/process.c +++ b/src/process.c @@ -7,9 +7,14 @@ #include <sys/wait.h> #include <unistd.h> -static int exec_child(const char *args[]) +static int exec_child(const char *args[], const char *envp[]) { - int ret = execv(args[0], (char *const *)args); + static const char *default_envp[] = {NULL}; + + if (!envp) + envp = default_envp; + + int ret = execvpe(args[0], (char *const *)args, (char *const *)envp); if (ret < 0) { print_errno("execv"); return ret; @@ -36,7 +41,7 @@ static int wait_for_child(pid_t pid, int *ec) return 0; } -int proc_spawn(const char *args[], int *ec) +int proc_spawn(const char *args[], const char *envp[], int *ec) { pid_t child_pid = fork(); if (child_pid < 0) { @@ -45,12 +50,12 @@ int proc_spawn(const char *args[], int *ec) } if (!child_pid) - exit(exec_child(args)); + exit(exec_child(args, envp)); return wait_for_child(child_pid, ec); } -static int redirect_and_exec_child(int pipe_fds[2], const char *args[]) +static int redirect_and_exec_child(int pipe_fds[2], const char *args[], const char *envp[]) { int ret = 0; @@ -68,10 +73,10 @@ static int redirect_and_exec_child(int pipe_fds[2], const char *args[]) return ret; } - return exec_child(args); + return exec_child(args, envp); } -int proc_capture(const char *args[], struct proc_output *result) +int proc_capture(const char *args[], const char *envp[], struct proc_output *result) { int pipe_fds[2]; int ret = 0; @@ -89,7 +94,7 @@ int proc_capture(const char *args[], struct proc_output *result) } if (!child_pid) - exit(redirect_and_exec_child(pipe_fds, args)); + exit(redirect_and_exec_child(pipe_fds, args, envp)); check_errno(close(pipe_fds[1]), "close"); diff --git a/src/process.h b/src/process.h index b378ad1..bc20748 100644 --- a/src/process.h +++ b/src/process.h @@ -10,13 +10,13 @@ struct proc_output { }; /* The exit code is only valid if the functions returns a non-negative number. */ -int proc_spawn(const char *args[], int *ec); +int proc_spawn(const char *args[], const char *envp[], int *ec); /* Similarly, the contents of the proc_output structure is only valid if the function returns a * non-negative number. * * In that case, you'll need to free the output. */ -int proc_capture(const char *args[], struct proc_output *result); +int proc_capture(const char *args[], const char *envp[], struct proc_output *result); void proc_output_init(struct proc_output *); void proc_output_free(const struct proc_output *); |