mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] hush: Fix return code when calling 'exit' inside loops
@ 2010-03-24  7:25 Sascha Hauer
  2010-03-24 11:35 ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2010-03-24  7:25 UTC (permalink / raw)
  To: barebox




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>
---
 common/hush.c |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/common/hush.c b/common/hush.c
index cf6704b..5459224 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;
 			}
 		} else {
 			if (ctx->old_flag != 0) {
-- 
1.7.0

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hush: Fix return code when calling 'exit' inside loops
  2010-03-24  7:25 [PATCH] hush: Fix return code when calling 'exit' inside loops Sascha Hauer
@ 2010-03-24 11:35 ` Sascha Hauer
  2010-03-26 14:54   ` Jan Weitzel
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2010-03-24 11:35 UTC (permalink / raw)
  To: barebox


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>
---
 common/hush.c |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/common/hush.c b/common/hush.c
index cf6704b..6a8b56b 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) {
-- 
1.7.0

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hush: Fix return code when calling 'exit' inside loops
  2010-03-24 11:35 ` Sascha Hauer
@ 2010-03-26 14:54   ` Jan Weitzel
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Weitzel @ 2010-03-26 14:54 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

works fine

Am Mittwoch, den 24.03.2010, 12:35 +0100 schrieb Sascha Hauer:
> 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>
> ---
>  common/hush.c |   14 +++-----------
>  1 files changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/common/hush.c b/common/hush.c
> index cf6704b..6a8b56b 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) {
> -- 
> 1.7.0
> 



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-26 14:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-24  7:25 [PATCH] hush: Fix return code when calling 'exit' inside loops Sascha Hauer
2010-03-24 11:35 ` Sascha Hauer
2010-03-26 14:54   ` Jan Weitzel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox