From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-return-43662-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 3675dc50 for ; Tue, 9 Oct 2018 13:39:28 +0000 (UTC) Received: (qmail 16039 invoked by alias); 9 Oct 2018 13:39:17 -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: 43662 Received: (qmail 11139 invoked by uid 1010); 9 Oct 2018 13:39:17 -0000 X-Qmail-Scanner-Diagnostics: from out3-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.27):SA:0(-2.6/5.0):. Processed in 0.80933 secs); 09 Oct 2018 13:39:17 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:references:date :in-reply-to:subject; s=fm1; bh=6hqYweGFwpEfziR9/T+PgZiTzLXGVLwu MT2ZPVBfdtQ=; b=HX98fHX/e4X9BwI7kAHp+fN9kyh0ojwE+hm6F6Aq1qgCsWwD EEMemL8naynCr2Ubscy4goQvzcIOFrjQyQe/l6xXY6M7U7/MLeErhXeIVn3wd9dJ ZRph2La5eC4TKmiF2jTXj8xhWVcmcEbBDC3SJiYOb2DzZzQMoe+GXav/4c+8KL9h PEffPKSxn9DGnw9CcukLFCCoa6AJJUQ7/lTStypleh6VOmO/Q1YOut0npPeUukvD Tmy4rVXiPz3BUL9XgZZLQAaR/S6M01DrVPDGuYWdh9sZmWN8BL4ADiXgNheCbwJJ 9JbRL2ubuKyJGIgdhhNCHr0vqzrpoe97iN/98w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=6hqYweGFwpEfziR9/T+PgZiTzLXGVLwuMT2ZPVBfd tQ=; b=mkQTm144HYwIWGncX7Gzigr5oSQq1m+04PmllVNgm9WbPwi0Khg2Zo4bE I8MJHAWBjoLTqMQQphKuvDVo8bkTmpRiIdUu5hb94t+Gp5K601KMEG3rymhG+Xy6 N/ppWOK8OW/K7V+ngVqdBI2UuZuE7h0ZTA+If+NbxEF/GJYkvejMOsFP256va1N5 4AOyObMTwgOC6iyvqWEkb9o20NSmpglu6kQ2jbNdP5/xJoOiVfY1BCddq4KTHPQu CYi9v0wn1gFJZSxHrsMb1D5zIFhusVxzfXOZoLtxB2YgnYbkCx/BNmtBJ44bodnq LOQXqdagSdo3/VYOSna7O8nWkqYEQ== X-ME-Sender: X-ME-Proxy: Message-Id: <1539092351.3163513.1535891128.20DDCB34@webmail.messagingengine.com> From: Daniel Shahaf To: Peter Stephenson , zsh-workers@zsh.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-148552aa References: <20181009084918eucas1p27dedda10d51beb773ba9175967912d2c~b5IUtvcVK3037630376eucas1p2R@eucas1p2.samsung.com> <205ea5e4-4dc9-2ebf-9437-0822195e1a9a@inlv.org> <20181009131646eucas1p2eb07d8fa34e97de25db60d6a56c584a4~b8x2n0O1S2407324073eucas1p2z@eucas1p2.samsung.com> Date: Tue, 09 Oct 2018 13:39:11 +0000 In-Reply-To: <20181009131646eucas1p2eb07d8fa34e97de25db60d6a56c584a4~b8x2n0O1S2407324073eucas1p2z@eucas1p2.samsung.com> Subject: Re: [Bug] Exiting shell from function called by trap handler always produces status 0 Peter Stephenson wrote on Tue, 09 Oct 2018 14:16 +0100: > +++ b/Src/builtin.c > @@ -5698,6 +5699,42 @@ checkjobs(void) > +/* > + * Exit status if explicitly set by an exit command. > + * This is complicated by the fact the exit command may be within > + * a function whose state we need to unwind (exit_pending set > + * and the exit will happen up the stack), or we may need to execute > + * additional code such as a trap after we are committed to exiting > + * (shell_exiting and the exit will happen down the stack). > + * > + * It's lucky this is all so obvious there is no possibility of any > + * bugs. (C.f. the entire rest of the shell.) > + */ > +/**/ > +int exit_val; Shouldn't this variable be initialized? A function-local 'static' (below) is implicitly initialized to 0, but a non-static global is not implicitly initialized. > + > +/* > + * Actually exit the shell, working out the status locally. > + * This is exit_val if "exit" has explicitly been called in the shell, > + * else lastval. > + */ > + > @@ -5709,7 +5746,6 @@ int shell_exiting; > mod_export void > zexit(int val, int from_where) > { > - static int exit_val; > /* > * Don't do anything recursively: see below. > * Do, however, update exit status --- there's no nesting,