zsh-workers
 help / color / mirror / code / Atom feed
* prompt problem
@ 2010-08-20 12:28 Vincent Lefevre
  2010-09-07 19:26 ` Vincent Lefevre
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Lefevre @ 2010-08-20 12:28 UTC (permalink / raw)
  To: zsh-workers

After a "zsh -f", source the following:

precmd()
{
  psvar[1]=$?
  if [[ $psvar[1] -gt 128 ]] then
    local sig=$signals[$(($psvar[1]-127))]
    [[ -n $sig ]] && psvar[1]=$sig
  fi
}

TRAPCLD() { [[ -o interactive && -n $TTY ]] && precmd }

PS1="%m:%20<...<%~%<<%(?..[%1v])%(#.#.>) "

then execute

  { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }

and interrupt it with Ctrl-C.

I can see two unexpected behaviors (not always reproducible, one
needs to try several times), as seen here:

ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
^C%
ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
^C%
ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
^C%
ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
^C%
ypig:~[INT]> ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
^C%
ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
^C%
ypig:~[0]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
^C%
ypig:~[0]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
^C%

So, sometimes the prompt is output twice. This seems to be a bug.

I sometimes get a "[0]" instead of "[INT]". This one may be due
to the fact that $? is 0 in the trap. I wonder whether this is
correct. At least the behavior doesn't seem to be consistent
with:

ypig:~> sleep 5 &
[1] 9217
ypig:~> blah
zsh: command not found: blah
ypig:~[127]> 
ypig:~[127]> 
[1]  + done       sleep 5
ypig:~[127]> 
ypig:~[127]> echo $?
127

where the value of $? seems to be preserved after "sleep 5" has
terminated.

-- 
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] 6+ messages in thread

* Re: prompt problem
  2010-08-20 12:28 prompt problem Vincent Lefevre
@ 2010-09-07 19:26 ` Vincent Lefevre
  2010-09-08  8:19   ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Lefevre @ 2010-09-07 19:26 UTC (permalink / raw)
  To: zsh-workers

Any news?

On 2010-08-20 14:28:23 +0200, Vincent Lefevre wrote:
> After a "zsh -f", source the following:
> 
> precmd()
> {
>   psvar[1]=$?
>   if [[ $psvar[1] -gt 128 ]] then
>     local sig=$signals[$(($psvar[1]-127))]
>     [[ -n $sig ]] && psvar[1]=$sig
>   fi
> }
> 
> TRAPCLD() { [[ -o interactive && -n $TTY ]] && precmd }
> 
> PS1="%m:%20<...<%~%<<%(?..[%1v])%(#.#.>) "
> 
> then execute
> 
>   { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
> 
> and interrupt it with Ctrl-C.
> 
> I can see two unexpected behaviors (not always reproducible, one
> needs to try several times), as seen here:
> 
> ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
> ^C%
> ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
> ^C%
> ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
> ^C%
> ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
> ^C%
> ypig:~[INT]> ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
> ^C%
> ypig:~[INT]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
> ^C%
> ypig:~[0]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
> ^C%
> ypig:~[0]> { sleep 3 } | { sleep 3 } | { sleep 3 } | { sleep 3 }
> ^C%
> 
> So, sometimes the prompt is output twice. This seems to be a bug.
> 
> I sometimes get a "[0]" instead of "[INT]". This one may be due
> to the fact that $? is 0 in the trap. I wonder whether this is
> correct. At least the behavior doesn't seem to be consistent
> with:
> 
> ypig:~> sleep 5 &
> [1] 9217
> ypig:~> blah
> zsh: command not found: blah
> ypig:~[127]> 
> ypig:~[127]> 
> [1]  + done       sleep 5
> ypig:~[127]> 
> ypig:~[127]> echo $?
> 127
> 
> where the value of $? seems to be preserved after "sleep 5" has
> terminated.

-- 
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] 6+ messages in thread

