diff options
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/shell/ash.c b/shell/ash.c index f1f044cbf..45ec13097 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -5766,25 +5766,17 @@ redirectsafe(union node *redir, int flags) | |||
5766 | static arith_t | 5766 | static arith_t |
5767 | ash_arith(const char *s) | 5767 | ash_arith(const char *s) |
5768 | { | 5768 | { |
5769 | arith_eval_hooks_t math_hooks; | 5769 | arith_state_t math_state; |
5770 | arith_t result; | 5770 | arith_t result; |
5771 | int errcode = 0; | ||
5772 | 5771 | ||
5773 | math_hooks.lookupvar = lookupvar; | 5772 | math_state.lookupvar = lookupvar; |
5774 | math_hooks.setvar = setvar2; | 5773 | math_state.setvar = setvar2; |
5775 | //math_hooks.endofname = endofname; | 5774 | //math_state.endofname = endofname; |
5776 | 5775 | ||
5777 | INT_OFF; | 5776 | INT_OFF; |
5778 | result = arith(s, &errcode, &math_hooks); | 5777 | result = arith(&math_state, s); |
5779 | if (errcode < 0) { | 5778 | if (math_state.errmsg) |
5780 | if (errcode == -3) | 5779 | ash_msg_and_raise_error(math_state.errmsg); |
5781 | ash_msg_and_raise_error("exponent less than 0"); | ||
5782 | if (errcode == -2) | ||
5783 | ash_msg_and_raise_error("divide by zero"); | ||
5784 | if (errcode == -5) | ||
5785 | ash_msg_and_raise_error("expression recursion loop detected"); | ||
5786 | raise_error_syntax(s); | ||
5787 | } | ||
5788 | INT_ON; | 5780 | INT_ON; |
5789 | 5781 | ||
5790 | return result; | 5782 | return result; |
@@ -5848,7 +5840,7 @@ cvtnum(arith_t num) | |||
5848 | int len; | 5840 | int len; |
5849 | 5841 | ||
5850 | expdest = makestrspace(32, expdest); | 5842 | expdest = makestrspace(32, expdest); |
5851 | len = fmtstr(expdest, 32, arith_t_fmt, num); | 5843 | len = fmtstr(expdest, 32, ARITH_FMT, num); |
5852 | STADJUST(len, expdest); | 5844 | STADJUST(len, expdest); |
5853 | return len; | 5845 | return len; |
5854 | } | 5846 | } |
@@ -8624,7 +8616,7 @@ static int evalstring(char *s, int mask); | |||
8624 | 8616 | ||
8625 | /* Called to execute a trap. | 8617 | /* Called to execute a trap. |
8626 | * Single callsite - at the end of evaltree(). | 8618 | * Single callsite - at the end of evaltree(). |
8627 | * If we return non-zero, exaltree raises EXEXIT exception. | 8619 | * If we return non-zero, evaltree raises EXEXIT exception. |
8628 | * | 8620 | * |
8629 | * Perhaps we should avoid entering new trap handlers | 8621 | * Perhaps we should avoid entering new trap handlers |
8630 | * while we are executing a trap handler. [is it a TODO?] | 8622 | * while we are executing a trap handler. [is it a TODO?] |
@@ -8814,11 +8806,15 @@ evaltree(union node *n, int flags) | |||
8814 | 8806 | ||
8815 | out: | 8807 | out: |
8816 | exception_handler = savehandler; | 8808 | exception_handler = savehandler; |
8809 | |||
8817 | out1: | 8810 | out1: |
8811 | /* Order of checks below is important: | ||
8812 | * signal handlers trigger before exit caused by "set -e". | ||
8813 | */ | ||
8814 | if (pending_sig && dotrap()) | ||
8815 | goto exexit; | ||
8818 | if (checkexit & exitstatus) | 8816 | if (checkexit & exitstatus) |
8819 | evalskip |= SKIPEVAL; | 8817 | evalskip |= SKIPEVAL; |
8820 | else if (pending_sig && dotrap()) | ||
8821 | goto exexit; | ||
8822 | 8818 | ||
8823 | if (flags & EV_EXIT) { | 8819 | if (flags & EV_EXIT) { |
8824 | exexit: | 8820 | exexit: |
@@ -9212,7 +9208,7 @@ poplocalvars(void) | |||
9212 | while ((lvp = localvars) != NULL) { | 9208 | while ((lvp = localvars) != NULL) { |
9213 | localvars = lvp->next; | 9209 | localvars = lvp->next; |
9214 | vp = lvp->vp; | 9210 | vp = lvp->vp; |
9215 | TRACE(("poplocalvar %s\n", vp ? vp->text : "-")); | 9211 | TRACE(("poplocalvar %s\n", vp ? vp->var_text : "-")); |
9216 | if (vp == NULL) { /* $- saved */ | 9212 | if (vp == NULL) { /* $- saved */ |
9217 | memcpy(optlist, lvp->text, sizeof(optlist)); | 9213 | memcpy(optlist, lvp->text, sizeof(optlist)); |
9218 | free((char*)lvp->text); | 9214 | free((char*)lvp->text); |
@@ -13383,7 +13379,7 @@ init(void) | |||
13383 | /* bash re-enables SIGHUP which is SIG_IGNed on entry. | 13379 | /* bash re-enables SIGHUP which is SIG_IGNed on entry. |
13384 | * Try: "trap '' HUP; bash; echo RET" and type "kill -HUP $$" | 13380 | * Try: "trap '' HUP; bash; echo RET" and type "kill -HUP $$" |
13385 | */ | 13381 | */ |
13386 | signal(SIGHUP, SIG_DFL); | 13382 | signal(SIGHUP, SIG_DFL); |
13387 | 13383 | ||
13388 | /* from var.c: */ | 13384 | /* from var.c: */ |
13389 | { | 13385 | { |
@@ -13598,10 +13594,12 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
13598 | if (e == EXERROR) | 13594 | if (e == EXERROR) |
13599 | exitstatus = 2; | 13595 | exitstatus = 2; |
13600 | s = state; | 13596 | s = state; |
13601 | if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) | 13597 | if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) { |
13602 | exitshell(); | 13598 | exitshell(); |
13603 | if (e == EXINT) | 13599 | } |
13600 | if (e == EXINT) { | ||
13604 | outcslow('\n', stderr); | 13601 | outcslow('\n', stderr); |
13602 | } | ||
13605 | 13603 | ||
13606 | popstackmark(&smark); | 13604 | popstackmark(&smark); |
13607 | FORCE_INT_ON; /* enable interrupts */ | 13605 | FORCE_INT_ON; /* enable interrupts */ |
@@ -13705,6 +13703,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
13705 | _mcleanup(); | 13703 | _mcleanup(); |
13706 | } | 13704 | } |
13707 | #endif | 13705 | #endif |
13706 | TRACE(("End of main reached\n")); | ||
13708 | exitshell(); | 13707 | exitshell(); |
13709 | /* NOTREACHED */ | 13708 | /* NOTREACHED */ |
13710 | } | 13709 | } |