[PATCH] shell script error management in ash (set of 6 patches)

Roberto A. Foglietta roberto.foglietta at gmail.com
Sat Aug 21 23:31:16 UTC 2021


Il giorno sab 21 ago 2021 alle ore 23:33 Harald van Dijk <harald at gigawatt.nl>
ha scritto:

> Hi again,
>
> Another bug: the exit status is not preserved.
>
> Consider
>
>    busybox ash -c 'trap "echo ERR" ERR; false; echo $?'
>
> This prints ERR, and then 0, because the echo command completed
> successfully. It is supposed to print ERR, and then 1, because like EXIT
> actions, ERR actions are supposed to preserve the exit status of the
> last command before the action was invoked.
>

Patch 11 and testsuite attached.
In the test suite two cases are evaluated exit status =0 !0

I am also somewhat concerned that there may be cases where the global
> variables "doingtrap" and "recursive" are set, but evalstring() exits
> via raise_exception() and they are never cleared, preventing future ERR
> handlers from running. I do not currently have a test case where it
> matters, but am not convinced there are no test cases where it matters.
>

line 13.320 in evalstring

exception_handler = savehandler;
if (ex)
longjmp(exception_handler->loc, ex);

do you think that this might resolve the issue?

exception_handler = savehandler;
if (ex) {
doingtrap = 0; recursive = 0;
longjmp(exception_handler->loc, ex);
}

Obviously recursive should become a global variable.
When an exception is raised, what is going to happen? Exit?
In case of exit then it is not a problem, IMHO.

Thank you, -R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210822/5cd05d00/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: busybox-1.33.1-11of11-trap-ERR-exist-status-bugfix.patch
Type: application/x-patch
Size: 506 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210822/5cd05d00/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testsuite.tgz
Type: application/gzip
Size: 2241 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210822/5cd05d00/attachment-0001.bin>


More information about the busybox mailing list