diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-04 23:15:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-04 23:15:14 +0000 |
commit | 609f2ab4345e173ea944db774131e3615b3176a8 (patch) | |
tree | f7a99412acecb9868966335fdb222bba8474c2fd /shell | |
parent | 9aa7d6fdc5554480b9cb4fc740ce3f1d2b734555 (diff) | |
download | busybox-w32-609f2ab4345e173ea944db774131e3615b3176a8.tar.gz busybox-w32-609f2ab4345e173ea944db774131e3615b3176a8.tar.bz2 busybox-w32-609f2ab4345e173ea944db774131e3615b3176a8.zip |
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
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 113 |
1 files changed, 91 insertions, 22 deletions
diff --git a/shell/hush.c b/shell/hush.c index ac3480578..0313cfd78 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -2329,6 +2329,16 @@ static void pseudo_exec_argv(nommu_save_t *nommu_save, | |||
2329 | _exit(EXIT_FAILURE); | 2329 | _exit(EXIT_FAILURE); |
2330 | } | 2330 | } |
2331 | 2331 | ||
2332 | static void re_execute_shell(const char *s) NORETURN; | ||
2333 | static void re_execute_shell(const char *s) | ||
2334 | { | ||
2335 | //TODO: pass non-exported variables, traps, and functions | ||
2336 | debug_printf_exec("re_execute_shell pid:%d cmd:'%s'", getpid(), s); | ||
2337 | execl(bb_busybox_exec_path, "hush", "-c", s, NULL); | ||
2338 | //TODO: fallback for init=/bin/hush? | ||
2339 | _exit(127); | ||
2340 | } | ||
2341 | |||
2332 | static int run_list(struct pipe *pi); | 2342 | static int run_list(struct pipe *pi); |
2333 | 2343 | ||
2334 | /* Called after [v]fork() in run_pipe() | 2344 | /* Called after [v]fork() in run_pipe() |
@@ -2360,8 +2370,7 @@ static void pseudo_exec(nommu_save_t *nommu_save, | |||
2360 | * since this process is about to exit */ | 2370 | * since this process is about to exit */ |
2361 | _exit(rcode); | 2371 | _exit(rcode); |
2362 | #else | 2372 | #else |
2363 | bb_error_msg_and_die("NOMMU TODO: re-exec '%s'", | 2373 | re_execute_shell(command->group_as_string); |
2364 | command->group_as_string); | ||
2365 | #endif | 2374 | #endif |
2366 | } | 2375 | } |
2367 | 2376 | ||
@@ -3831,9 +3840,7 @@ static FILE *generate_stream_from_string(const char *s) | |||
3831 | * huge=`cat TESTFILE` # was blocking here forever | 3840 | * huge=`cat TESTFILE` # was blocking here forever |
3832 | * echo OK | 3841 | * echo OK |
3833 | */ | 3842 | */ |
3834 | //TODO: pass non-exported variables, traps, and functions | 3843 | re_execute_shell(s); |
3835 | execl(bb_busybox_exec_path, "hush", "-c", s, NULL); | ||
3836 | _exit(127); | ||
3837 | #endif | 3844 | #endif |
3838 | } | 3845 | } |
3839 | 3846 | ||
@@ -4071,7 +4078,13 @@ static void add_till_closing_paren(o_string *dest, struct in_str *input, bool db | |||
4071 | #endif /* ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT */ | 4078 | #endif /* ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT */ |
4072 | 4079 | ||
4073 | /* Return code: 0 for OK, 1 for syntax error */ | 4080 | /* Return code: 0 for OK, 1 for syntax error */ |
4074 | static int handle_dollar(o_string *dest, struct in_str *input) | 4081 | #if BB_MMU |
4082 | #define handle_dollar(ctx, dest, input) \ | ||
4083 | handle_dollar(dest, input) | ||
4084 | #endif | ||
4085 | static int handle_dollar(struct parse_context *ctx, | ||
4086 | o_string *dest, | ||
4087 | struct in_str *input) | ||
4075 | { | 4088 | { |
4076 | int expansion; | 4089 | int expansion; |
4077 | int ch = i_peek(input); /* first character after the $ */ | 4090 | int ch = i_peek(input); /* first character after the $ */ |
@@ -4079,7 +4092,10 @@ static int handle_dollar(o_string *dest, struct in_str *input) | |||
4079 | 4092 | ||
4080 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); | 4093 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); |
4081 | if (isalpha(ch)) { | 4094 | if (isalpha(ch)) { |
4082 | i_getch(input); | 4095 | ch = i_getch(input); |
4096 | #if !BB_MMU | ||
4097 | o_addchr(&ctx->as_string, ch); | ||
4098 | #endif | ||
4083 | make_var: | 4099 | make_var: |
4084 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4100 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
4085 | while (1) { | 4101 | while (1) { |
@@ -4089,12 +4105,18 @@ static int handle_dollar(o_string *dest, struct in_str *input) | |||
4089 | ch = i_peek(input); | 4105 | ch = i_peek(input); |
4090 | if (!isalnum(ch) && ch != '_') | 4106 | if (!isalnum(ch) && ch != '_') |
4091 | break; | 4107 | break; |
4092 | i_getch(input); | 4108 | ch = i_getch(input); |
4109 | #if !BB_MMU | ||
4110 | o_addchr(&ctx->as_string, ch); | ||
4111 | #endif | ||
4093 | } | 4112 | } |
4094 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4113 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
4095 | } else if (isdigit(ch)) { | 4114 | } else if (isdigit(ch)) { |
4096 | make_one_char_var: | 4115 | make_one_char_var: |
4097 | i_getch(input); | 4116 | ch = i_getch(input); |
4117 | #if !BB_MMU | ||
4118 | o_addchr(&ctx->as_string, ch); | ||
4119 | #endif | ||
4098 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4120 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
4099 | debug_printf_parse(": '%c'\n", ch); | 4121 | debug_printf_parse(": '%c'\n", ch); |
4100 | o_addchr(dest, ch | quote_mask); | 4122 | o_addchr(dest, ch | quote_mask); |
@@ -4111,13 +4133,19 @@ static int handle_dollar(o_string *dest, struct in_str *input) | |||
4111 | bool first_char, all_digits; | 4133 | bool first_char, all_digits; |
4112 | 4134 | ||
4113 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4135 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
4114 | i_getch(input); | 4136 | ch = i_getch(input); |
4137 | #if !BB_MMU | ||
4138 | o_addchr(&ctx->as_string, ch); | ||
4139 | #endif | ||
4115 | /* XXX maybe someone will try to escape the '}' */ | 4140 | /* XXX maybe someone will try to escape the '}' */ |
4116 | expansion = 0; | 4141 | expansion = 0; |
4117 | first_char = true; | 4142 | first_char = true; |
4118 | all_digits = false; | 4143 | all_digits = false; |
4119 | while (1) { | 4144 | while (1) { |
4120 | ch = i_getch(input); | 4145 | ch = i_getch(input); |
4146 | #if !BB_MMU | ||
4147 | o_addchr(&ctx->as_string, ch); | ||
4148 | #endif | ||
4121 | if (ch == '}') | 4149 | if (ch == '}') |
4122 | break; | 4150 | break; |
4123 | 4151 | ||
@@ -4183,10 +4211,16 @@ static int handle_dollar(o_string *dest, struct in_str *input) | |||
4183 | break; | 4211 | break; |
4184 | } | 4212 | } |
4185 | case '(': { | 4213 | case '(': { |
4186 | i_getch(input); | 4214 | ch = i_getch(input); |
4215 | #if !BB_MMU | ||
4216 | o_addchr(&ctx->as_string, ch); | ||
4217 | #endif | ||
4187 | #if ENABLE_SH_MATH_SUPPORT | 4218 | #if ENABLE_SH_MATH_SUPPORT |
4188 | if (i_peek(input) == '(') { | 4219 | if (i_peek(input) == '(') { |
4189 | i_getch(input); | 4220 | ch = i_getch(input); |
4221 | #if !BB_MMU | ||
4222 | o_addchr(&ctx->as_string, ch); | ||
4223 | #endif | ||
4190 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4224 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
4191 | o_addchr(dest, /*quote_mask |*/ '+'); | 4225 | o_addchr(dest, /*quote_mask |*/ '+'); |
4192 | add_till_closing_paren(dest, input, true); | 4226 | add_till_closing_paren(dest, input, true); |
@@ -4205,7 +4239,10 @@ static int handle_dollar(o_string *dest, struct in_str *input) | |||
4205 | break; | 4239 | break; |
4206 | } | 4240 | } |
4207 | case '_': | 4241 | case '_': |
4208 | i_getch(input); | 4242 | ch = i_getch(input); |
4243 | #if !BB_MMU | ||
4244 | o_addchr(&ctx->as_string, ch); | ||
4245 | #endif | ||
4209 | ch = i_peek(input); | 4246 | ch = i_peek(input); |
4210 | if (isalnum(ch)) { /* it's $_name or $_123 */ | 4247 | if (isalnum(ch)) { /* it's $_name or $_123 */ |
4211 | ch = '_'; | 4248 | ch = '_'; |
@@ -4281,7 +4318,7 @@ static int parse_stream_dquoted(struct parse_context *ctx, | |||
4281 | goto again; | 4318 | goto again; |
4282 | } | 4319 | } |
4283 | if (ch == '$') { | 4320 | if (ch == '$') { |
4284 | if (handle_dollar(dest, input) != 0) { | 4321 | if (handle_dollar(ctx, dest, input) != 0) { |
4285 | debug_printf_parse("parse_stream_dquoted return 1: " | 4322 | debug_printf_parse("parse_stream_dquoted return 1: " |
4286 | "handle_dollar returned non-0\n"); | 4323 | "handle_dollar returned non-0\n"); |
4287 | return 1; | 4324 | return 1; |
@@ -4477,7 +4514,12 @@ static struct pipe *parse_stream(char **pstring, | |||
4477 | if (ch == EOF || ch == '\n') | 4514 | if (ch == EOF || ch == '\n') |
4478 | break; | 4515 | break; |
4479 | i_getch(input); | 4516 | i_getch(input); |
4517 | /* note: we do not add it to &ctx.as_string */ | ||
4480 | } | 4518 | } |
4519 | #if !BB_MMU | ||
4520 | //TODO: go back one char? | ||
4521 | o_addchr(&ctx.as_string, '\n'); | ||
4522 | #endif | ||
4481 | } else { | 4523 | } else { |
4482 | o_addQchr(&dest, ch); | 4524 | o_addQchr(&dest, ch); |
4483 | } | 4525 | } |
@@ -4488,10 +4530,15 @@ static struct pipe *parse_stream(char **pstring, | |||
4488 | goto parse_error; | 4530 | goto parse_error; |
4489 | } | 4531 | } |
4490 | o_addchr(&dest, '\\'); | 4532 | o_addchr(&dest, '\\'); |
4491 | o_addchr(&dest, i_getch(input)); | 4533 | ch = i_getch(input); |
4534 | o_addchr(&dest, ch); | ||
4535 | #if !BB_MMU | ||
4536 | o_addchr(&ctx.as_string, ch); | ||
4537 | #endif | ||
4492 | break; | 4538 | break; |
4493 | case '$': | 4539 | case '$': |
4494 | if (handle_dollar(&dest, input) != 0) { | 4540 | //NOMMU TODO! |
4541 | if (handle_dollar(&ctx, &dest, input) != 0) { | ||
4495 | debug_printf_parse("parse_stream parse error: " | 4542 | debug_printf_parse("parse_stream parse error: " |
4496 | "handle_dollar returned non-0\n"); | 4543 | "handle_dollar returned non-0\n"); |
4497 | goto parse_error; | 4544 | goto parse_error; |
@@ -4505,6 +4552,9 @@ static struct pipe *parse_stream(char **pstring, | |||
4505 | syntax("unterminated '"); | 4552 | syntax("unterminated '"); |
4506 | goto parse_error; | 4553 | goto parse_error; |
4507 | } | 4554 | } |
4555 | #if !BB_MMU | ||
4556 | o_addchr(&ctx.as_string, ch); | ||
4557 | #endif | ||
4508 | if (ch == '\'') | 4558 | if (ch == '\'') |
4509 | break; | 4559 | break; |
4510 | if (dest.o_assignment == NOT_ASSIGNMENT) | 4560 | if (dest.o_assignment == NOT_ASSIGNMENT) |
@@ -4538,7 +4588,10 @@ static struct pipe *parse_stream(char **pstring, | |||
4538 | redir_style = REDIRECT_OVERWRITE; | 4588 | redir_style = REDIRECT_OVERWRITE; |
4539 | if (next == '>') { | 4589 | if (next == '>') { |
4540 | redir_style = REDIRECT_APPEND; | 4590 | redir_style = REDIRECT_APPEND; |
4541 | i_getch(input); | 4591 | ch = i_getch(input); |
4592 | #if !BB_MMU | ||
4593 | o_addchr(&ctx.as_string, ch); | ||
4594 | #endif | ||
4542 | } | 4595 | } |
4543 | #if 0 | 4596 | #if 0 |
4544 | else if (next == '(') { | 4597 | else if (next == '(') { |
@@ -4556,10 +4609,16 @@ static struct pipe *parse_stream(char **pstring, | |||
4556 | redir_style = REDIRECT_INPUT; | 4609 | redir_style = REDIRECT_INPUT; |
4557 | if (next == '<') { | 4610 | if (next == '<') { |
4558 | redir_style = REDIRECT_HEREIS; | 4611 | redir_style = REDIRECT_HEREIS; |
4559 | i_getch(input); | 4612 | ch = i_getch(input); |
4613 | #if !BB_MMU | ||
4614 | o_addchr(&ctx.as_string, ch); | ||
4615 | #endif | ||
4560 | } else if (next == '>') { | 4616 | } else if (next == '>') { |
4561 | redir_style = REDIRECT_IO; | 4617 | redir_style = REDIRECT_IO; |
4562 | i_getch(input); | 4618 | ch = i_getch(input); |
4619 | #if !BB_MMU | ||
4620 | o_addchr(&ctx.as_string, ch); | ||
4621 | #endif | ||
4563 | } | 4622 | } |
4564 | #if 0 | 4623 | #if 0 |
4565 | else if (next == '(') { | 4624 | else if (next == '(') { |
@@ -4584,7 +4643,10 @@ static struct pipe *parse_stream(char **pstring, | |||
4584 | ch = i_peek(input); | 4643 | ch = i_peek(input); |
4585 | if (ch != ';') | 4644 | if (ch != ';') |
4586 | break; | 4645 | break; |
4587 | i_getch(input); | 4646 | ch = i_getch(input); |
4647 | #if !BB_MMU | ||
4648 | o_addchr(&ctx.as_string, ch); | ||
4649 | #endif | ||
4588 | if (ctx.ctx_res_w == RES_CASEI) { | 4650 | if (ctx.ctx_res_w == RES_CASEI) { |
4589 | ctx.ctx_dsemicolon = 1; | 4651 | ctx.ctx_dsemicolon = 1; |
4590 | ctx.ctx_res_w = RES_MATCH; | 4652 | ctx.ctx_res_w = RES_MATCH; |
@@ -4602,7 +4664,10 @@ static struct pipe *parse_stream(char **pstring, | |||
4602 | goto parse_error; | 4664 | goto parse_error; |
4603 | } | 4665 | } |
4604 | if (next == '&') { | 4666 | if (next == '&') { |
4605 | i_getch(input); | 4667 | ch = i_getch(input); |
4668 | #if !BB_MMU | ||
4669 | o_addchr(&ctx.as_string, ch); | ||
4670 | #endif | ||
4606 | done_pipe(&ctx, PIPE_AND); | 4671 | done_pipe(&ctx, PIPE_AND); |
4607 | } else { | 4672 | } else { |
4608 | done_pipe(&ctx, PIPE_BG); | 4673 | done_pipe(&ctx, PIPE_BG); |
@@ -4617,7 +4682,10 @@ static struct pipe *parse_stream(char **pstring, | |||
4617 | break; /* we are in case's "word | word)" */ | 4682 | break; /* we are in case's "word | word)" */ |
4618 | #endif | 4683 | #endif |
4619 | if (next == '|') { /* || */ | 4684 | if (next == '|') { /* || */ |
4620 | i_getch(input); | 4685 | ch = i_getch(input); |
4686 | #if !BB_MMU | ||
4687 | o_addchr(&ctx.as_string, ch); | ||
4688 | #endif | ||
4621 | done_pipe(&ctx, PIPE_OR); | 4689 | done_pipe(&ctx, PIPE_OR); |
4622 | } else { | 4690 | } else { |
4623 | /* we could pick up a file descriptor choice here | 4691 | /* we could pick up a file descriptor choice here |
@@ -4647,6 +4715,7 @@ static struct pipe *parse_stream(char **pstring, | |||
4647 | ) { | 4715 | ) { |
4648 | bb_error_msg("seems like a function definition"); | 4716 | bb_error_msg("seems like a function definition"); |
4649 | i_getch(input); | 4717 | i_getch(input); |
4718 | //if !BB_MMU o_addchr(&ctx.as_string... | ||
4650 | do { | 4719 | do { |
4651 | //TODO: do it properly. | 4720 | //TODO: do it properly. |
4652 | ch = i_getch(input); | 4721 | ch = i_getch(input); |