Skip to content

Commit 48817ef

Browse files
committed
Pass along the child exit status
For some strange reason we cannot use WNOHANG in the options for waitpid, otherwise it will always return 0. This might be another kernel bug with seccomp we would have to investigate, as this does not make any sense since the child has obviously exited. However, with this we finally imitate the exit code of the supervised process.
1 parent 019c0dc commit 48817ef

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/bin/seccomp/seccomp_exec.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,17 @@ int seccomp_parent(struct seccomp_state *state) {
9999
memset(req, 0, sizes.seccomp_notif);
100100
if (ioctl(state->listener, SECCOMP_IOCTL_NOTIF_RECV, req)) {
101101
if (errno == ENOENT) {
102-
// when the child exits, SECCOMP_IOCTL_NOTIF_RECV will return with ENOENT,
103-
// in which case we can also just quit the supervisor
104-
exit_code = EXIT_SUCCESS;
102+
// When the child exits, SECCOMP_IOCTL_NOTIF_RECV will return with ENOENT,
103+
// in which case we can also just quit the supervisor.
104+
// But first we have to retrieve the child's exit code
105+
int wstatus;
106+
pid_t wait = waitpid(state->task_pid, &wstatus, WUNTRACED | WCONTINUED);
107+
if (wait != state->task_pid || !WIFEXITED(wstatus)) {
108+
exit_code = EXIT_FAILURE;
109+
} else {
110+
// Pass over the same exit code
111+
exit_code = WEXITSTATUS(wstatus);
112+
}
105113
} else {
106114
perror("ioctl recv");
107115
}

0 commit comments

Comments
 (0)