1
0
mirror of https://passt.top/passt synced 2024-06-23 11:37:04 +00:00

pasta: propagate exit code from child command

Exits codes are very useful for scripts, when the pasta child execvp()
call fails with ENOENT that parent should also exit with > 0. In short
the parent should always exit with the code from the child to make it
useful in scripts.

It is easy to test with: `pasta -- bash -c "exit 3"; echo $?`

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Paul Holzinger 2023-02-09 15:59:49 +01:00 committed by Stefano Brivio
parent 04dfc5b81f
commit a234407f5c

12
pasta.c
View File

@ -64,9 +64,17 @@ void pasta_child_handler(int signal)
if (pasta_child_pid &&
!waitid(P_PID, pasta_child_pid, &infop, WEXITED | WNOHANG)) {
if (infop.si_pid == pasta_child_pid)
exit(EXIT_SUCCESS);
if (infop.si_pid == pasta_child_pid) {
if (infop.si_code == CLD_EXITED)
exit(infop.si_status);
/* If killed by a signal, si_status is the number.
* Follow common shell convention of returning it + 128.
*/
exit(infop.si_status + 128);
/* Nothing to do, detached PID namespace going away */
}
}
waitid(P_ALL, 0, NULL, WEXITED | WNOHANG);