Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Exit code 130 kills pipeline
- X-seq: zsh-workers 46060
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Exit code 130 kills pipeline
- Date: Wed, 17 Jun 2020 17:58:29 +0100 (BST)
- Importance: Medium
- In-reply-to: <CAN=4vMqH7hQ6p=x+WHcWe3Xr2wD26W1kv65dUj4M5SmgsGo7Qw@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAN=4vMqH7hQ6p=x+WHcWe3Xr2wD26W1kv65dUj4M5SmgsGo7Qw@mail.gmail.com>
> On 17 June 2020 at 16:45 Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
> Is it expected that the following command produces no output?
>
> ( exit 130 ) | { sleep 1; echo hello }
There's some slightly dodgy use of flags when testing for signals.
I'm not sure "or"ing in the 128 is really needed at all but to, keep
this minimal, all we need to do is test separately whether the process
actually got a signal. If it didn't we've no business looking for
SIGINT or SIGQUIT.
pws
diff --git a/Src/jobs.c b/Src/jobs.c
index 8353f1152..0d4993554 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -442,7 +442,7 @@ update_job(Job jn)
Process pn;
int job;
int val = 0, status = 0;
- int somestopped = 0, inforeground = 0;
+ int somestopped = 0, inforeground = 0, signalled = 0;
for (pn = jn->auxprocs; pn; pn = pn->next) {
#ifdef WIFCONTINUED
@@ -464,12 +464,15 @@ update_job(Job jn)
return; /* so no need to update job table entry */
if (WIFSTOPPED(pn->status)) /* some processes are stopped */
somestopped = 1; /* so job is not done, but entry needs updating */
- if (!pn->next) /* last job in pipeline determines exit status */
+ if (!pn->next) {
+ /* last job in pipeline determines exit status */
val = (WIFSIGNALED(pn->status) ?
0200 | WTERMSIG(pn->status) :
(WIFSTOPPED(pn->status) ?
0200 | WEXITSTATUS(pn->status) :
WEXITSTATUS(pn->status)));
+ signalled = WIFSIGNALED(pn->status);
+ }
if (pn->pid == jn->gleader) /* if this process is process group leader */
status = pn->status;
}
@@ -564,7 +567,7 @@ update_job(Job jn)
}
/* If we have `foo|while true; (( x++ )); done', and hit
* ^C, we have to stop the loop, too. */
- if ((val & 0200) && inforeground == 1 &&
+ if (signalled && inforeground == 1 &&
((val & ~0200) == SIGINT || (val & ~0200) == SIGQUIT)) {
if (!errbrk_saved) {
errbrk_saved = 1;
@@ -581,7 +584,7 @@ update_job(Job jn)
adjustwinsize(0);
}
}
- } else if (list_pipe && (val & 0200) && inforeground == 1 &&
+ } else if (list_pipe && signalled && inforeground == 1 &&
((val & ~0200) == SIGINT || (val & ~0200) == SIGQUIT)) {
if (!errbrk_saved) {
errbrk_saved = 1;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author