[PATCH] shell script error management in ash (ready for integration)
Roberto A. Foglietta
roberto.foglietta at gmail.com
Sat Sep 4 18:39:05 UTC 2021
Il giorno sab 4 set 2021 alle ore 16:36 Denys Vlasenko <
vda.linux at googlemail.com> ha scritto:
> On Mon, Aug 30, 2021 at 8:55 AM Roberto A. Foglietta
> <roberto.foglietta at gmail.com> wrote:
> > Hi Denis,
> >
> > supported by the experience of Harald, I developed this patch far
> enough to be ready for integration. These are the features that will add to
> busybox ash:
> >
> > - trap ERR and set -E added
> > - global FUNCNAME added
> > - LINENO became global
>
> Can this be reasonably split up, or it is too interrelated?
> E.g. add FUNCNAME in a separate patch?
> Add set -E in a separate patch?
>
They are interrelated but there is a more specific reason to maintain then
all together:
- trap ERR requires set -E to let functions inherit the trap
- global LINENO requires global FUNCNAME because functions might be
sourced by a file
Moreover, who uses trap ERR does it because s/he wants to be acknowledged
of any error otherwise s/he would use set -e.
Being acknowledged for error requires LINENO and FUNCNAME thus all these
functionalities achieve a higher level goal: error management/debug in
shell scripting.
With this patch busybox ash became more precise and informative than bash,
so it is the optimal environment to test/debug complex shell scripts.
AFAIK, every script that runs on patched busybox ash could run smoothly in
bash as well but not vice versa.
Thus patched busybox ash became a development/debug tool, also.
Under these points of view a single patch seems the most rational way to
go and it is simpler.
> > The patch is in attachment with its test suite.
>
> Can you git send-email the patches?
>
Uhm, I will try it. After all it is just a matter of using a tool instead
of another.
In this email, I am going to answer raised questions and thereafter I will
improve the patch with the suggestions received ASAP.
> #define linenovar (G_var.linenovar )
> +#define funcnamevar (G_var.funcnamevar )
> +#define funcname (G_var.funcname )
> +#define doingtrap (G_var.doingtrap )
>
> Inconsistent whitespace
>
I am confused because the image inlined here below shows that they are
correctly aligned with a fixed font text editor.
[image: image.png]
What does doingtrap do? Inhibits line counting?
> In this case, you don't need to save/restore lineno?
>
Nope, save/restoring lineno is done elsewhere only when required.
It is enough to not change the lineno during the evaluation of a trap.
> It seems you can replace the above save/restore of doingtrap
> if you change it from bool to counter?
>
The boolean doingtrap = 1 avoids lineno increasing inside ANY traps.
It does a single thing in the simplest way and this is enough for every
case.
> "static bool recursive" functionality can be achieved if you
> temporarily set trap[NTRAP_ERR] to NULL while running it.
>
Unless the trap ERR sets a trap ERR and then fails.
The recursive boolean could not be changed by shell script.
So, it is intrinsically reliable.
> A wider concern is that dash development has become reasonably active
> and we need to backport fixes from dash. This means that divergent
> development in our code creates future problems.
>
> Please ask on dash mailing list whether they are willing to take
> patches implementing trap "ERR".
>
As soon as the patch will be ready to be integrated here, I will ask them
to evaluate it.
http://gondor.apana.org.au/~herbert/dash/
Thank you for your answer,
--
Roberto A. Foglietta
+39.349.33.30.697
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210904/cd5e38a4/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 26091 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210904/cd5e38a4/attachment-0001.png>
More information about the busybox
mailing list