From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2063 invoked from network); 28 Apr 2005 01:02:53 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 28 Apr 2005 01:02:53 -0000 Received: (qmail 71274 invoked from network); 28 Apr 2005 01:02:45 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 28 Apr 2005 01:02:45 -0000 Received: (qmail 19726 invoked by alias); 28 Apr 2005 01:02:36 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8763 Received: (qmail 19706 invoked from network); 28 Apr 2005 01:02:35 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 28 Apr 2005 01:02:35 -0000 Received: (qmail 70184 invoked from network); 28 Apr 2005 01:02:35 -0000 Received: from lakermmtao08.cox.net (68.230.240.31) by a.mx.sunsite.dk with SMTP; 28 Apr 2005 01:02:27 -0000 Received: from quark.hightek.org ([68.12.75.33]) by lakermmtao08.cox.net (InterMail vM.6.01.04.00 201-2131-118-20041027) with ESMTP id <20050428010227.ERMN18139.lakermmtao08.cox.net@quark.hightek.org> for ; Wed, 27 Apr 2005 21:02:27 -0400 Received: by quark.hightek.org (Postfix, from userid 501) id 67A7F4589B; Wed, 27 Apr 2005 20:00:27 -0500 (CDT) Date: Wed, 27 Apr 2005 20:00:27 -0500 From: Vincent Stemen To: zsh-users@sunsite.dk Subject: Re: localtraps Message-ID: <20050428010027.GA8100@quark.hightek.org> References: <20050425063521.GA17598@quark.hightek.org> <1050425163202.ZM25027@candle.brasslantern.com> <20050426030308.GA21501@quark.hightek.org> <200504261834.j3QIYHSa018951@news01.csr.com> <20050426221247.GA3964@quark.hightek.org> <1050427055907.ZM28766@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1050427055907.ZM28766@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 Wed, Apr 27, 2005 at 05:59:07AM +0000, Bart Schaefer wrote: > On Apr 26, 5:12pm, Vincent Stemen wrote: > } > } 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. > > This should work with a sufficiently recent version of zsh to have the > "always" construct: > > inner () { > if ((trips++)) > then > { > print "Do the multiple-trip thing ..." > } always { > ((--trips)) > } > fi > } > > outer () { > { > setopt localoptions nolocaltraps > integer -g trips=1 > trap inner INT > print "Doing something useful now ..." > sleep 2 > } always { > unset trips > trap outer INT > } > } > trap outer INT > > With that, even if I press ^C and hold it down, it alternates between > "Doing something useful now ..." and "Do the multiple-trip thing ..." > and ends up with "trips" unset. Of course, this is on Linux; if you > are right about the NetBSD signal behavior, you'll need something more > subtle. I added a sleep at the end to give me time to hit ^C and tested on NetBSD. Here is the result. # sigtest ^CDoing something useful now ... ^C^C^C^C^CDoing something useful now ... ^C^C^CDoing something useful now ... Which is pretty much what I expected since I cannot reset the trap in the sig handler. -- 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