diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-05 08:43:57 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-05 08:43:57 +0000 |
commit | d85a5df1598d671620407fb86e1dad00e4cbcb8c (patch) | |
tree | 9573b5f3f856ee0bb92462367ed833b209d432d0 | |
parent | cc4c693ec5c9bf93a179f205182d68d54a3daae4 (diff) | |
download | busybox-w32-d85a5df1598d671620407fb86e1dad00e4cbcb8c.tar.gz busybox-w32-d85a5df1598d671620407fb86e1dad00e4cbcb8c.tar.bz2 busybox-w32-d85a5df1598d671620407fb86e1dad00e4cbcb8c.zip |
hush: randomconfig fixes
-rw-r--r-- | shell/hush.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/shell/hush.c b/shell/hush.c index 47eff0fb8..43e715aff 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -2359,12 +2359,13 @@ static void re_execute_shell(const char *s) | |||
2359 | if (!cur->flg_export || cur->flg_read_only) | 2359 | if (!cur->flg_export || cur->flg_read_only) |
2360 | cnt += 2; | 2360 | cnt += 2; |
2361 | } | 2361 | } |
2362 | //TODO: need to free these strings in parent! | 2362 | G.argv_for_re_execing = pp = xzalloc(sizeof(argv[0]) * cnt); |
2363 | G.argv_for_re_execing = pp = xmalloc(sizeof(argv[0]) * cnt); | ||
2364 | *pp++ = (char *) applet_name; | 2363 | *pp++ = (char *) applet_name; |
2365 | *pp++ = xasprintf("-$%u", G.root_pid); | 2364 | *pp++ = xasprintf("-$%u", G.root_pid); |
2366 | *pp++ = xasprintf("-?%u", G.last_return_code); | 2365 | *pp++ = xasprintf("-?%u", G.last_return_code); |
2366 | #if ENABLE_HUSH_LOOPS | ||
2367 | *pp++ = xasprintf("-D%u", G.depth_of_loop); | 2367 | *pp++ = xasprintf("-D%u", G.depth_of_loop); |
2368 | #endif | ||
2368 | for (cur = G.top_var; cur; cur = cur->next) { | 2369 | for (cur = G.top_var; cur; cur = cur->next) { |
2369 | if (cur->varstr == hush_version_str) | 2370 | if (cur->varstr == hush_version_str) |
2370 | continue; | 2371 | continue; |
@@ -2381,7 +2382,7 @@ static void re_execute_shell(const char *s) | |||
2381 | pp2 = G.global_argv; | 2382 | pp2 = G.global_argv; |
2382 | while (*pp2) | 2383 | while (*pp2) |
2383 | *pp++ = *pp2++; | 2384 | *pp++ = *pp2++; |
2384 | *pp = NULL; | 2385 | /* *pp = NULL; - is already there */ |
2385 | //TODO: pass traps and functions | 2386 | //TODO: pass traps and functions |
2386 | 2387 | ||
2387 | debug_printf_exec("re_execute_shell pid:%d cmd:'%s'\n", getpid(), s); | 2388 | debug_printf_exec("re_execute_shell pid:%d cmd:'%s'\n", getpid(), s); |
@@ -2398,7 +2399,9 @@ static void clean_up_after_re_execute(void) | |||
2398 | /* Must match re_execute_shell's allocations */ | 2399 | /* Must match re_execute_shell's allocations */ |
2399 | free(pp[1]); | 2400 | free(pp[1]); |
2400 | free(pp[2]); | 2401 | free(pp[2]); |
2402 | #if ENABLE_HUSH_LOOPS | ||
2401 | free(pp[3]); | 2403 | free(pp[3]); |
2404 | #endif | ||
2402 | free(pp); | 2405 | free(pp); |
2403 | G.argv_for_re_execing = NULL; | 2406 | G.argv_for_re_execing = NULL; |
2404 | } | 2407 | } |
@@ -4281,56 +4284,58 @@ static int handle_dollar(struct parse_context *ctx, | |||
4281 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4284 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
4282 | break; | 4285 | break; |
4283 | } | 4286 | } |
4287 | #if (ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_TICK) | ||
4284 | case '(': { | 4288 | case '(': { |
4285 | #if !BB_MMU | 4289 | # if !BB_MMU |
4286 | int pos; | 4290 | int pos; |
4287 | #endif | 4291 | # endif |
4288 | ch = i_getch(input); | 4292 | ch = i_getch(input); |
4289 | #if !BB_MMU | 4293 | # if !BB_MMU |
4290 | if (ctx) o_addchr(&ctx->as_string, ch); | 4294 | if (ctx) o_addchr(&ctx->as_string, ch); |
4291 | #endif | 4295 | # endif |
4292 | #if ENABLE_SH_MATH_SUPPORT | 4296 | # if ENABLE_SH_MATH_SUPPORT |
4293 | if (i_peek(input) == '(') { | 4297 | if (i_peek(input) == '(') { |
4294 | ch = i_getch(input); | 4298 | ch = i_getch(input); |
4295 | #if !BB_MMU | 4299 | # if !BB_MMU |
4296 | if (ctx) o_addchr(&ctx->as_string, ch); | 4300 | if (ctx) o_addchr(&ctx->as_string, ch); |
4297 | #endif | 4301 | # endif |
4298 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4302 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
4299 | o_addchr(dest, /*quote_mask |*/ '+'); | 4303 | o_addchr(dest, /*quote_mask |*/ '+'); |
4300 | #if !BB_MMU | 4304 | # if !BB_MMU |
4301 | pos = dest->length; | 4305 | pos = dest->length; |
4302 | #endif | 4306 | # endif |
4303 | add_till_closing_paren(dest, input, true); | 4307 | add_till_closing_paren(dest, input, true); |
4304 | #if !BB_MMU | 4308 | # if !BB_MMU |
4305 | if (ctx) { | 4309 | if (ctx) { |
4306 | o_addstr(&ctx->as_string, dest->data + pos); | 4310 | o_addstr(&ctx->as_string, dest->data + pos); |
4307 | o_addchr(&ctx->as_string, ')'); | 4311 | o_addchr(&ctx->as_string, ')'); |
4308 | o_addchr(&ctx->as_string, ')'); | 4312 | o_addchr(&ctx->as_string, ')'); |
4309 | } | 4313 | } |
4310 | #endif | 4314 | # endif |
4311 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4315 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
4312 | break; | 4316 | break; |
4313 | } | 4317 | } |
4314 | #endif | 4318 | # endif |
4315 | #if ENABLE_HUSH_TICK | 4319 | # if ENABLE_HUSH_TICK |
4316 | //int pos = dest->length; | 4320 | //int pos = dest->length; |
4317 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4321 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
4318 | o_addchr(dest, quote_mask | '`'); | 4322 | o_addchr(dest, quote_mask | '`'); |
4319 | #if !BB_MMU | 4323 | # if !BB_MMU |
4320 | pos = dest->length; | 4324 | pos = dest->length; |
4321 | #endif | 4325 | # endif |
4322 | add_till_closing_paren(dest, input, false); | 4326 | add_till_closing_paren(dest, input, false); |
4323 | #if !BB_MMU | 4327 | # if !BB_MMU |
4324 | if (ctx) { | 4328 | if (ctx) { |
4325 | o_addstr(&ctx->as_string, dest->data + pos); | 4329 | o_addstr(&ctx->as_string, dest->data + pos); |
4326 | o_addchr(&ctx->as_string, '`'); | 4330 | o_addchr(&ctx->as_string, '`'); |
4327 | } | 4331 | } |
4328 | #endif | 4332 | # endif |
4329 | //debug_printf_subst("SUBST RES2 '%s'\n", dest->data + pos); | 4333 | //debug_printf_subst("SUBST RES2 '%s'\n", dest->data + pos); |
4330 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4334 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
4331 | #endif | 4335 | # endif |
4332 | break; | 4336 | break; |
4333 | } | 4337 | } |
4338 | #endif | ||
4334 | case '_': | 4339 | case '_': |
4335 | ch = i_getch(input); | 4340 | ch = i_getch(input); |
4336 | #if !BB_MMU | 4341 | #if !BB_MMU |
@@ -5075,9 +5080,11 @@ int hush_main(int argc, char **argv) | |||
5075 | case '?': | 5080 | case '?': |
5076 | G.last_return_code = xatoi_u(optarg); | 5081 | G.last_return_code = xatoi_u(optarg); |
5077 | break; | 5082 | break; |
5083 | #if ENABLE_HUSH_LOOPS | ||
5078 | case 'D': | 5084 | case 'D': |
5079 | G.depth_of_loop = xatoi_u(optarg); | 5085 | G.depth_of_loop = xatoi_u(optarg); |
5080 | break; | 5086 | break; |
5087 | #endif | ||
5081 | case 'R': | 5088 | case 'R': |
5082 | case 'V': | 5089 | case 'V': |
5083 | set_local_var(xstrdup(optarg), 0, opt == 'R'); | 5090 | set_local_var(xstrdup(optarg), 0, opt == 'R'); |