From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3/2) with ESMTP id WAA18867 for ; Fri, 26 Jul 1996 22:11:32 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id HAA04892; Fri, 26 Jul 1996 07:57:18 -0400 (EDT) Resent-Date: Fri, 26 Jul 1996 07:57:18 -0400 (EDT) From: Zoltan Hidvegi Message-Id: <199607261156.NAA04201@bolyai.cs.elte.hu> Subject: Re: Odd behavior of "trap" and "functions" in 3.0-pre2 To: pws@ifh.de (Peter Stephenson) Date: Fri, 26 Jul 1996 13:56:21 +0200 (MET DST) Cc: zsh-workers@math.gatech.edu (Zsh workers list) In-Reply-To: <199607260808.KAA09932@hydra.ifh.de> from Peter Stephenson at "Jul 26, 96 10:08:34 am" Organization: Dept. of Comp. Sci., Eotvos University, Budapest, Hungary Phone: (36 1)2669833 ext: 2667, home phone: (36 1) 2752368 X-Mailer: ELM [version 2.4ME+ PL16 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-ID: <"Afc1p.0.MC1.TAB-n"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1780 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu > schaefer@candle.brasslantern.com 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