zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Peter Stephenson <p.stephenson@samsung.com>, zsh-workers@zsh.org
Subject: Re: [Bug] Exiting shell from function called by trap handler always produces status 0
Date: Tue, 09 Oct 2018 13:39:11 +0000	[thread overview]
Message-ID: <1539092351.3163513.1535891128.20DDCB34@webmail.messagingengine.com> (raw)
In-Reply-To: <20181009131646eucas1p2eb07d8fa34e97de25db60d6a56c584a4~b8x2n0O1S2407324073eucas1p2z@eucas1p2.samsung.com>

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,

  reply	other threads:[~2018-10-09 13:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20181009012624epcas1p44f2ae223f663713a980af4be735e5a3f@epcas1p4.samsung.com>
2018-10-08 13:02 ` Martijn Dekker
2018-10-09  8:49   ` Peter Stephenson
2018-10-09  9:58     ` Mikael Magnusson
2018-10-09 11:46     ` Martijn Dekker
2018-10-09 13:16       ` Peter Stephenson
2018-10-09 13:39         ` Daniel Shahaf [this message]
2018-10-09 13:43           ` Peter Stephenson
     [not found]           ` <1539092591.3286.12.camel@samsung.com>
2018-10-09 13:50             ` Peter Stephenson
2018-10-09 20:09         ` Peter Stephenson
2018-10-10  8:56           ` Daniel Shahaf
2018-10-10  9:31             ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1539092351.3163513.1535891128.20DDCB34@webmail.messagingengine.com \
    --to=d.s@daniel.shahaf.name \
    --cc=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).