From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 2776 invoked from network); 7 May 2020 21:22:28 -0000 Received-SPF: pass (primenet.com.au: domain of zsh.org designates 203.24.36.2 as permitted sender) receiver=inbox.vuxu.org; client-ip=203.24.36.2 envelope-from= Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 7 May 2020 21:22:28 -0000 Received: (qmail 26850 invoked by alias); 7 May 2020 21:22:16 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45790 Received: (qmail 15942 invoked by uid 1010); 7 May 2020 21:22:15 -0000 X-Qmail-Scanner-Diagnostics: from wout1-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25801. spamassassin: 3.4.4. Clear:RC:0(64.147.123.24):SA:0(-1.1/5.0):. Processed in 1.40832 secs); 07 May 2020 21:22:15 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrkedtgdduheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfgjfhfogggtgfesthhqtddtredtjeenucfhrhhomhepffgrnhhi vghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvgeqne cuggftrfgrthhtvghrnhephfdtteefheevuedthedutdeifeegteettdejtdffheduieei jeelteetkeduteehnecukfhppedutdelrdeiiedrudehrddvfeelnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggrnhhivghlrdhs hhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Date: Thu, 7 May 2020 21:21:36 +0000 From: Daniel Shahaf To: Roman Perepelitsa Cc: Zsh hackers list Subject: Re: local_traps doesn't restore traps set from functions Message-ID: <20200507212136.3ff1a843@tarpaulin.shahaf.local2> In-Reply-To: References: X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Roman Perepelitsa wrote on Wed, 06 May 2020 15:31 +0200: > Is this working as intended? >=20 > =E2=9D=AF zsh -f > adam% () { trap '' INT } > adam% () { emulate -L zsh; trap 'echo INT' INT } > adam% kill -INT $$ > INT > adam% >=20 I'd say it doesn't, since the trap _is_ set before the second function is c= alled =E2=80=94 . % () { trap '' INT } % kill -INT $$ %=20 . =E2=80=94 and the documentation is quite clear about the semantics in this = case: LOCAL_TRAPS If this option is set when a signal trap is set inside a function, then the previous status of the trap for that signal will be restored when the function exits. > It appears that local_traps doesn't restore traps that were originally > set from functions. Precisely. The following patch fixes it: [[[ diff --git a/Src/signals.c b/Src/signals.c index 4adf03202..3e4fdf370 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -1154,6 +1154,29 @@ endtrapscope(void) } } =20 + /* Fixup locallevel of signals. */ + { + int i; + for (i =3D 0; i < VSIGCOUNT; ++i) { + int locallevel_of_signal =3D (sigtrapped[i] >> ZSIG_SHIFT); + if (locallevel_of_signal > locallevel) { + DPUTS3(locallevel_of_signal !=3D locallevel + 1, + "BUG: signal %s's locallevel unexpected: %d>>ZSIG_SHIFT seen, v. %d+= 1 expected", + sigs[i], sigtrapped[i], locallevel); + + /*=20 + * Decrement the locallevel embedded in sigtrapped[i]. + * + * Keep the low ZSIG_SHIFT bits unchanged. + */ + sigtrapped[i] =3D + (sigtrapped[i] & ((1u << ZSIG_SHIFT) - 1u)) + | + (locallevel << ZSIG_SHIFT); + } + } + } + if (exittr) { /* * We already made sure this wasn't set as a POSIX exit trap. diff --git a/Src/zsh.h b/Src/zsh.h index 1f2d774a1..71ba6e6e0 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2940,8 +2940,8 @@ struct heap { #define ZSIG_FUNC (1<<2) /* Trap is a function, not an eval list */ /* Mask to get the above flags */ #define ZSIG_MASK (ZSIG_TRAPPED|ZSIG_IGNORED|ZSIG_FUNC) -/* No. of bits to shift local level when storing in sigtrapped */ #define ZSIG_ALIAS (1<<3) /* Trap is stored under an alias */ +/* No. of bits to shift locallevel when storing in sigtrapped */ #define ZSIG_SHIFT 4 =20 /* ]]] [[[ % () { trap '' INT } % () { emulate -L zsh; trap 'echo INT' INT } % kill -INT $$ %=20 ]]] However, I don't know this area of the code well enough to be sure the patch doesn't break anything. Reviews would be appreciated. Also, if someone could write a regression test for this, that'd be great. Cheers, Daniel