From a234407f5c561b729d7d77f4f9ab82df3ce6a6c7 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 9 Feb 2023 15:59:49 +0100 Subject: 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 Signed-off-by: Stefano Brivio --- pasta.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pasta.c b/pasta.c index d5f90e8..d4d3dc8 100644 --- a/pasta.c +++ b/pasta.c @@ -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); -- cgit v1.2.3