[PATCH] ash: add bash-like ERR trap and set -E
Roberto A. Foglietta
roberto.foglietta at gmail.com
Sun Sep 5 21:52:58 UTC 2021
Il giorno dom 5 set 2021 alle ore 21:40 Denys Vlasenko
<vda.linux at googlemail.com> ha scritto:
>
> > > @@ -9395,8 +9407,32 @@ evaltree(union node *n, int flags)
> > > */
> > > dotrap();
> > >
> > > - if (checkexit & status)
> > > - raise_exception(EXEND);
> > > + if (checkexit & status) {
> > > + if (trap[NTRAP_ERR] && !in_trap_ERR) {
> > > + int err;
> > > + struct jmploc *volatile savehandler = exception_handler;
> > > + struct jmploc jmploc;
> > > +
> > > + in_trap_ERR = 1;
> > > + trap_depth++;
> > > + err = setjmp(jmploc.loc);
> > > + if (!err) {
> > > + exception_handler = &jmploc;
> > > + savestatus = exitstatus;
> > > + evalstring(trap[NTRAP_ERR], 0);
> > > + }
> > > + trap_depth--;
> > > + in_trap_ERR = 0;
> > > +
> > > + exception_handler = savehandler;
> > > + if (err && exception_type != EXERROR)
> > > + longjmp(exception_handler->loc, 1);
> > > +
> > > + exitstatus = savestatus;
> > > + }
> > > + if (eflag)
> > > + raise_exception(EXEND);
> > > + }
> > > if (flags & EV_EXIT)
> > > raise_exception(EXEND);
> >
> > if (eflag)
> > exitshell();
> > }
> > if (flags & EV_EXIT)
> > exitshell();
> >
> > Otherwise LINENO is not reported correctly when these exceptions are raised.
>
> Walk me through the mechanism of this failure. You mean that LINENO
> in EXIT trap will be counting incorrectly?
I took my v021 patch and replaced that two exitshell() with raise_exception()
I ran the test suite and it happens that the exit in function returns
the right line number with exitshell() but not with raise_exception().
The right line number should be within the function with FUNCNAME set,
instead I read the right FUNCNAME but the LINENO of the script in
which the function is called.
In attachment the diff file: failures in test 4, 7, A and C.
> > For sure the first one is needed to have exitshell().
>
> All LINENO problems are to be fixed in a separate patch -
ok
> IIRC you want to fix other LINENO problems anyway,
> like incorrect handling of it in functions?
Nope, at the moment all problems are fixed. AFAIK. Patch v021 is my
final one, IMHO.
Unless, you show unacceptable downsides in replacing raise_exception()
with exitshell().
I hope this helps,
--
Roberto A. Foglietta
+39.349.33.30.697
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exit_VS_exce.diff
Type: application/octet-stream
Size: 1508 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210905/6b880b17/attachment.obj>
More information about the busybox
mailing list