svn commit: [25954] trunk/busybox/shell

vda at busybox.net vda at busybox.net
Sat Apr 4 23:15:14 UTC 2009


Author: vda
Date: 2009-04-04 23:15:14 +0000 (Sat, 04 Apr 2009)
New Revision: 25954

Log:
hush: enable NOMMU re-execution logic. Some testsuite entries
 fail on NOMMU. Before it was much worse.
 No regressions on MMU, size:

function                                             old     new   delta
handle_dollar                                        626     632      +6
run_list                                            2018    2022      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 10/0)               Total: 10 bytes



Modified:
   trunk/busybox/shell/hush.c


Changeset:
Modified: trunk/busybox/shell/hush.c
===================================================================
--- trunk/busybox/shell/hush.c	2009-04-04 22:47:50 UTC (rev 25953)
+++ trunk/busybox/shell/hush.c	2009-04-04 23:15:14 UTC (rev 25954)
@@ -2329,6 +2329,16 @@
 	_exit(EXIT_FAILURE);
 }
 
+static void re_execute_shell(const char *s) NORETURN;
+static void re_execute_shell(const char *s)
+{
+//TODO: pass non-exported variables, traps, and functions
+	debug_printf_exec("re_execute_shell pid:%d cmd:'%s'", getpid(), s);
+	execl(bb_busybox_exec_path, "hush", "-c", s, NULL);
+//TODO: fallback for init=/bin/hush?
+	_exit(127);
+}
+
 static int run_list(struct pipe *pi);
 
 /* Called after [v]fork() in run_pipe()
@@ -2360,8 +2370,7 @@
 		 * since this process is about to exit */
 		_exit(rcode);
 #else
-		bb_error_msg_and_die("NOMMU TODO: re-exec '%s'",
-				command->group_as_string);
+		re_execute_shell(command->group_as_string);
 #endif
 	}
 
@@ -3831,9 +3840,7 @@
 	 * huge=`cat TESTFILE` # was blocking here forever
 	 * echo OK
 	 */
-//TODO: pass non-exported variables, traps, and functions
-		execl(bb_busybox_exec_path, "hush", "-c", s, NULL);
-		_exit(127);
+		re_execute_shell(s);
 #endif
 	}
 
@@ -4071,7 +4078,13 @@
 #endif /* ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT */
 
 /* Return code: 0 for OK, 1 for syntax error */
