Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: localtraps

On Tue, Apr 26, 2005 at 07:34:16PM +0100, Peter Stephenson wrote:
> Vincent Stemen wrote:
> > I had hoped that I could get around the problem for now by explicitly
> > resetting the signal trap without using localtraps but, as you
> > indicated, it will not let me do anything with the same signal while
> > it is in the signal handler function.  This is a real problem that I
> > don't know how to get around.
> The problem may be related to the fact that the shell executes traps
> from within the signal handler.  Other shells presumably wait for the
> handler to exit and execute the trap at the next obvious point (e.g. a
> command executed).

I am not sure if this is exactly what you are saying, but zsh on
NetBSD queues the next signal and will not re-call the signal handler
until it exits the handler from the first one.  However, I can trap a
different signal from within the signal handler and if it catches that
new signal, it immediatly re-calls the handler.  It just won't do it
on the same signal.

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.

> However, I've tried this in some recent versions of zsh (4.2.0 and
> 4.3.0-dev-1, which is a moving target) and it seems to do what I think
> you want... abort the programme when you hit ^C twice quickly, otherwise
> continue.  So I'm not sure what you're doing wrong.

My need generally is not just to require two ^C's to exit.  I often
need to print a message, have a delay, and/or do other work on the
first signal and abort on the second one, or disable the signal all
together while in the handler to perform some function so that another
hit will not re-call the function, and then re-enable the signal just
before exiting the handler.  I also have written scripts before where
I required more than two ^C's to abort in critical sections of code.

Either way, I really need to be able to use the trap command on the
same signal in the handler like I can in the BSD shell.  It would also
be very convenient to be able to use localtraps so that I don't have
to explicitly reset the signal before returning.

Vincent Stemen
Avoid the VeriSign/Network Solutions domain registration trap!
Read how Network Solutions (NSI) was involved in stealing our domain name.

Messages sorted by: Reverse Date, Date, Thread, Author