diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2014-10-06 21:51:26 +0800 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2014-10-06 21:51:26 +0800 |
commit | 70c16dd30d4cf824aa895e9f6c095fec741c65a8 (patch) | |
tree | 6b0057c3ab08a4eafbf477d6e6ea412e9b807ee0 /src/eval.c | |
parent | [BUILTIN] Allow return in loop conditional to set exit status (diff) | |
download | dash-70c16dd30d4cf824aa895e9f6c095fec741c65a8.tar.gz dash-70c16dd30d4cf824aa895e9f6c095fec741c65a8.zip |
[BUILTIN] Return without arguments in a trap should use status outside traps
POSIX now requires that return without arguments in a trap should return the last command status prior to executing traps. This patch implements this behaviour. Incidentally this also changes the behaviour of return without arguments in a loop conditional to use the last exit status in the body as opposed to the last command in the conditional when there is one. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/eval.c b/src/eval.c index 7b341f3..071fb1b 100644 --- a/src/eval.c +++ b/src/eval.c @@ -967,7 +967,7 @@ funcdone: shellparam = saveparam; handler = savehandler; INTON; - evalskip &= ~SKIPFUNC; + evalskip &= ~(SKIPFUNC | SKIPFUNCDEF); return e; } @@ -1047,12 +1047,23 @@ breakcmd(int argc, char **argv) int returncmd(int argc, char **argv) { + int skip; + int status; + /* * If called outside a function, do what ksh does; * skip the rest of the file. */ - evalskip = SKIPFUNC; - return argv[1] ? number(argv[1]) : exitstatus; + if (argv[1]) { + skip = SKIPFUNC; + status = number(argv[1]); + } else { + skip = SKIPFUNCDEF; + status = exitstatus; + } + evalskip = skip; + + return status; } |