EXIT trap handling in subshells broken

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

 



Hi,

dash unwinds too far before running EXIT handlers, causing e.g. redirections to be dropped in subshells when those subshells should have no way of dropping them.

  eval '(trap "echo bug" EXIT)' >/dev/null

The problem is easy enough to see: EV_EXIT causes longjmp() all the way back to main(), even from within the subshell, and all redirections will dropped regardless of whether they were created in the parent shell or the subshell.

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.

One way to fix this is to install an exception handler in evaltree(nr) to prevent exceptions bubbling up too far. It can just call exitshell() from there. It is not clear to me yet whether this is the best way.

Cheers,
Harald van Dijk



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

  Powered by Linux