Re: EXIT trap handling in subshells broken

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 17/01/2020 10:15, Herbert Xu wrote:
On Mon, Jan 06, 2020 at 09:57:20PM +0000, Harald van Dijk wrote:

The problem is not limited to redirections:

   f() { (trap "echo \$var" EXIT); }
   var=bad
   var=ok f

This prints "bad", when it should print "ok". Here, the local variable is
dropped not in main(), but during the unwind process.

This works fine for me with the latest git tree.  This is because
reset has now been split into exitreset and reset and variables
are only reset in reset() which is only called if exitshell is
not happening.

As if we're in a subshell we will never take the reset() path
I don't think we need to do anything here at all.

Ah, right, forgot about that. That change also altered the behaviour of

  trap "echo foo=\$foo" EXIT
  f() {
    local foo=bar
    exit
  }
  f

though, which printed foo= in released versions of dash since at least as far back as 0.5.1, and prints foo= in current versions of bash and zsh. It now prints foo=bar. That is defensible and also what some other shells do, but I'm not sure it's intended.

(Combined with some other changes I have, the behaviour stops being defensible, but I suspect that is nothing that affects dash.)

Cheers,
Harald van Dijk



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux