On 14/12/2018 09:16, Herbert Xu wrote:
On Fri, Dec 14, 2018 at 08:02:04AM +0000, Harald van Dijk wrote:
On 14/12/2018 03:10, Herbert Xu wrote:
The reason this is needed is to support a naked return. With
your patch a naked return would either have to always return the
saved status or the new status. Neither of which is what we
want.
I actually saw the commit you referenced already and tested that with my
patch before sending. This is how I tested it:
Returns 1:
f() {
false; return
}
f
That's not a naked return. A naked return is one used outside of
a function. I know this is unspecified under POSIX, but for dash
this has a specific meaning and that is the return is equivalent
to exit.
The commit you referred to specifically mentioned changing the behaviour
to conform to POSIX requirements, and now it's actually about an
extension? Still, that works as well, doesn't it? The control flow is
basically the same so the logic in my other message applies. returncmd()
doesn't use exceptions, so you get to dotrap() which already resets
exitstatus if necessary.
Test cases:
Returns 0 (status of previous kill command):
trap "false; return" USR1
kill -USR1 $$
Returns 1 (status specified in return command):
trap "return 1" USR1
kill -USR1 $$
Kills itself with SIGINT (status of cat command) after printing "bye":
trap "echo bye; return" INT
cat; :
<press Ctrl-C>
Or is this about observing return's status in a trap action?
Prints status=0 and exits with status 0:
trap "echo status=\$?; false; exit" EXIT
return
Prints status=1 and exits with status 1:
trap "echo status=\$?; exit" EXIT
return 1