zsh-workers
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: [PATCH v2] exec: run final pipeline command in a subshell in sh mode
Date: Thu, 11 Jun 2020 00:24:03 +0000	[thread overview]
Message-ID: <20200611002403.GY6569@camp.crustytoothpaste.net> (raw)
In-Reply-To: <CAH+w=7aq+U5Ap-aqcDXuLtctT3Pu3WFLzOQA6u7xmn7xyUU5Og@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1929 bytes --]

On 2020-06-07 at 16:55:54, Bart Schaefer wrote:
> On Fri, Jun 5, 2020 at 1:42 PM brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
> >
> > I will tell you that as a practical matter, nobody writing code for sh
> > expects the last command not to be run in a subshell and consequently
> > lots of code is practically broken in this case with zsh as /bin/sh.
> 
> I believe you, but would be curious to see an example.

I'll demonstrate an example from the Git testsuite (t1300), which is
necessarily incomplete, and whose behavior baffles me a bit.

	echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
	test_i18ngrep "bad config line 1 in standard input" output

test_must_fail checks for a nonzero, non-SIGSEGV exit code, and
test_i18ngrep is a glorified grep operation which always succeeds when
LC_ALL=C doesn't work.  There is also a lot of FD redirection going on
under the hood.

This operation fails, interestingly enough, because grep complains that
the output is also the input; that is, the redirection of stdout on the
previous line applies to the grep as well.  I'm unable to reproduce this
with a simpler example, but putting it in a subshell does work.  AT&T
ksh does not have this behavior, and so this may be a legitimate bug in
zsh which my patch happens to fix.

The other case (t0410) in the Git testsuite is more straightforward; we
have this function:

pack_as_from_promisor () {
	HASH=$(git -C repo pack-objects .git/objects/pack/pack) &&
	>repo/.git/objects/pack/pack-$HASH.promisor &&
	echo $HASH
}

and that function is then called on the right end of a pipe.  The caller
was not expecting that HASH would be overwritten, and since until
recently the Git testsuite did not allow "local" and this test has not
been updated, the test gets the wrong value.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

      parent reply	other threads:[~2020-06-11  0:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-05  1:53 [PATCH v2 0/1] Run pipeline command in " brian m. carlson
2020-06-05  1:53 ` [PATCH v2] exec: run final pipeline command in a " brian m. carlson
2020-06-05 10:21   ` Mikael Magnusson
2020-06-05 20:41     ` brian m. carlson
2020-06-06  4:33       ` [PATCH v2] exec: run final pipeline command in a subshell in sh modeZZ Daniel Shahaf
2020-06-06 16:28         ` brian m. carlson
2020-06-07 11:29           ` Daniel Shahaf
2020-06-07 16:55       ` [PATCH v2] exec: run final pipeline command in a subshell in sh mode Bart Schaefer
2020-06-07 17:24         ` Peter Stephenson
2020-06-09  7:57           ` Daniel Shahaf
2020-06-09 10:54             ` Mikael Magnusson
2020-06-17 18:26               ` Daniel Shahaf
2020-07-03 20:16                 ` brian m. carlson
2020-06-11  0:24         ` brian m. carlson [this message]

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=20200611002403.GY6569@camp.crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=schaefer@brasslantern.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).