zsh-workers
 help / color / mirror / code / Atom feed
* [BUG] Sticky-sh POSIX_TRAPS are function-local
@ 2016-02-15  5:11 Martijn Dekker
  2016-02-16  9:57 ` Peter Stephenson
  0 siblings, 1 reply; 12+ messages in thread
From: Martijn Dekker @ 2016-02-15  5:11 UTC (permalink / raw)
  To: zsh-workers

The POSIX_TRAPS option for the EXIT trap does not work if both of the
following conditions apply:

- zsh was launched as zsh, not sh
- the EXIT trap is set from a shell function with sticky sh emulation

Script showing the bug (on zsh-5.2-142-gac5d83b):

	#! /bin/zsh
	echo start program
	emulate sh -c 'testfn() {
	        echo start function
		set -o | grep posixtraps
		trap "echo EXIT TRAP TRIGGERED" EXIT
		echo end function
	}'
	testfn
	echo program continuing
	echo end of program

Actual output:

	start program
	start function
	noposixtraps          off
	end function
	EXIT TRAP TRIGGERED
	program continuing
	end of program

Expected output:

	start program
	start function
	noposixtraps          off
	end function
	program continuing
	end of program
	EXIT TRAP TRIGGERED

Note how the EXIT trap is triggered upon exit from the function that set
it, and not upon exit from the shell, even though 'emulate sh' should
activate POSIX_TRAPS so the function should have set a global trap.

Thanks,

- M.

(How I found this bug: my cross-platform shell library, modernish
<https://github.com/modernish/modernish>, can be used with native zsh
with the command
   emulate sh -c '. modernish'
Sticky sh emulation is fantastic: the library's features mix in
seamlessly with native zsh, even the crazy alias-based ones such as the
new loop constructs. The only thing that is *not* working are the
functions that set EXIT traps, i.e.. 'pushtrap' -- stack-based traps, so
modernish modules can set their own clean-up traps without interfering
with others. On native zsh with modernish in sticky sh emulation, those
get executed instantly upon setting them.)


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

end of thread, other threads:[~2016-03-04 18:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-15  5:11 [BUG] Sticky-sh POSIX_TRAPS are function-local Martijn Dekker
2016-02-16  9:57 ` Peter Stephenson
2016-02-16 12:46   ` Peter Stephenson
2016-02-16 23:38   ` Martijn Dekker
2016-02-17  4:25     ` Bart Schaefer
2016-02-17  5:24       ` Martijn Dekker
2016-02-19 18:59         ` Bart Schaefer
2016-02-17 10:36     ` Peter Stephenson
2016-02-25 11:53     ` Peter Stephenson
2016-02-25 13:52       ` Martijn Dekker
2016-02-25 14:17         ` Peter Stephenson
2016-03-04 18:02         ` Peter Stephenson

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).