From 2cd8e92813dfda7684d94cf3bf322d4bae7fdfc2 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Wed, 10 Apr 2019 18:13:39 +0200 Subject: buildSandbox: return the exit status of wrapped executable Since we want to create a transparent sandbox, returning the same exit code as the wrapped process is very important. --- pkgs/build-support/build-sandbox/src/setup.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'pkgs/build-support/build-sandbox/src/setup.c') diff --git a/pkgs/build-support/build-sandbox/src/setup.c b/pkgs/build-support/build-sandbox/src/setup.c index feafd6f6..8a5d29b5 100644 --- a/pkgs/build-support/build-sandbox/src/setup.c +++ b/pkgs/build-support/build-sandbox/src/setup.c @@ -864,9 +864,25 @@ bool setup_sandbox(void) /* Just wait in the parent until the child exits. We need to fork because * otherwise we can't mount /proc in the right PID namespace. */ + int wstatus; if (pid > 0) { - waitpid(pid, NULL, 0); - _exit(1); + + if (waitpid(pid, &wstatus, 0) == -1) { + fputs("sandbox: waitpid failure", stderr); + _exit(EXIT_FAILURE); + } + else if (WIFEXITED(wstatus)) { + _exit(WEXITSTATUS(wstatus)); + } + else if (WIFSIGNALED(wstatus)) { + fprintf(stderr, "sandbox: killed by signal %d\n", WTERMSIG(wstatus)); + _exit(EXIT_FAILURE); + } + else { + // WIFSTOPPED, WIFCONTINUED? + fputs("sandbox: wait failed", stderr); + _exit(EXIT_FAILURE); + } } cached_paths = new_path_cache(); -- cgit 1.4.1