zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: Re: Strange parameter visibility
Date: Fri, 30 Sep 2016 10:36:25 +0100	[thread overview]
Message-ID: <20160930103625.0f46aa9d@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20160930095032.17083e7b@pwslap01u.europe.root.pri>

On Fri, 30 Sep 2016 09:50:32 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> I wonder if that means there are cases where the change is problematic
> --- I hadn't realised this also covered assignments before running a
> command.  Given your experience elsewhere, you might find this makes
> pipestatus worse if you test it on relevant shell code, for example.

I've now realised WC_ASSIGN just applies to the invididual assignment
--- it doesn't actually mark the command line at all, there could in
principle be any sort of command after it.  So probably the change is
unsafe and needs to be backed off at least for now.

I'm not sure it's worth scanning down the code and seeing what's next in
excpline2(), though that's probably the right thing to do.

A more robust fix is a complete refactoring of execcmd(), which is far
too big anyway, with the appropriate parts being called form above,
deciding on asignments and analysing the commands early, possibly
allowing there to be a single fork in one place.  However, that's a big
job --- and without extra code to delay prefork() I still don't think
that fixes the case ": ${x:=2} | echo $x", and I suspect the case
"cmd=:; $cmd ${x:=2} | echo $x" is pretty much unfixable without
delaying the assignment from the ${x:=2} until a later part of
processing, which might have side effects.

pws

diff --git a/Src/exec.c b/Src/exec.c
index e253d7b..2714edb 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1844,7 +1844,7 @@ execpline2(Estate state, wordcode pcode,
 	/* if we are doing "foo | bar" where foo is a current *
 	 * shell command, do foo in a subshell and do the     *
 	 * rest of the pipeline in the current shell.         */
-	if ((wc_code(code) >= WC_CURSH || wc_code(code) == WC_ASSIGN)
+	if ((wc_code(code) >= WC_CURSH)
 	    && (how & Z_SYNC)) {
 	    int synch[2];
 	    struct timeval bgtime;
index 0b1085c..1ad73c5 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -757,9 +757,12 @@
 >}
 >Stuff here
 
-  x=1
-  x=2 | echo $x
-  echo $x
-0:Assignment-only current shell commands in LHS of pipelin
->1
->1
+## This problem is hard to fix without significant changes to how
+## the shell forks for a pipeline.
+#
+#   x=1
+#   x=2 | echo $x
+#   echo $x
+# 0:Assignment-only current shell commands in LHS of pipelin
+# >1
+# >1


  reply	other threads:[~2016-09-30  9:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20160917181339eucas1p24d214aa618aa96b5a8ddfbf351598da6@eucas1p2.samsung.com>
     [not found] ` <87bmzmtmzq.fsf@alfa.kjonca>
     [not found]   ` <831b307a-a00f-1df7-5136-17fcb769ccaf@gmx.com>
     [not found]     ` <CAH+w=7YtacLo6aY9gT5V27xYbh-wz0Tot1kbPxBiWN1ZXpavRA@mail.gmail.com>
2016-09-18  4:55       ` Bart Schaefer
2016-09-29 16:24   ` Peter Stephenson
2016-09-29 17:03     ` Peter Stephenson
2016-09-29 21:28       ` Bart Schaefer
2016-09-29 21:36         ` Bart Schaefer
2016-09-30  8:50         ` Peter Stephenson
2016-09-30  9:36           ` Peter Stephenson [this message]
2016-09-30 13:50             ` Peter Stephenson
2016-09-30 19:06               ` Bart Schaefer

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=20160930103625.0f46aa9d@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.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).