zsh-users
 help / color / mirror / code / Atom feed
* Option PRINT_EXIT_VALUE doesn't always work as expected
@ 2010-07-30 13:02 Vincent Lefevre
  2010-07-31 21:53 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Vincent Lefevre @ 2010-07-30 13:02 UTC (permalink / raw)
  To: zsh-users

Note: every test has been done under Debian/unstable (zsh 4.3.10).

I wonder why PRINT_EXIT_VALUE doesn't always work as expected:

ypig% setopt PRINT_EXIT_VALUE
ypig% false | head -n 1
zsh: exit 1     false | 
zsh: done       head -n 1
ypig% echo $pipestatus
1 0
ypig% false | true
ypig% echo $pipestatus
1 0

Also, if tst is a script that does "exit 141", I get as expected:

ypig% ./tst | head -n 1
zsh: exit 141   ./tst | 
zsh: done       head -n 1
ypig% echo $pipestatus
141 0

but if tst does "kill -PIPE $$", I get:

ypig% ./tst | head -n 1
ypig% echo $pipestatus
141 0

Actually, under some conditions, zsh knows that a process has been
killed with a signal:

ypig% svn log | cat | head -n 1
------------------------------------------------------------------------
svn: Write error: Broken pipe
zsh: exit 1       svn log | 
zsh: broken pipe  cat | 
zsh: done         head -n 1

How to make this always work?
Is this due to some bug in zsh?

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Option PRINT_EXIT_VALUE doesn't always work as expected
  2010-07-30 13:02 Option PRINT_EXIT_VALUE doesn't always work as expected Vincent Lefevre
@ 2010-07-31 21:53 ` Peter Stephenson
  2010-08-19 14:25   ` Vincent Lefevre
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2010-07-31 21:53 UTC (permalink / raw)
  To: zsh-users

On Fri, 30 Jul 2010 15:02:04 +0200
Vincent Lefevre <vincent@vinc17.net> wrote:
> Also, if tst is a script that does "exit 141", I get as expected:
> 
> ypig% ./tst | head -n 1
> zsh: exit 141   ./tst | 
> zsh: done       head -n 1
> ypig% echo $pipestatus
> 141 0
> 
> but if tst does "kill -PIPE $$", I get:
> 
> ypig% ./tst | head -n 1
> ypig% echo $pipestatus
> 141 0

The fact that the signal number + 128 is added to get the status isn't
currently taken account at that point.  It should presumably be
transparent.

Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.76
diff -p -u -r1.76 jobs.c
--- Src/jobs.c	31 Jul 2010 21:06:12 -0000	1.76
+++ Src/jobs.c	31 Jul 2010 21:47:54 -0000
@@ -873,6 +873,10 @@ printjob(Job jn, int lng, int synch)
 		    sflag = 1;
 		if (job == thisjob && sig == SIGINT)
 		    doputnl = 1;
+		if (isset(PRINTEXITVALUE) && isset(SHINSTDIN)) {
+		    sflag = 1;
+		    skip_print = 0;
+		}
 	    } else if (WIFSTOPPED(pn->status)) {
 		sig = WSTOPSIG(pn->status);
 		if ((int)strlen(sigmsg(sig)) > len)


-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Option PRINT_EXIT_VALUE doesn't always work as expected
  2010-07-31 21:53 ` Peter Stephenson
@ 2010-08-19 14:25   ` Vincent Lefevre
  0 siblings, 0 replies; 3+ messages in thread
From: Vincent Lefevre @ 2010-08-19 14:25 UTC (permalink / raw)
  To: zsh-users

On 2010-07-31 22:53:45 +0100, Peter Stephenson wrote:
> On Fri, 30 Jul 2010 15:02:04 +0200
> Vincent Lefevre <vincent@vinc17.net> wrote:
> > Also, if tst is a script that does "exit 141", I get as expected:
> > 
> > ypig% ./tst | head -n 1
> > zsh: exit 141   ./tst | 
> > zsh: done       head -n 1
> > ypig% echo $pipestatus
> > 141 0
> > 
> > but if tst does "kill -PIPE $$", I get:
> > 
> > ypig% ./tst | head -n 1
> > ypig% echo $pipestatus
> > 141 0
> 
> The fact that the signal number + 128 is added to get the status isn't
> currently taken account at that point.  It should presumably be
> transparent.

Actually I'm wondering whether this is a good idea. I often do
"program | less" and I often quit "less" before looking at the
end of the output, so that one gets a typical broken pipe, with
a useless "zsh: broken pipe" message.

Perhaps there should be an option (useful only with PRINT_EXIT_VALUE)
to ignore the broken pipe specifically. And/or an option so that
exit information is output only when the last command of a pipeline
exits with a non-zero status.

I'm also wondering whether I still need PRINT_EXIT_VALUE since I now
print the exit status (or signal) in my prompt.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-19 14:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-30 13:02 Option PRINT_EXIT_VALUE doesn't always work as expected Vincent Lefevre
2010-07-31 21:53 ` Peter Stephenson
2010-08-19 14:25   ` Vincent Lefevre

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).