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].
It looks more coherent for me.

> @@ -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.
For sure the first one is needed to have exitshell().

Best regards,
-R
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to