zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Exit code 130 kills pipeline
Date: Wed, 17 Jun 2020 17:58:29 +0100 (BST)	[thread overview]
Message-ID: <1742415134.186024.1592413109794@mail2.virginmedia.com> (raw)
In-Reply-To: <CAN=4vMqH7hQ6p=x+WHcWe3Xr2wD26W1kv65dUj4M5SmgsGo7Qw@mail.gmail.com>

> On 17 June 2020 at 16:45 Roman Perepelitsa <roman.perepelitsa@gmail.com> 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;

  reply	other threads:[~2020-06-17 16:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17 15:45 Roman Perepelitsa
2020-06-17 16:58 ` Peter Stephenson [this message]
2020-06-18  5:49   ` Roman Perepelitsa
2020-06-18 10:49     ` Peter Stephenson
2020-06-17 17:42 ` Mikael Magnusson
2020-06-17 17:46   ` Roman Perepelitsa
2020-06-17 20:34     ` Mikael Magnusson

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=1742415134.186024.1592413109794@mail2.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /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://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).