From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@math.gatech.edu
Subject: Re: Insidious exit status bugs
Date: Fri, 25 Sep 1998 12:09:50 +0200 [thread overview]
Message-ID: <9809251009.AA12696@ibmth.df.unipi.it> (raw)
In-Reply-To: ""Bart Schaefer""'s message of "Thu, 24 Sep 1998 23:41:27 DFT." <980924234127.ZM15042@candle.brasslantern.com>
"Bart Schaefer" wrote:
> The following really messed me up, trying to write a script that will work
> whether sh is bash or zsh. Here's zsh 3.0.5 (3.1.4 is the same):
>
> zagzig% echo yyy | fgrep -q xxx && echo ok
> zagzig% echo yyy | fgrep -q `echo xxx` && echo ok
> ok
>
> It appears that the exit status of `echo xxx` is masking the exit status of
> `fgrep -q`, but I'm not certain.
Insidious is definitely right. This is serious harrow-up-thy-soul
territory. There appear to be two things happening. The first I
think I understand, though not why it's there. The second currently
has me stumped.
First: the exit status from the `...` or $(...) is being explicitly
passed back as lastval, i.e. $?. Why??? There's a variable cmdoutval
whose only function in life is to remember that status to be assigned
to lastval, so someone thought it was a good idea. Here's the
offending chunk from getoutput() in exec.c which is for the parent
side of the forked $(...).
} else if (pid) {
LinkList retval;
zclose(pipes[1]);
retval = readoutput(pipes[0], qt);
fdtable[pipes[0]] = 0;
child_suspend(0); /* unblocks */
lastval = cmdoutval;
return retval;
}
`lastval = cmdoutval' is deliberately messing up the return status for
reasons I can't even guess at. Perhaps if the second bug wasn't
there, this wouldn't be seen, but it had me confused anyway.
Second: I commented the cmdoutval stuff out, and now things start to
go really haywire. It looks like you have to have a builtin in the
first part of the pipe, and an external command in the second part to
see this. Bearing this in mind, I commented out the chunk in
execpline2() where `builtin as first command in pipe' is specially
handled, so as to simplify things, and added some messages; it still
goes wrong:
+11:58% echo yyy | fgrep -q $(echo xxx)
Got status 0 from process 36923 OK, that's the $(echo xxx)
...was procsub process.
Got status 0 from process 36410 This must be the echo yyy...
Setting status of 36410 to 0 (1)
Exit status 0 from 36410 ...and this means that
it's being handled
as if it were last in
the pipeline.
setting lastval to 0 (1)
Got status 0 from process -1
...error: No child processes self explanatory, but...
+11:58% Got status 256 from process 36412 now we're back to the
prompt, and 36412 (fgrep)
has only just been handled.
Got status 256 from process -1
...error: No child processes
So it looks like the fgrep is being run, or at least waited for,
asynchronously instead of synchronously, and all because of the $(echo
xxx). I've wasted too much time on this already, so that's it for
now.
--
Peter Stephenson <pws@ibmth.df.unipi.it> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy
next prev parent reply other threads:[~1998-09-25 10:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-09-25 6:41 Bart Schaefer
1998-09-25 10:09 ` Peter Stephenson [this message]
1998-09-25 10:50 ` Zefram
1998-09-25 15:01 ` PATCH: 3.1.4: Insidious exit status bug Peter Stephenson
1998-09-25 16:43 ` 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=9809251009.AA12696@ibmth.df.unipi.it \
--to=pws@ibmth.df.unipi.it \
--cc=zsh-workers@math.gatech.edu \
/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).