From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17014 invoked from network); 27 Apr 2005 05:59:35 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 27 Apr 2005 05:59:35 -0000 Received: (qmail 47114 invoked from network); 27 Apr 2005 05:59:25 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 27 Apr 2005 05:59:25 -0000 Received: (qmail 396 invoked by alias); 27 Apr 2005 05:59:20 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8762 Received: (qmail 382 invoked from network); 27 Apr 2005 05:59:19 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 27 Apr 2005 05:59:19 -0000 Received: (qmail 46242 invoked from network); 27 Apr 2005 05:59:19 -0000 Received: from vms044pub.verizon.net (206.46.252.44) by a.mx.sunsite.dk with SMTP; 27 Apr 2005 05:59:12 -0000 Received: from candle.brasslantern.com ([4.11.1.68]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IFL00GKICMKK3VH@vms044.mailsrvcs.net> for zsh-users@sunsite.dk; Wed, 27 Apr 2005 00:59:09 -0500 (CDT) Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id j3R5x7uB028768 for ; Tue, 26 Apr 2005 22:59:07 -0700 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j3R5x7Yl028767 for zsh-users@sunsite.dk; Tue, 26 Apr 2005 22:59:07 -0700 Date: Wed, 27 Apr 2005 05:59:07 +0000 From: Bart Schaefer Subject: Re: localtraps In-reply-to: <20050426221247.GA3964@quark.hightek.org> To: zsh-users@sunsite.dk Message-id: <1050427055907.ZM28766@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii 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> Comments: In reply to Vincent Stemen "Re: localtraps" (Apr 26, 5:12pm) 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 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.