zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: zsh-workers@zsh.org
Subject: [BUG] Sticky-sh POSIX_TRAPS are function-local
Date: Mon, 15 Feb 2016 06:11:13 +0100	[thread overview]
Message-ID: <56C15DF1.8080405@inlv.org> (raw)

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


             reply	other threads:[~2016-02-15  5:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-15  5:11 Martijn Dekker [this message]
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

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=56C15DF1.8080405@inlv.org \
    --to=martijn@inlv.org \
    --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).