Re: [PATCH] clear_traps: reset savestatus

2018-11-29 Thread Martijn Dekker
Op 29-11-18 om 21:39 schreef Harald van Dijk: By the way, my change has an unintended but possibly acceptable side effect:   trap '(trap "echo exit" EXIT; :)' EXIT This prints nothing with current dash, but prints "exit" with my change. It also prints "exit" in ksh, mksh, posh, and bosh. I

Re: [PATCH] clear_traps: reset savestatus

2018-11-29 Thread Harald van Dijk
On 29/11/2018 20:28, Martijn Dekker wrote: Op 29-11-18 om 20:56 schreef Harald van Dijk: That's part of it, but not the whole story. Herbert Xu's comment about exitshell() was right, that is still a problem. A testcase for this is    trap '(true) || echo bug' EXIT Yes. Thanks. I hadn't thoug

Re: [PATCH] clear_traps: reset savestatus

2018-11-29 Thread Martijn Dekker
Op 29-11-18 om 20:56 schreef Harald van Dijk: That's part of it, but not the whole story. Herbert Xu's comment about exitshell() was right, that is still a problem. A testcase for this is   trap '(true) || echo bug' EXIT Yes. Thanks. I hadn't thought about that. The test case above is not q

Re: [PATCH] clear_traps: reset savestatus

2018-11-29 Thread Harald van Dijk
On 29/11/2018 15:45, Martijn Dekker wrote: Op 27-11-18 om 17:24 schreef Martijn Dekker: Big bad bug: it appears that subshells always return status 0 in traps. As posted elsewhere, looks like the problem is simply that savestatus ("/* exit status of last command outside traps */") isn't reset

[PATCH] clear_traps: reset savestatus

2018-11-29 Thread Martijn Dekker
Op 27-11-18 om 17:24 schreef Martijn Dekker: Big bad bug: it appears that subshells always return status 0 in traps. As posted elsewhere, looks like the problem is simply that savestatus ("/* exit status of last command outside traps */") isn't reset to -1 upon resetting traps when forking a

Re: [BUG] exit status of subshells in traps is always 0

2018-11-29 Thread Martijn Dekker
Op 27-11-18 om 17:24 schreef Martijn Dekker: Big bad bug: it appears that subshells always return status 0 in traps. Bug found in dash 0.5.9 and later. In fact, the bug exists on at least dash 0.5.6 and possibly earlier (earlier versions don't compile for me) if the exit occurs due to a fail

Re: eval: Only restore exit status on exit/return

2018-11-29 Thread Martijn Dekker
Op 29-11-18 om 15:48 schreef Herbert Xu: The problem is that in evalsubshell we end up in exitshell again which restores the old exit status. So we need to come up with a way to differentiate the exitshell from the original shell vs. a subshell. Isn't it much simpler than that? Upon forking a

Re: eval: Only restore exit status on exit/return

2018-11-29 Thread Herbert Xu
On Thu, Nov 29, 2018 at 03:27:31PM +0100, Martijn Dekker wrote: > Op 29-11-18 om 12:33 schreef Herbert Xu: > > Thanks for the report. This patch should fix the problem: > > Doesn't work for me, in fact it seems to make no difference. > > Here are a few more test cases. > > (trap '(! :) && echo

Re: eval: Only restore exit status on exit/return

2018-11-29 Thread Martijn Dekker
Op 29-11-18 om 12:33 schreef Herbert Xu: Thanks for the report. This patch should fix the problem: Doesn't work for me, in fact it seems to make no difference. Here are a few more test cases. (trap '(! :) && echo BUG1' EXIT) (trap '(false) && echo BUG2' EXIT) (trap 'readonly foo=bar; (foo=ba

eval: Only restore exit status on exit/return

2018-11-29 Thread Herbert Xu
Martijn Dekker wrote: > Big bad bug: it appears that subshells always return status 0 in traps. > > Bug found in dash 0.5.9 and later. > > $ src/dash -c 'trap "(false) && echo BUG" INT; kill -s INT $$' > BUG > $ src/dash -c 'trap "(false) && echo BUG" EXIT' > BUG > $ src/dash -c 'trap "(false);