Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: localtraps
- X-seq: zsh-users 8763
- From: Vincent Stemen <zsh@xxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: localtraps
- Date: Wed, 27 Apr 2005 20:00:27 -0500
- In-reply-to: <1050427055907.ZM28766@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20050425063521.GA17598@xxxxxxxxxxxxxxxxx> <1050425163202.ZM25027@xxxxxxxxxxxxxxxxxxxxxxx> <20050426030308.GA21501@xxxxxxxxxxxxxxxxx> <200504261834.j3QIYHSa018951@xxxxxxxxxxxxxx> <20050426221247.GA3964@xxxxxxxxxxxxxxxxx> <1050427055907.ZM28766@xxxxxxxxxxxxxxxxxxxxxxx>
On Wed, Apr 27, 2005 at 05:59:07AM +0000, Bart Schaefer wrote:
> On Apr 26, 5:12pm, Vincent Stemen wrote:
> }
> } One thing I tried was to set a flag indicating that the signal had
> } already hit once so that when it re-calls the sig handler it would
> } know it was the second time. That did not work though for the same
> } reason. I cannot reset the flag before exiting the function because
> } it always completes the function before processing the next signal and
> } re-calling it. So on the next signal, the flag is always back unset.
>
> This should work with a sufficiently recent version of zsh to have the
> "always" construct:
>
> inner () {
> if ((trips++))
> then
> {
> print "Do the multiple-trip thing ..."
> } always {
> ((--trips))
> }
> fi
> }
>
> outer () {
> {
> setopt localoptions nolocaltraps
> integer -g trips=1
> trap inner INT
> print "Doing something useful now ..."
> sleep 2
> } always {
> unset trips
> trap outer INT
> }
> }
> trap outer INT
>
> With that, even if I press ^C and hold it down, it alternates between
> "Doing something useful now ..." and "Do the multiple-trip thing ..."
> and ends up with "trips" unset. Of course, this is on Linux; if you
> are right about the NetBSD signal behavior, you'll need something more
> subtle.
I added a sleep at the end to give me time to hit ^C and tested on
NetBSD. Here is the result.
# sigtest
^CDoing something useful now ...
^C^C^C^C^CDoing something useful now ...
^C^C^CDoing something useful now ...
Which is pretty much what I expected since I cannot reset the trap
in the sig handler.
--
Vincent Stemen
Avoid the VeriSign/Network Solutions domain registration trap!
Read how Network Solutions (NSI) was involved in stealing our domain name.
http://www.InetAddresses.net
Messages sorted by:
Reverse Date,
Date,
Thread,
Author