From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 419 invoked by alias); 15 Feb 2016 05:35:18 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37977 Received: (qmail 23794 invoked from network); 15 Feb 2016 05:11:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 Message-ID: <56C15DF1.8080405@inlv.org> Date: Mon, 15 Feb 2016 06:11:13 +0100 From: Martijn Dekker User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: zsh-workers@zsh.org Subject: [BUG] Sticky-sh POSIX_TRAPS are function-local Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit 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 , 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.)