about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2019-04-10 18:13:39 +0200
committerProfpatsch <mail@profpatsch.de>2019-04-18 15:24:30 +0200
commit2cd8e92813dfda7684d94cf3bf322d4bae7fdfc2 (patch)
tree2696eafb1fc645bab102b2414a63d39ca7c4a454 /pkgs/build-support
parentab86438cc60dcaf7b0191009e20a3cb61d401421 (diff)
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.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/build-sandbox/src/setup.c20
1 files changed, 18 insertions, 2 deletions
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();