Re: [v2 PATCH] eval: Only restore exit status on exit/return

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

 



On 02/12/2018 14:53, Herbert Xu wrote:
On Sat, Dec 01, 2018 at 04:45:39PM +0800, Herbert Xu wrote:
Hmm, I think this breaks the following case which used to work:

	dash -c 'trap "(:; exit) && echo BUG" EXIT; false'

I know this makes no sense but almost every other shell does it
this way.

FWIW, I read this as you saying the behaviour is clearly wrong, and other shells doing it this way is the *only* reason you want to preserve it. This is contradicted by you in your reply to my other message, but I do not see how else to interpret this sentence.

Here is a new patch that fixes the reported issue for both signal
traps and the EXIT trap.

This has the benefit of fixing one other test case, a small modification from one of Martijn Dekker's:

  $SHELL -c 'trap "set -o bad@option" INT; kill -s INT $$' && echo BUG

Although the shell exited on the invalid option, it still reset the exit status to 0 because a trap handler was started, so BUG is printed. ksh is the only other shell I found to also print BUG.

In this test case, execution never reaches clear_traps() since no subshell is started. Any changes made there therefore cannot have any effect. Some other approach is needed. Distinguishing between the different ways of exiting like you're doing here does manage to get this right.

Still feels like it's more complicated than it should be though.



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

  Powered by Linux