aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-06 18:40:31 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-06 18:40:31 +0000
commit0e15138c03db5ac6b68ac24a074bf1c1532cbe1e (patch)
tree0f8806b8ebc01be3fe33541c01864655bb6c6f3b /shell
parent4ed67dd3d5a042470c6bc04723c2a0a37ca072b7 (diff)
downloadbusybox-w32-0e15138c03db5ac6b68ac24a074bf1c1532cbe1e.tar.gz
busybox-w32-0e15138c03db5ac6b68ac24a074bf1c1532cbe1e.tar.bz2
busybox-w32-0e15138c03db5ac6b68ac24a074bf1c1532cbe1e.zip
hush: fix "if false; then...fi" exitcode;
trim "keyword"-less hush by 10 bytes
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c13
-rw-r--r--shell/hush_test/hush-misc/if_false_exitcode.right1
-rwxr-xr-xshell/hush_test/hush-misc/if_false_exitcode.tests2
3 files changed, 12 insertions, 4 deletions
diff --git a/shell/hush.c b/shell/hush.c
index c74d10c1b..c563cfe33 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3038,8 +3038,10 @@ static int run_list(struct pipe *pi)
3038#else 3038#else
3039 enum { cond_code = 0 }; 3039 enum { cond_code = 0 };
3040#endif 3040#endif
3041#if HAS_KEYWORDS
3041 smallint rword; /* enum reserved_style */ 3042 smallint rword; /* enum reserved_style */
3042 smallint last_rword; /* ditto */ 3043 smallint last_rword; /* ditto */
3044#endif
3043 3045
3044 debug_printf_exec("run_list start lvl %d\n", G.run_list_level + 1); 3046 debug_printf_exec("run_list start lvl %d\n", G.run_list_level + 1);
3045 3047
@@ -3118,10 +3120,12 @@ static int run_list(struct pipe *pi)
3118 } 3120 }
3119#endif /* JOB */ 3121#endif /* JOB */
3120 3122
3121 rcode = G.last_return_code; 3123#if HAS_KEYWORDS
3122 rword = RES_NONE; 3124 rword = RES_NONE;
3123 last_rword = RES_XXXX; 3125 last_rword = RES_XXXX;
3126#endif
3124 last_followup = PIPE_SEQ; 3127 last_followup = PIPE_SEQ;
3128 rcode = G.last_return_code;
3125 3129
3126 /* Go through list of pipes, (maybe) executing them. */ 3130 /* Go through list of pipes, (maybe) executing them. */
3127 for (; pi; pi = USE_HUSH_LOOPS(rword == RES_DONE ? loop_top : ) pi->next) { 3131 for (; pi; pi = USE_HUSH_LOOPS(rword == RES_DONE ? loop_top : ) pi->next) {
@@ -3129,7 +3133,6 @@ static int run_list(struct pipe *pi)
3129 break; 3133 break;
3130 3134
3131 IF_HAS_KEYWORDS(rword = pi->res_word;) 3135 IF_HAS_KEYWORDS(rword = pi->res_word;)
3132 IF_HAS_NO_KEYWORDS(rword = RES_NONE;)
3133 debug_printf_exec(": rword=%d cond_code=%d last_rword=%d\n", 3136 debug_printf_exec(": rword=%d cond_code=%d last_rword=%d\n",
3134 rword, cond_code, last_rword); 3137 rword, cond_code, last_rword);
3135#if ENABLE_HUSH_LOOPS 3138#if ENABLE_HUSH_LOOPS
@@ -3142,7 +3145,7 @@ static int run_list(struct pipe *pi)
3142 } 3145 }
3143#endif 3146#endif
3144 /* Still in the same "if...", "then..." or "do..." branch? */ 3147 /* Still in the same "if...", "then..." or "do..." branch? */
3145 if (rword == last_rword) { 3148 if (IF_HAS_KEYWORDS(rword == last_rword &&) 1) {
3146 if ((rcode == 0 && last_followup == PIPE_OR) 3149 if ((rcode == 0 && last_followup == PIPE_OR)
3147 || (rcode != 0 && last_followup == PIPE_AND) 3150 || (rcode != 0 && last_followup == PIPE_AND)
3148 ) { 3151 ) {
@@ -3154,10 +3157,12 @@ static int run_list(struct pipe *pi)
3154 } 3157 }
3155 } 3158 }
3156 last_followup = pi->followup; 3159 last_followup = pi->followup;
3157 last_rword = rword; 3160 IF_HAS_KEYWORDS(last_rword = rword;)
3158#if ENABLE_HUSH_IF 3161#if ENABLE_HUSH_IF
3159 if (cond_code) { 3162 if (cond_code) {
3160 if (rword == RES_THEN) { 3163 if (rword == RES_THEN) {
3164 /* if false; then ... fi has exitcode 0! */
3165 G.last_return_code = rcode = EXIT_SUCCESS;
3161 /* "if <false> THEN cmd": skip cmd */ 3166 /* "if <false> THEN cmd": skip cmd */
3162 continue; 3167 continue;
3163 } 3168 }
diff --git a/shell/hush_test/hush-misc/if_false_exitcode.right b/shell/hush_test/hush-misc/if_false_exitcode.right
new file mode 100644
index 000000000..7b24a35ff
--- /dev/null
+++ b/shell/hush_test/hush-misc/if_false_exitcode.right
@@ -0,0 +1 @@
Ok:0
diff --git a/shell/hush_test/hush-misc/if_false_exitcode.tests b/shell/hush_test/hush-misc/if_false_exitcode.tests
new file mode 100755
index 000000000..01b36b100
--- /dev/null
+++ b/shell/hush_test/hush-misc/if_false_exitcode.tests
@@ -0,0 +1,2 @@
1if false; then echo Bad; fi
2echo Ok:$?