-static int handle_dollar(o_string *dest, struct in_str *input)
+#if BB_MMU
+#define handle_dollar(ctx, dest, input) \
+	handle_dollar(dest, input)
+#endif
+static int handle_dollar(struct parse_context *ctx,
+		o_string *dest,
+		struct in_str *input)
 {
 	int expansion;
 	int ch = i_peek(input);  /* first character after the $ */
@@ -4079,7 +4092,10 @@
 
 	debug_printf_parse("handle_dollar entered: ch='%c'\n", ch);
 	if (isalpha(ch)) {
-		i_getch(input);
+		ch = i_getch(input);
+#if !BB_MMU
+		o_addchr(&ctx->as_string, ch);
+#endif
  make_var:
 		o_addchr(dest, SPECIAL_VAR_SYMBOL);
 		while (1) {
@@ -4089,12 +4105,18 @@
 			ch = i_peek(input);
 			if (!isalnum(ch) && ch != '_')
 				break;
-			i_getch(input);
+			ch = i_getch(input);
+#if !BB_MMU
+			o_addchr(&ctx->as_string, ch);
+#endif
 		}
 		o_addchr(dest, SPECIAL_VAR_SYMBOL);
 	} else if (isdigit(ch)) {
  make_one_char_var:
-		i_getch(input);
+		ch = i_getch(input);
+#if !BB_MMU
+		o_addchr(&ctx->as_string, ch);
+#endif
 		o_addchr(dest, SPECIAL_VAR_SYMBOL);
 		debug_printf_parse(": '%c'\n", ch);
 		o_addchr(dest, ch | quote_mask);
@@ -4111,13 +4133,19 @@
 		bool first_char, all_digits;
 
 		o_addchr(dest, SPECIAL_VAR_SYMBOL);
-		i_getch(input);
+		ch = i_getch(input);
+#if !BB_MMU
+		o_addchr(&ctx->as_string, ch);
+#endif
 		/* XXX maybe someone will try to escape the '}' */
 		expansion = 0;
 		first_char = true;
 		all_digits = false;
 		while (1) {
 			ch = i_getch(input);
+#if !BB_MMU
+			o_addchr(&ctx->as_string, ch);
+#endif
 			if (ch == '}')
 				break;
 
@@ -4183,10 +4211,16 @@
 		break;
 	}
 	case '(': {
-		i_getch(input);
+		ch = i_getch(input);
+#if !BB_MMU
+		o_addchr(&ctx->as_string, ch);
+#endif
 #if ENABLE_SH_MATH_SUPPORT
 		if (i_peek(input) == '(') {
-			i_getch(input);
+			ch = i_getch(input);
+#if !BB_MMU
+			o_addchr(&ctx->as_string, ch);
+#endif
 			o_addchr(dest, SPECIAL_VAR_SYMBOL);
 			o_addchr(dest, /*quote_mask |*/ '+');
 			add_till_closing_paren(dest, input, true);
@@ -4205,7 +4239,10 @@
 		break;
 	}
 	case '_':
-		i_getch(input);
+		ch = i_getch(input);
+#if !BB_MMU
+		o_addchr(&ctx->as_string, ch);
+#endif
 		ch = i_peek(input);
 		if (isalnum(ch)) { /* it's $_name or $_123 */
 			ch = '_';
@@ -4281,7 +4318,7 @@
 		goto again;
 	}
 	if (ch == '$') {
-		if (handle_dollar(dest, input) != 0) {
+		if (handle_dollar(ctx, dest, input) != 0) {
 			debug_printf_parse("parse_stream_dquoted return 1: "
 					"handle_dollar returned non-0\n");
 			return 1;
@@ -4477,7 +4514,12 @@
 					if (ch == EOF || ch == '\n')
 						break;
 					i_getch(input);
+					/* note: we do not add it to &ctx.as_string */
 				}
+#if !BB_MMU
+//TODO: go back one char?
+				o_addchr(&ctx.as_string, '\n');
+#endif
 			} else {
 				o_addQchr(&dest, ch);
 			}
@@ -4488,10 +4530,15 @@
 				goto parse_error;
 			}
 			o_addchr(&dest, '\\');
-			o_addchr(&dest, i_getch(input));
+			ch = i_getch(input);
+			o_addchr(&dest, ch);
+#if !BB_MMU
+			o_addchr(&ctx.as_string, ch);
+#endif
 			break;
 		case '$':
-			if (handle_dollar(&dest, input) != 0) {
+//NOMMU TODO!
+			if (handle_dollar(&ctx, &dest, input) != 0) {
 				debug_printf_parse("parse_stream parse error: "
 					"handle_dollar returned non-0\n");
 				goto parse_error;
@@ -4505,6 +4552,9 @@
 					syntax("unterminated '");
 					goto parse_error;
 				}
+#if !BB_MMU
+				o_addchr(&ctx.as_string, ch);
+#endif
 				if (ch == '\'')
 					break;
 				if (dest.o_assignment == NOT_ASSIGNMENT)
@@ -4538,7 +4588,10 @@
 			redir_style = REDIRECT_OVERWRITE;
 			if (next == '>') {
 				redir_style = REDIRECT_APPEND;
-				i_getch(input);
+				ch = i_getch(input);
+#if !BB_MMU
+				o_addchr(&ctx.as_string, ch);
+#endif
 			}
 #if 0
 			else if (next == '(') {
@@ -4556,10 +4609,16 @@
 			redir_style = REDIRECT_INPUT;
 			if (next == '<') {
 				redir_style = REDIRECT_HEREIS;
-				i_getch(input);
+				ch = i_getch(input);
+#if !BB_MMU
+				o_addchr(&ctx.as_string, ch);
+#endif
 			} else if (next == '>') {
 				redir_style = REDIRECT_IO;
-				i_getch(input);
+				ch = i_getch(input);
+#if !BB_MMU
+				o_addchr(&ctx.as_string, ch);
+#endif
 			}
 #if 0
 			else if (next == '(') {
@@ -4584,7 +4643,10 @@
 				ch = i_peek(input);
 				if (ch != ';')
 					break;
-				i_getch(input);
+				ch = i_getch(input);
+#if !BB_MMU
+				o_addchr(&ctx.as_string, ch);
+#endif
 				if (ctx.ctx_res_w == RES_CASEI) {
 					ctx.ctx_dsemicolon = 1;
 					ctx.ctx_res_w = RES_MATCH;
@@ -4602,7 +4664,10 @@
 				goto parse_error;
 			}
 			if (next == '&') {
-				i_getch(input);
+				ch = i_getch(input);
+#if !BB_MMU
+				o_addchr(&ctx.as_string, ch);
+#endif
 				done_pipe(&ctx, PIPE_AND);
 			} else {
 				done_pipe(&ctx, PIPE_BG);
@@ -4617,7 +4682,10 @@
 				break; /* we are in case's "word | word)" */
 #endif
 			if (next == '|') { /* || */
-				i_getch(input);
+				ch = i_getch(input);
+#if !BB_MMU
+				o_addchr(&ctx.as_string, ch);
+#endif
 				done_pipe(&ctx, PIPE_OR);
 			} else {
 				/* we could pick up a file descriptor choice here
@@ -4647,6 +4715,7 @@
 			) {
 				bb_error_msg("seems like a function definition");
 				i_getch(input);
+//if !BB_MMU o_addchr(&ctx.as_string...
 				do {
 //TODO: do it properly.
 					ch = i_getch(input);



More information about the busybox-cvs mailing list