From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 6383 invoked from network); 12 Dec 2022 04:52:56 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 Dec 2022 04:52:56 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670820776; b=AxOESMcc8MU6RvfpVmajSEFiinw3Sr3RIubRxn46TbDDvTYZYRtBRjZzkE1DDV5U26P+cuEdeA RabW8iJpAr4BgBDfJF1W1+++h2VA/UR1kDfNmEPaU5CloF/tv1lrc/6fomE8tIYgdyTt4qnVdj enHyi1+IZ4VLvzASpGebAHN5+e6Yb6STZqkl9sU39BnviQkMmAUwrsUS05rfTc5n4OsXnuHz8H 3snCY6hHk0wd9zhyqNfGHeLtY6kavC3lwPk6ikHeVKAY8dD2PeuCnMoimUut5moFnW8aOKj/W2 A+z/wMoC734sjUiJTtXfVx8Dpxt9zryWHf5GWQEUgin5xQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f48.google.com) smtp.remote-ip=209.85.208.48; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1670820776; bh=X8vf2jx3gOVmSebSVZWJigKvD2VYL4I0w7IfhHeviic=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=jeCFCJ0Hip0G7Ak0qutr3uPywRA/eQW8Kuz7BBQemiRvf4NnkfUPjzr0kaM88W4SqKRxqvvGYX oTbo5BtuhT/FsClfvEoMK8PDndCjgODlKV6hJQBjF90olM0DjcetjEuwcCaelM2UStAZD+ZPxT 9F0BPSbGtEC3GV1olaBd1p0Rg4U8aSGuU10Wv6I8PwimQYNRaI+gb0NtZ6QfvBky2HIlSbkvaQ GjE51d7Y2kJ9BBYL2nizk6cXOSHqf+dYkfoKVDm5+66FFvRiv+V6bPymhoubZQe0zfz2Q/0a1N 1qto8FD3FKK8iR4V+je03jDfwSt4nXFSUP6LJv/CKDBLnQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=+ixRIPlEhfFmmlOV6oTjgOjLYOAOluKvVXaswG7BSDA=; b=cdsCc6mnd7pN48bBBy3skNmJT8 Zpyc73wbuk7Tv9OtWgmJyacGEWGgOPKr/FOio4VEBSfjnfOD72cR8AhAwo/YzaI0kcxB1fsasXk5u /GXCPXxa23K9asLK9ohMphO4yY68Y66pfJ3Z/XSsYsO2dnjgu7ENqKfYtV50YI+gKAhHe9Ieh1clA AD2FZnrG/tzV4631xc14CU0+RZVZpGgfWdL0r5jcM9EYfXwW9kt9WOQ6q1qQCwAP2vbzhQ2Psqjb6 mA66QDc9mQ3jYnJ3rC0HPQNz6sFonupZcBxLMN13ahgCwWMqJdzqAuH/ECxPvVxGcheYooc3AjNuB Z93KV78g==; Received: by zero.zsh.org with local id 1p4aoC-0002J7-4V; Mon, 12 Dec 2022 04:52:56 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f48.google.com) smtp.remote-ip=209.85.208.48; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f48.google.com ([209.85.208.48]:40744) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1p4anb-00020z-La; Mon, 12 Dec 2022 04:52:20 +0000 Received: by mail-ed1-f48.google.com with SMTP id e13so11223798edj.7 for ; Sun, 11 Dec 2022 20:52:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+ixRIPlEhfFmmlOV6oTjgOjLYOAOluKvVXaswG7BSDA=; b=s2L2CtO8c3AXgZOgrNq24/IV9+lU24sVfimcEHWBoh8TBkuYixkz9qF7/muE2CG5Fb A5UiIy2mlgbq7WrOGDSea0ObXV3D5AGCHl9HTVHogetO3gDrtLpeR0NP/fTXfnYPEjZw Xk6g5ydaSkAnbnef5g+YLcC5AZ1Ke0bGlpedr6cWrYQihS3hTWeHVlhK12inRva5cvi3 mh6LQiBstW8ZqVRIT85//bKFe+3hyfmSfvpA3x0lhbjJb9Vof7cf0sHfqiIGBB/XcxYL nFgG6WDcvVUS932vWf7i/pRcCkAJzJuKx2Oao10NVNIw3hBHuEF/XILatsE73UsM8sS6 mwuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+ixRIPlEhfFmmlOV6oTjgOjLYOAOluKvVXaswG7BSDA=; b=YDDubLB43boDaW7JjlLHtUuE2JyIQTbkPUshhjQxbnDU6XCw55HMvTMp1vtAnp/qyL J53uuaaSMMzuB1klTj6lNxq2c1dq0lo6dK5Z2YuEubSTbb7gW9+giA3bSG8+x24qOvM3 ztjkpdWO2bH8p8sOlfIf+qfdRD0gTYHB/Vk5qFnfjwcqiBhPM5YFDCUo/oQRqCqqXxYe 5QdqXp+YZgNKgSSr80Mc1oWmW2IAFQBSAyl20CQ8u5c3M75BrCw5Bhx72xvJvWL6rSjI gyCITZ4baq7O+cicakAtrUKWdM1nocA2IyG3Oo7DqH6L47J0EgRaN03UAE88KQpTCUnR uU8Q== X-Gm-Message-State: ANoB5pnd3Atwhmv5KkH3oxL+ri3POvq5Q8TdHXQ4tUTi41yc8rvbDe3u VDrF90rNazICAhETLWoWosBx9KKJzjmUyl7Aucbo3jYCpMh4Y5/G X-Google-Smtp-Source: AA0mqf5b4bo5Wy1k5Pqkh8e6+WL3WdJ6cn6IWcjoDKdk75CNonN6he6jMUcemeF/9IhCWEYHIOjbx6tUVQBWUhlANRE= X-Received: by 2002:aa7:d4d4:0:b0:46b:5c9f:52e with SMTP id t20-20020aa7d4d4000000b0046b5c9f052emr40142681edr.416.1670820739000; Sun, 11 Dec 2022 20:52:19 -0800 (PST) MIME-Version: 1.0 References: <1939278e-89c4-812d-5dea-e836568dc100@inlv.org> In-Reply-To: <1939278e-89c4-812d-5dea-e836568dc100@inlv.org> From: Bart Schaefer Date: Sun, 11 Dec 2022 20:52:07 -0800 Message-ID: Subject: Re: EXIT trap not executed on error To: Martijn Dekker Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 51191 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Had this sitting on my TODO list for four years. Mentioned it in a recent thread about ERR_EXIT handling. On Sat, Dec 8, 2018 at 12:23 PM Martijn Dekker wrote: > > When zsh exits due to an error in a special builtin (e.g. 'set -o > bad@option') or in an arithmetic expression in $((...)), the EXIT trap > is not executed. > > Is this a bug? I'm going to have to say "yes." Because this is "zsh -c", we come through this bit of execlist(): 1632 if (exiting && sigtrapped[SIGEXIT]) { 1633 dotrap(SIGEXIT); 1634 /* Make sure this doesn't get executed again. */ 1635 sigtrapped[SIGEXIT] = 0; 1636 } That brings us to this bit of signals.c with errflag == ERRFLAG_ERROR: 1302 /* if signal is being ignored or the trap function * 1303 * is NULL, then return * 1304 * * 1305 * Also return if errflag is set. In fact, the code in the * 1306 * function will test for this, but this way we keep status flags * 1307 * intact without working too hard. Special cases (e.g. calling * 1308 * a trap for SIGINT after the error flag was set) are handled * 1309 * by the calling code. (PWS 1995/06/08). * 1310 * * 1311 * This test is now replicated in dotrap(). */ 1312 if ((*sigtr & ZSIG_IGNORED) || !sigfn || errflag) 1313 return; I don't recall why this suppresses traps on errflag, if I ever knew. However, the comment suggests the calling code should be clearing errflag around the dotrap(). Indeed, this seems to fix at least this case: diff --git a/Src/exec.c b/Src/exec.c index a1059af5e..57a1eaa1d 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1630,6 +1630,7 @@ sublist_done: thisjob = cj; if (exiting && sigtrapped[SIGEXIT]) { + errflag = 0; dotrap(SIGEXIT); /* Make sure this doesn't get executed again. */ sigtrapped[SIGEXIT] = 0; The question is whether its OK here to just clear errflag like this, or if it should be saved and restored?