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

Re: trap .. EXIT doesn't execute when exit is due to a signal



Bart Schaefer wrote:
> It just occured to me that it may very well be the case that bash is
> using the POSIX atexit() handler to execute its exit traps, which I
> believe would handle the situation described in 3513 without having
> to do any special handling of SIGINT.
> 
> However, I'm not positive that covers all the cases in which zsh runs
> the exit trap, and it'd have to be used carefully to be sure the exit
> trap wasn't run more than once.

No, it's not good enough for traps exiting functions.  bash only has an
EXIT trap for the whole shell.

bash-2.05b$ fn() { trap 'echo exiting' EXIT; echo fn run; }
bash-2.05b$ fn
fn run
bash-2.05b$ exit
exit
exiting

You couldn't use atexit() to fix the problem in zsh.  You'd need to
return from the interrupt and unwind the call stack to the top, then
exit.

It is a nuisance that EXIT traps aren't always run, however.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************



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