summaryrefslogtreecommitdiff
path: root/status.c
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2016-07-11 22:05:18 +0200
committerBert Münnich <ber.t@posteo.de>2019-03-24 15:01:23 +0100
commit592d9f333cde3f5263453c34d58c82708a91224c (patch)
treea5f15f7ea812fa370d6e3484a6ef49c88b2e49ce /status.c
parent1263ab60d5bf5612d273b80e87a430b9e0a75afd (diff)
Revise status messages for terminated children
Print a status message for a terminated child if: 1) the wait builtin is called in an interactive shell, or 2) the child terminated due to a signal and it is not sigint and not sigpipe or it caused the child to dump core. The messages are of the form: [pid:] <signal message[--core dumped] | done (status)> Before this, there were various inconsistencies, e.g. the wait builtin-- regardless if called in an interactive shell or script--would print just the pid and a colon w/o a message and w/o a newline if the child it waited for terminated due to receiving sigint.
Diffstat (limited to 'status.c')
-rw-r--r--status.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/status.c b/status.c
index 58a2411..b413c76 100644
--- a/status.c
+++ b/status.c
@@ -64,21 +64,24 @@ extern void setstatus(pid_t pid, int i) {
statprint(pid, i);
}
-/* print a message if termination was with a signal, and if the child dumped core. exit on error if -e is set */
+/*
+ Print a message if called from the wait builitin in an interactive
+ shell or termination was with a signal and it is not sigint and
+ sigpipe or the child dumped core. Exit on error if -e is set.
+*/
static void statprint(pid_t pid, int i) {
- if (WIFSIGNALED(i)) {
- int t = WTERMSIG(i);
- char *msg = ((t > 0) && (t < NUMOFSIGNALS) ? signals[WTERMSIG(i)].msg : "");
+ int t = WIFSIGNALED(i) ? WTERMSIG(i) : 0;
+ const char *core = ((t > 0) && myWIFDUMPED(i) ? "--core dumped" : "");
+ if ((interactive && pid != -1) || (t > 0 && (*core || (t != SIGINT && t != SIGPIPE)))) {
if (pid != -1)
fprint(2, "%ld: ", (long)pid);
- if (myWIFDUMPED(i)) {
- if (*msg == '\0')
- fprint(2, "core dumped\n");
- else
- fprint(2, "%s--core dumped\n", msg);
- } else if (*msg != '\0')
- fprint(2, "%s\n", msg);
+ if (t == 0)
+ fprint(2, "done (%d)\n", WEXITSTATUS(i));
+ else if ((t > 0) && (t < NUMOFSIGNALS) && *signals[t].msg != '\0')
+ fprint(2, "%s%s\n", signals[t].msg, core);
+ else
+ fprint(2, "unknown signal %d%s\n", t, core);
}
if (i != 0 && dashee && !cond)
rc_exit(getstatus());