* Re: prompt problem
  2010-09-07 19:26 ` Vincent Lefevre
@ 2010-09-08  8:19   ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2010-09-08  8:19 UTC (permalink / raw)
  To: zsh-workers

On Sep 7,  9:26pm, Vincent Lefevre wrote:
}
} Any news?

My guess would be that this is a race condition of some kind.  In some
cases the TRAPCLD function gets called twice on a single interrupt.
It's somewhat easier to make this happen [and much easier to observe
that it is what happens] if (a) you put a "print" statement in the
precmd function and (b) you vary the number of seconds passed to each
sleep in the pipe.  When called twice, $? differs in each call -- it's
130 (INT) in the first call, and 0 in the second, in every case where
I got two calls to happen at all.

The race probably depends on which part of the pipeline gets signalled
first -- something over which zsh has no control, as it's counting on
the OS to kill the entire process group when managing of a pipeline.

As a further guess, when the process group is killed zsh wakes up and
starts to print the prompt when the SIGCHLD is received for the group
leader.  Another child in the group then exits, catching the internals
of ZLE in a state where the prompt has been printed but it hasn't
recorded that fact yet.


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

* Re: Prompt problem
  1996-12-17 12:51 Prompt problem Alexey Solovyov
  1996-12-17 13:10 ` Goran Larsson
@ 1996-12-17 13:24 ` gwing
  1 sibling, 0 replies; 6+ messages in thread
From: gwing @ 1996-12-17 13:24 UTC (permalink / raw)
  To: Alexey Solovyov; +Cc: zsh-workers

Alexey Solovyov wrote:
:I just noticed that one-symbol PS1 is not handled properly. If it is a
:feature how to get rid of it?   :)

This was a bug for a short while, quite a while back.  
New versions should not have it.  If so, what version, what machine?
-- 
Geoff Wing [gwing@primenet.com.au]   Technical Manager
  Phone    : +61-3-9818 2977	     PrimeNet - Internet Consultancy
  Facsimile: +61-3-9819 3788	     Web : <URL:http://www.primenet.com.au/>
  Mobile   : 0412 162 441


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

* Re: Prompt problem
  1996-12-17 12:51 Prompt problem Alexey Solovyov
@ 1996-12-17 13:10 ` Goran Larsson
  1996-12-17 13:24 ` gwing
  1 sibling, 0 replies; 6+ messages in thread
From: Goran Larsson @ 1996-12-17 13:10 UTC (permalink / raw)
  To: zsh-workers

> I just noticed that one-symbol PS1 is not handled properly. If it is a
> feature how to get rid of it?   :)

You are using zsh version 3.0.0 and just found the problem I reported
on the 3:rd of september. The fix from Geoff Wing <mason@primenet.com.au>
is included in version 3.0.1.

-- 
 Goran Larsson                mailto:hoh@approve.se
 I was an atheist,            http://home1.swipnet.se/%7Ew-12153/
 until I found out I was God.


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

* Prompt problem
@ 1996-12-17 12:51 Alexey Solovyov
  1996-12-17 13:10 ` Goran Larsson
  1996-12-17 13:24 ` gwing
  0 siblings, 2 replies; 6+ messages in thread
From: Alexey Solovyov @ 1996-12-17 12:51 UTC (permalink / raw)
  To: zsh-workers

Hi, there,

I just noticed that one-symbol PS1 is not handled properly. If it is a
feature how to get rid of it?   :)

With respect,
----------------------------------------------------------------------
Alexey A. Solovyov
<alekso@math.ucr.edu>
<alekso@math.uu.se>


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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-20 12:28 prompt problem Vincent Lefevre
2010-09-07 19:26 ` Vincent Lefevre
2010-09-08  8:19   ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
1996-12-17 12:51 Prompt problem Alexey Solovyov
1996-12-17 13:10 ` Goran Larsson
1996-12-17 13:24 ` gwing

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