zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Johan Grande <nahoj@crans.org>, zsh-workers@zsh.org
Subject: Re: Failed pipeline doesn't err_exit/return if complex command last
Date: Tue, 18 Jul 2023 14:57:20 +0100 (BST)	[thread overview]
Message-ID: <1570386064.868183.1689688640076@mail.virginmedia.com> (raw)
In-Reply-To: <CAH+w=7bFd6Bnd4X+giWymmtrmCXCHkrBGUmDj3dYmgApJqYniw@mail.gmail.com>

> fn () {
>   emulate -L zsh
>   setopt errreturn pipefail
>   false | {
>     true
>   }
>   print "Shouldn't get here, status $?"
> }

A bit more prodding reveals it's not actually timing that
has this effect --- the problem is this_noerrexit being
set to indicate something like "we're doing that complicated
internal shell stuff and we've discovered the status is OK".
This time it isn['t.

Not sure if I need the second case or not, certainly
the first case is the one we're hitting here (the
STAT_CURSH is the giveaway).  My guess is that it's
simply irrelevant because if there's no STAT_CURSH
we aren't going to hit those cases where this_noerrexit
becomes non-zero.

Obviously, there could be even more complicated cases that
still cause problems, but I think we'll just have to discover
those.  I'll write some tests that might help.

Note I fixed some indentation.

pws

diff --git a/Src/jobs.c b/Src/jobs.c
index dd7bba405..a3b9f667a 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -427,11 +427,17 @@ storepipestats(Job jn, int inforeground, int fixlastval)
     }
 
     if (fixlastval) {
-      if (jn->stat & STAT_CURSH) {
-	if (!lastval && isset(PIPEFAIL))
-	  lastval = pipefail;
-      } else if (isset(PIPEFAIL))
-	lastval = pipefail;
+	if (jn->stat & STAT_CURSH) {
+	    if (!lastval && isset(PIPEFAIL)) {
+		if (inforeground)
+		    this_noerrexit = 0;
+		lastval = pipefail;
+	    }
+	} else if (isset(PIPEFAIL)) {
+	    if (inforeground)
+		this_noerrexit = 0;
+	    lastval = pipefail;
+	}
     }
 }


  reply	other threads:[~2023-07-18 13:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-05 23:18 Johan Grande
2023-07-05 23:45 ` Johan Grande
2023-07-06  9:44 ` Peter Stephenson
2023-07-08  4:31   ` Bart Schaefer
     [not found]   ` <cf275400-d63a-d991-3aa5-1543d20a2f42@crans.org>
2023-07-16 14:36     ` Peter Stephenson
2023-07-17 19:25       ` Johan Grande
2023-07-17 23:34   ` Bart Schaefer
2023-07-18  1:51     ` Bart Schaefer
2023-07-18 13:57       ` Peter Stephenson [this message]
2023-07-20  8:47         ` Peter Stephenson

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=1570386064.868183.1689688640076@mail.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=nahoj@crans.org \
    --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).