aboutgitcodebugslistschat
path: root/pasta.c
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2023-02-09 15:59:49 +0100
committerStefano Brivio <sbrivio@redhat.com>2023-02-12 23:42:50 +0100
commita234407f5c561b729d7d77f4f9ab82df3ce6a6c7 (patch)
tree0b658224e631d895e8b9e78534361e844658fed9 /pasta.c
parent04dfc5b81fd8d59a8ac6d27f23a7fb530a1eb515 (diff)
downloadpasst-a234407f5c561b729d7d77f4f9ab82df3ce6a6c7.tar
passt-a234407f5c561b729d7d77f4f9ab82df3ce6a6c7.tar.gz
passt-a234407f5c561b729d7d77f4f9ab82df3ce6a6c7.tar.bz2
passt-a234407f5c561b729d7d77f4f9ab82df3ce6a6c7.tar.lz
passt-a234407f5c561b729d7d77f4f9ab82df3ce6a6c7.tar.xz
passt-a234407f5c561b729d7d77f4f9ab82df3ce6a6c7.tar.zst
passt-a234407f5c561b729d7d77f4f9ab82df3ce6a6c7.zip
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>
Diffstat (limited to 'pasta.c')
-rw-r--r--pasta.c12
1 files 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);