From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: Strange function/pipestatus behavior, maybe a scope bug?
Date: Thu, 24 Oct 2013 16:48:29 +0100 [thread overview]
Message-ID: <20131024164829.55842279@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20131024095713.44d2982e@pwslap01u.europe.root.pri>
On Thu, 24 Oct 2013 09:57:13 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> > Oh, one other bug which I don't believe is new: the PIPEFAIL option
> > doesn't work right if the last command is a builtin. Maybe that
> > test should be moved into storepipestats() as well, in which case
> > the redundancy I mentioned above might also be eliminated.
>
> Are you saying that $pipestatus is correct but the overall status is
> wrong if you have something like "true | true | true" or "true | true |
> false"? It certainly sounds like they ought to run at the same point.
> The last command ought to be the easy one --- that's where the status
> has always come from, so if those two pipelines are giving different
> answers with and without PIPEFAIL something is definitely odd.
I can't see any problem here, which might not be too surprising if it's
a race, but I don't see how the following fix can be wrong if pipestatus
is now working: the most complicated case appears to be if it gets
called multiple times and STAT_CURSH is set, but even there it looks
like it's idempotent with respect to lastval (assuming the information
hasn't changed, of course).
I don't know if this potentially makes one of the calls removable.
There is some bad interaction with completion, at least on my setup
(happens from a vanilla setup, too):
% true | true | false
% print $pipest<TAB>
0
This doesn't seem to happen with hooks, so completion is failing to save
something it should.
diff --git a/Src/jobs.c b/Src/jobs.c
index 82ffdf2..200e38e 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -377,7 +377,7 @@ check_cursh_sig(int sig)
}
/**/
-int
+static void
storepipestats(Job jn, int inforeground)
{
int i, pipefail = 0, jpipestats[MAX_PIPESTATS];
@@ -397,7 +397,13 @@ storepipestats(Job jn, int inforeground)
numpipestats = i;
}
- return pipefail;
+ if (jn == jobtab+thisjob) {
+ if (jn->stat & STAT_CURSH) {
+ if (!lastval && isset(PIPEFAIL))
+ lastval = pipefail;
+ } else if (isset(PIPEFAIL))
+ lastval = pipefail;
+ }
}
/* Update status of job, possibly printing it */
@@ -531,17 +537,8 @@ update_job(Job jn)
return;
jn->stat |= (somestopped) ? STAT_CHANGED | STAT_STOPPED :
STAT_CHANGED | STAT_DONE;
- if (jn->stat & STAT_DONE) {
- int newlastval = storepipestats(jn, inforeground);
-
- if (job == thisjob) {
- if (jn->stat & STAT_CURSH) {
- if (!lastval && isset(PIPEFAIL))
- lastval = newlastval;
- } else if (isset(PIPEFAIL))
- lastval = newlastval;
- }
- }
+ if (jn->stat & STAT_DONE)
+ storepipestats(jn, inforeground);
if (!inforeground &&
(jn->stat & (STAT_SUBJOB | STAT_DONE)) == (STAT_SUBJOB | STAT_DONE)) {
int su;
@@ -991,7 +988,7 @@ printjob(Job jn, int lng, int synch)
if (skip_print) {
if (jn->stat & STAT_DONE) {
- (void) storepipestats(jn, job == thisjob);
+ storepipestats(jn, job == thisjob);
if (should_report_time(jn))
dumptime(jn);
deletejob(jn, 0);
@@ -1122,7 +1119,7 @@ printjob(Job jn, int lng, int synch)
/* delete job if done */
if (jn->stat & STAT_DONE) {
- (void) storepipestats(jn, job == thisjob);
+ storepipestats(jn, job == thisjob);
if (should_report_time(jn))
dumptime(jn);
deletejob(jn, 0);
pws
next prev parent reply other threads:[~2013-10-24 15:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-22 18:03 Ian F
2013-10-23 8:21 ` Peter Stephenson
2013-10-23 19:49 ` Ian F
2013-10-23 21:14 ` Peter Stephenson
2013-10-24 5:15 ` Bart Schaefer
2013-10-24 8:57 ` Peter Stephenson
2013-10-24 15:48 ` Peter Stephenson [this message]
2013-10-24 16:03 ` Peter Stephenson
2013-10-24 16:44 ` Bart Schaefer
2013-10-24 16:39 ` Bart Schaefer
2013-10-24 16:26 ` Bart Schaefer
2013-10-24 16:46 ` Peter Stephenson
2013-10-25 0:38 ` Bart Schaefer
2013-10-24 15:17 ` Jun T.
2013-10-24 16:25 ` 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=20131024164829.55842279@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).