From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24074 invoked from network); 17 Jun 2020 16:59:18 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 17 Jun 2020 16:59:18 -0000 Received: (qmail 20534 invoked by alias); 17 Jun 2020 16:59:09 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 46060 Received: (qmail 17876 invoked by uid 1010); 17 Jun 2020 16:59:09 -0000 X-Qmail-Scanner-Diagnostics: from smtpq2.tb.ukmail.iss.as9143.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25842. spamassassin: 3.4.4. Clear:RC:0(212.54.57.97):SA:0(-2.7/5.0):. Processed in 2.988949 secs); 17 Jun 2020 16:59:09 -0000 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _mailcloud.virginmedia.com designates 212.54.57.97 as permitted sender) X-Env-Mailfrom: p.w.stephenson@ntlworld.com X-Env-Rcptto: zsh-workers@zsh.org X-SourceIP: 172.25.160.136 X-CNFS-Analysis: v=2.3 cv=T8IXs8CQ c=1 sm=1 tr=0 a=4AIt8OzuWET5BS7mAkvERw==:117 a=KEnZaF_ea6UA:10 a=IkcTkHD0fZMA:10 a=DoY9bV0jb9AA:10 a=pGLkceISAAAA:8 a=XN8cTWXHJZoGM73JnZgA:9 a=QEXdDO2ut3YA:10 X-Authenticated-Sender: p.w.stephenson@ntlworld.com Date: Wed, 17 Jun 2020 17:58:29 +0100 (BST) From: Peter Stephenson To: Zsh hackers list Message-ID: <1742415134.186024.1592413109794@mail2.virginmedia.com> In-Reply-To: References: Subject: Re: Exit code 130 kills pipeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.8.4-Rev70 X-Originating-IP: 165.225.81.56 X-Originating-Client: open-xchange-appsuite X-CMAE-Envelope: MS4wfBJgRTPbSSi7nUKZtuAlcK9RE5BPB/xma3IG9pulL8DShJt+Z3kbefe3izKpKP6Jej5vbpUmweUN0wKbig0fT+WYwoB1ie0NnjiuXICh3pzRUWji6n8V eL14iNKam3LDo8RYSOpmHf7VQaxGr5qPu1+T3Tkeg3xkBjLa6kpL7jlj3hLEWDR1lBo49CmxgV2nZOujV0i1/Cv5ZRXQpvnyFeo= > On 17 June 2020 at 16:45 Roman Perepelitsa 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;