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
---
pasta.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/pasta.c b/pasta.c
index 3f6477c..4b18d7e 100644
--- a/pasta.c
+++ b/pasta.c
@@ -64,9 +64,14 @@ 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);
- /* Nothing to do, detached PID namespace going away */
+ if (infop.si_pid == pasta_child_pid) {
+ if (infop.si_code == CLD_EXITED)
+ exit(infop.si_status);
+
+ /* else killed by signal, si_status == SIGNUM in this case */
+ exit(infop.si_status + 128);
+ }
+ /* Nothing to do, detached PID namespace going away */
}
waitid(P_ALL, 0, NULL, WEXITED | WNOHANG);
--
2.39.1