Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

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,



Messages sorted by: Reverse Date, Date, Thread, Author