From: Paul Holzinger <pholzing@redhat.com>
To: passt-dev@passt.top
Cc: Paul Holzinger <pholzing@redhat.com>
Subject: [PATCH v2] pasta: propagate exit code from child command
Date: Thu, 9 Feb 2023 15:59:49 +0100 [thread overview]
Message-ID: <20230209145948.20773-1-pholzing@redhat.com> (raw)
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>
---
Changes from v1:
- Fixed comments from Stefano.
pasta.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/pasta.c b/pasta.c
index 3f6477c..fe21c5b 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);
--
@@ -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);
--
2.39.1
next reply other threads:[~2023-02-09 15:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 14:59 Paul Holzinger [this message]
2023-02-13 1:16 ` [PATCH v2] pasta: propagate exit code from child command Stefano Brivio
2023-02-13 2:37 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230209145948.20773-1-pholzing@redhat.com \
--to=pholzing@redhat.com \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).