From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6330 invoked from network); 26 Apr 2005 03:05:07 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 26 Apr 2005 03:05:07 -0000 Received: (qmail 58511 invoked from network); 26 Apr 2005 03:05:00 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 26 Apr 2005 03:05:00 -0000 Received: (qmail 16521 invoked by alias); 26 Apr 2005 03:04:51 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8758 Received: (qmail 16507 invoked from network); 26 Apr 2005 03:04:50 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 26 Apr 2005 03:04:50 -0000 Received: (qmail 57457 invoked from network); 26 Apr 2005 03:04:50 -0000 Received: from lakermmtao04.cox.net (68.230.240.35) by a.mx.sunsite.dk with SMTP; 26 Apr 2005 03:04:45 -0000 Received: from quark.hightek.org ([68.12.75.33]) by lakermmtao04.cox.net (InterMail vM.6.01.04.00 201-2131-118-20041027) with ESMTP id <20050426030443.ZNKA20878.lakermmtao04.cox.net@quark.hightek.org> for ; Mon, 25 Apr 2005 23:04:43 -0400 Received: by quark.hightek.org (Postfix, from userid 501) id D3A944588D; Mon, 25 Apr 2005 22:03:08 -0500 (CDT) Date: Mon, 25 Apr 2005 22:03:08 -0500 From: Vincent Stemen To: zsh-users@sunsite.dk Subject: Re: localtraps Message-ID: <20050426030308.GA21501@quark.hightek.org> References: <20050425063521.GA17598@quark.hightek.org> <1050425163202.ZM25027@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1050425163202.ZM25027@candle.brasslantern.com> User-Agent: Mutt/1.4.1i X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 On Mon, Apr 25, 2005 at 04:32:02PM +0000, Bart Schaefer wrote: > On Apr 25, 1:35am, Vincent Stemen wrote: > } Subject: localtraps > } > } I don't seem to be able to get the localtraps option to work. > > Try it where the outer function is NOT a trap for the same signal > that you're trapping inside the function. > > I suspect that changing the trap of the same signal that is trapped > is confusing the trap code, because low-level signal handling already > requires that the signal handler restore itself before exiting, so in > effect you're restoring multiple different traps, and the order in > which function exit and trap unwinding are processed is mixed up. I have some new information. 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. Here is a new snippet of test code that does basically what I am trying to do perfectly under the BSD shell. #-------------------------------- #!/bin/sh abort() { echo echo '** Aborting program **' echo exit 1 } signal() { local signal=$1 if [ -n "$script" ] then trap abort INT echo -e "\n$0: $script Interrupted. Hit ^C again to abort everything." sleep 2 echo -n "Continuing " trap 'signal INT' INT # Reset the signal trap for ^C return else abort fi } script=foo trap 'signal' INT echo -n "Doing something important " for n in 1 2 3 4 5 6 7 8 9 do echo -n "." sleep 1 done echo echo "Exiting normally" echo #-------------------------------- Here is the output using the BSD /bin/sh: # sigtest Doing something important ..^C sigtest: foo Interrupted. Hit ^C again to abort everything. Continuing ..^C sigtest: foo Interrupted. Hit ^C again to abort everything. ^C ** Aborting program ** After the first time I hit ^C, I waited more than 2 seconds. The second time I hit ^C twice and it called abort() as I wanted. Trying this under Z shell, I get # sigtest Doing something important ..^C sigtest6: foo Interrupted. Hit ^C again to abort everything. ^CContinuing sigtest6: foo Interrupted. Hit ^C again to abort everything. ^CContinuing sigtest6: foo Interrupted. Hit ^C again to abort everything. Continuing ....... Exiting normally Since it ignores the trap statement in signal() I have no way of aborting. I am using Z shell in all the scripts I am working on because it is generally so vastly better that bourne shell, but this is a real handycap. Any ideas? -- 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