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

Re: Odd behavior of "trap" and "functions" in 3.0-pre2



> schaefer@xxxxxxxxxxxxxxxxxxxxxxx wrote:
> > zagzig<14> trap "echo foo" USR2
> > zagzig<17> grep TRAP <<(functions)
> > TRAPALRM () {
> > zagzig<18>
> > 
> > I'm almost certain that `functions` used to list all the TRAPxxx ....
> 
> Looks like the `trap' form of traps don't handle functions properly,
> while the TRAPxxx functions do handle traps properly, so this is
> certainly a mistake.  It seems the bin_trap() end of things got missed
> out in some reorganisation.
> 
> I've tried to write this in such away as to maintain symmetry between
> settrap() and unsettrap().  They now have a final argument which is
> set to 1 if they should set/unset the corresponding function.  This is
> necessary because the function code needs to be able to do its own
> separate manipulations on the function.  The rule is therefore that
> any call from outside the function-handling code should set the last
> argument to 1 to maintain parallel trap/TRAPxxx settings.
> 
> Note there's no memory leak in the second last hunk:  the function,
> the command list, and the name all needed to be separately allocated.
> 
> I fixed a related bug:
> 
> % TRAPUSR1() { }
> % trap
> TRAPUSR1() {}
> 
> When defining the function, you now need the space between the braces

I've mostly rewritten most of the thing related to traps which fixed all of
these bugs you describe above.  Sorry for the duplicate work.  In pre4
traps defined by trap and TRAPxxx functions will be different.  trap will
be POSIX compatible.  It will not define any function and it executes the
trap in the current environment.  TRAPxxx functions will work as before.
Also traps set by trap will be unset in a subshell as required by POSIX but
this does not affect the TRAPxxx functions.  This is only done with
explicit subshells and with backgrounded commands, so trap | less still
works (in bash/ksh trap | less shows nothing).  This is legal since POSIX
does not tell wether a pipe element should be executed in a subshell or in
the current shell environment.  In fact I've already put together pre4 and
put in onto the ftp site yesterday.  Then I went home and I wanted to post
the announcement with my modem but then I discovered a bug in this new trap
implementation ...  So even if you see pre4 on an ftp site, do not download
it, it is not the final version.  The final pre4 will be ready within a few
hours.

Zoltan




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