zsh-workers
 help / color / mirror / Atom feed
* exit does not exit in traps triggered within functions
@ 2020-10-25 20:19 Michaël Cadilhac
  2020-10-25 20:56 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Michaël Cadilhac @ 2020-10-25 20:19 UTC (permalink / raw)
  To: zsh-workers

Hello,

Users at Unix.StackExchange suggested that I forward a question of
mine appearing here [1], as a potential bug.

Consider these two examples, the second contributed by Stéphane Chazelas:

$ zsh -c 'trap "exit 1; echo X" TERM; f() { kill -TERM $$; echo Y; }; f'
Y
$ zsh -c 'trap "exit 1; echo X" EXIT; f() { exit;          echo Y; }; f'
X

In the first case, the exit in the trap causes the trap to end, but
f() continues executing—but does not return.  The return value of the
program is 1.

In the second case, the exit in the trap does not cause the trap to
end immediately, the trap finishes and does not return, and the return
value of the program is 0.

As far as I understand, the expected behavior, which BASH displays, is
for these two scripts to print nothing.

Tested on zsh 5.5.1 and 5.8.

Thanks.

1: https://unix.stackexchange.com/questions/616217/why-does-zsh-finish-executing-a-function-after-exit-was-called-from-a-trap


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: exit does not exit in traps triggered within functions
  2020-10-25 20:19 exit does not exit in traps triggered within functions Michaël Cadilhac
@ 2020-10-25 20:56 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2020-10-25 20:56 UTC (permalink / raw)
  To: Michaël Cadilhac; +Cc: zsh-workers

This was previously discussed in the thread "Bug with traps and exit"
which started in January 2019 and proceeded sporadically through
January 2020.

There was discussion of regression tests but no patch proposed, as far
as I can tell.

On Sun, Oct 25, 2020 at 1:20 PM Michaël Cadilhac <michael@cadilhac.name> wrote:
>
> Hello,
>
> Users at Unix.StackExchange suggested that I forward a question of
> mine appearing here [1], as a potential bug.
>
> Consider these two examples, the second contributed by Stéphane Chazelas:
>
> $ zsh -c 'trap "exit 1; echo X" TERM; f() { kill -TERM $$; echo Y; }; f'
> Y
> $ zsh -c 'trap "exit 1; echo X" EXIT; f() { exit;          echo Y; }; f'
> X
>
> In the first case, the exit in the trap causes the trap to end, but
> f() continues executing—but does not return.  The return value of the
> program is 1.
>
> In the second case, the exit in the trap does not cause the trap to
> end immediately, the trap finishes and does not return, and the return
> value of the program is 0.
>
> As far as I understand, the expected behavior, which BASH displays, is
> for these two scripts to print nothing.
>
> Tested on zsh 5.5.1 and 5.8.
>
> Thanks.
>
> 1: https://unix.stackexchange.com/questions/616217/why-does-zsh-finish-executing-a-function-after-exit-was-called-from-a-trap
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-25 20:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-25 20:19 exit does not exit in traps triggered within functions Michaël Cadilhac
2020-10-25 20:56 ` Bart Schaefer

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git