On Sun, Sep 5, 2021 at 5:53 PM Roberto A. Foglietta
<[email protected]> wrote:
> Il giorno dom 5 set 2021 alle ore 17:03 Denys Vlasenko
> <[email protected]> ha scritto:
>
> > @@ -468,7 +470,11 @@ struct globals_misc {
> > /* indicates specified signal received */
> > uint8_t gotsig[NSIG - 1]; /* offset by 1: "signal" 0 is meaningless
> > */
> > uint8_t may_have_traps; /* 0: definitely no traps are set, 1: some
> > traps may be set */
> > - char *trap[NSIG];
> > + char *trap[NSIG + 1];
> > +/* trap[0] is EXIT trap, trap[NTRAP_ERR] is ERR trap, other trap[i] are
> > signal traps */
> > +#define NTRAP_ERR NSIG
> > +#define NTRAP_LAST NSIG
>
> If NTRAP_LAST is defined as NSIG + 1 then char *trap[NSIG + 1]; could
> become trap[NTRAP_LAST].
If NTRAP_LAST is defined as NSIG + 1, then its name would be lying to people
reading the code: it says "the last trap number", but it would actually mean
"the number of existing traps".
> > @@ -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?
> For sure the first one is needed to have exitshell().
All LINENO problems are to be fixed in a separate patch -
IIRC you want to fix other LINENO problems anyway,
like incorrect handling of it in functions?
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox