summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2010-03-23 15:33:43 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2010-03-30 12:51:44 +0200
commit2477fb12e9960a410a53ac125e2b43b0d8e1d7b6 (patch)
tree95d1a8a26f97c26f03b311f14355d951ddba0de8
parentc46c96b0cd96b020cd9b304361b1b1c94e776910 (diff)
downloadbarebox-2477fb12e9960a410a53ac125e2b43b0d8e1d7b6.tar.gz
barebox-2477fb12e9960a410a53ac125e2b43b0d8e1d7b6.tar.xz
hush: Fix return code when calling 'exit' inside loops
v2: Do not exit from all scripts but only the current one This fixes the case: barebox:/ cat /test if [ 0 = 0 ]; then exit 1 fi barebox:/ /test barebox:/ echo $? 0 barebox:/ Also, remove code to not allow exit from main shell. The for(;;) loop in common/startup.c will bring us back anyway. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/hush.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/common/hush.c b/common/hush.c
index cf6704be..6a8b56be 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -699,7 +699,7 @@ static int run_list_real(struct pipe *pi)
debug("run_pipe_real returned %d\n",rcode);
if (rcode < -1) {
last_return_code = -rcode - 2;
- return -2; /* exit */
+ return rcode; /* exit */
}
last_return_code=rcode;
if ( rmode == RES_IF || rmode == RES_ELIF )
@@ -1371,17 +1371,9 @@ static int parse_stream_outer(struct p_context *ctx, struct in_str *inp, int fla
free_pipe_list(ctx->list_head, 0);
continue;
}
- if (code == -2) { /* exit */
+ if (code < -1) { /* exit */
b_free(&temp);
-
- /* XXX hackish way to not allow exit from main loop */
- if (inp->peek == file_peek) {
- printf("exit not allowed from main input shell.\n");
- code = 0;
- continue;
- }
- code = last_return_code;
- break;
+ return -code - 2;
}
} else {
if (ctx->old_flag != 0) {