diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-19 13:13:06 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-19 13:13:06 +0200 |
commit | c0836530f1cee749f758217a4b60c19f03419481 (patch) | |
tree | 518b00b8176dfd0bfd61e82cd79c6e46d887036f /shell | |
parent | e8405619fa28972eacff34d3dee030927c4afc24 (diff) | |
download | busybox-w32-c0836530f1cee749f758217a4b60c19f03419481.tar.gz busybox-w32-c0836530f1cee749f758217a4b60c19f03419481.tar.bz2 busybox-w32-c0836530f1cee749f758217a4b60c19f03419481.zip |
hush: cosmetics. no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 131 |
1 files changed, 66 insertions, 65 deletions
diff --git a/shell/hush.c b/shell/hush.c index 46bb7e9a2..6ee128641 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -2689,9 +2689,9 @@ static void re_execute_shell(char ***to_free, const char *s, | |||
2689 | char param_buf[sizeof("-$%x:%x:%x:%x:%x") + sizeof(unsigned) * 2]; | 2689 | char param_buf[sizeof("-$%x:%x:%x:%x:%x") + sizeof(unsigned) * 2]; |
2690 | char *heredoc_argv[4]; | 2690 | char *heredoc_argv[4]; |
2691 | struct variable *cur; | 2691 | struct variable *cur; |
2692 | #if ENABLE_HUSH_FUNCTIONS | 2692 | # if ENABLE_HUSH_FUNCTIONS |
2693 | struct function *funcp; | 2693 | struct function *funcp; |
2694 | #endif | 2694 | # endif |
2695 | char **argv, **pp; | 2695 | char **argv, **pp; |
2696 | unsigned cnt; | 2696 | unsigned cnt; |
2697 | 2697 | ||
@@ -2726,10 +2726,10 @@ static void re_execute_shell(char ***to_free, const char *s, | |||
2726 | if (!cur->flg_export || cur->flg_read_only) | 2726 | if (!cur->flg_export || cur->flg_read_only) |
2727 | cnt += 2; | 2727 | cnt += 2; |
2728 | } | 2728 | } |
2729 | #if ENABLE_HUSH_FUNCTIONS | 2729 | # if ENABLE_HUSH_FUNCTIONS |
2730 | for (funcp = G.top_func; funcp; funcp = funcp->next) | 2730 | for (funcp = G.top_func; funcp; funcp = funcp->next) |
2731 | cnt += 3; | 2731 | cnt += 3; |
2732 | #endif | 2732 | # endif |
2733 | pp = g_argv; | 2733 | pp = g_argv; |
2734 | while (*pp++) | 2734 | while (*pp++) |
2735 | cnt++; | 2735 | cnt++; |
@@ -2747,13 +2747,13 @@ static void re_execute_shell(char ***to_free, const char *s, | |||
2747 | *pp++ = cur->varstr; | 2747 | *pp++ = cur->varstr; |
2748 | } | 2748 | } |
2749 | } | 2749 | } |
2750 | #if ENABLE_HUSH_FUNCTIONS | 2750 | # if ENABLE_HUSH_FUNCTIONS |
2751 | for (funcp = G.top_func; funcp; funcp = funcp->next) { | 2751 | for (funcp = G.top_func; funcp; funcp = funcp->next) { |
2752 | *pp++ = (char *) "-F"; | 2752 | *pp++ = (char *) "-F"; |
2753 | *pp++ = funcp->name; | 2753 | *pp++ = funcp->name; |
2754 | *pp++ = funcp->body_as_string; | 2754 | *pp++ = funcp->body_as_string; |
2755 | } | 2755 | } |
2756 | #endif | 2756 | # endif |
2757 | /* We can pass activated traps here. Say, -Tnn:trap_string | 2757 | /* We can pass activated traps here. Say, -Tnn:trap_string |
2758 | * | 2758 | * |
2759 | * However, POSIX says that subshells reset signals with traps | 2759 | * However, POSIX says that subshells reset signals with traps |
@@ -3242,9 +3242,9 @@ static int run_function(const struct function *funcp, char **argv) | |||
3242 | /* "we are in function, ok to use return" */ | 3242 | /* "we are in function, ok to use return" */ |
3243 | sv_flg = G.flag_return_in_progress; | 3243 | sv_flg = G.flag_return_in_progress; |
3244 | G.flag_return_in_progress = -1; | 3244 | G.flag_return_in_progress = -1; |
3245 | #if ENABLE_HUSH_LOCAL | 3245 | # if ENABLE_HUSH_LOCAL |
3246 | G.func_nest_level++; | 3246 | G.func_nest_level++; |
3247 | #endif | 3247 | # endif |
3248 | 3248 | ||
3249 | /* On MMU, funcp->body is always non-NULL */ | 3249 | /* On MMU, funcp->body is always non-NULL */ |
3250 | # if !BB_MMU | 3250 | # if !BB_MMU |
@@ -3258,7 +3258,7 @@ static int run_function(const struct function *funcp, char **argv) | |||
3258 | rc = run_list(funcp->body); | 3258 | rc = run_list(funcp->body); |
3259 | } | 3259 | } |
3260 | 3260 | ||
3261 | #if ENABLE_HUSH_LOCAL | 3261 | # if ENABLE_HUSH_LOCAL |
3262 | { | 3262 | { |
3263 | struct variable *var; | 3263 | struct variable *var; |
3264 | struct variable **var_pp; | 3264 | struct variable **var_pp; |
@@ -3281,7 +3281,7 @@ static int run_function(const struct function *funcp, char **argv) | |||
3281 | } | 3281 | } |
3282 | G.func_nest_level--; | 3282 | G.func_nest_level--; |
3283 | } | 3283 | } |
3284 | #endif | 3284 | # endif |
3285 | G.flag_return_in_progress = sv_flg; | 3285 | G.flag_return_in_progress = sv_flg; |
3286 | 3286 | ||
3287 | restore_G_args(&sv, argv); | 3287 | restore_G_args(&sv, argv); |
@@ -3291,13 +3291,13 @@ static int run_function(const struct function *funcp, char **argv) | |||
3291 | #endif /* ENABLE_HUSH_FUNCTIONS */ | 3291 | #endif /* ENABLE_HUSH_FUNCTIONS */ |
3292 | 3292 | ||
3293 | 3293 | ||
3294 | # if BB_MMU | 3294 | #if BB_MMU |
3295 | #define exec_builtin(to_free, x, argv) \ | 3295 | #define exec_builtin(to_free, x, argv) \ |
3296 | exec_builtin(x, argv) | 3296 | exec_builtin(x, argv) |
3297 | # else | 3297 | #else |
3298 | #define exec_builtin(to_free, x, argv) \ | 3298 | #define exec_builtin(to_free, x, argv) \ |
3299 | exec_builtin(to_free, argv) | 3299 | exec_builtin(to_free, argv) |
3300 | # endif | 3300 | #endif |
3301 | static void exec_builtin(char ***to_free, | 3301 | static void exec_builtin(char ***to_free, |
3302 | const struct built_in_command *x, | 3302 | const struct built_in_command *x, |
3303 | char **argv) NORETURN; | 3303 | char **argv) NORETURN; |
@@ -3305,11 +3305,11 @@ static void exec_builtin(char ***to_free, | |||
3305 | const struct built_in_command *x, | 3305 | const struct built_in_command *x, |
3306 | char **argv) | 3306 | char **argv) |
3307 | { | 3307 | { |
3308 | # if BB_MMU | 3308 | #if BB_MMU |
3309 | int rcode = x->function(argv); | 3309 | int rcode = x->function(argv); |
3310 | fflush(NULL); | 3310 | fflush(NULL); |
3311 | _exit(rcode); | 3311 | _exit(rcode); |
3312 | # else | 3312 | #else |
3313 | /* On NOMMU, we must never block! | 3313 | /* On NOMMU, we must never block! |
3314 | * Example: { sleep 99 | read line; } & echo Ok | 3314 | * Example: { sleep 99 | read line; } & echo Ok |
3315 | */ | 3315 | */ |
@@ -3318,7 +3318,7 @@ static void exec_builtin(char ***to_free, | |||
3318 | G.global_argv[0], | 3318 | G.global_argv[0], |
3319 | G.global_argv + 1, | 3319 | G.global_argv + 1, |
3320 | argv); | 3320 | argv); |
3321 | # endif | 3321 | #endif |
3322 | } | 3322 | } |
3323 | 3323 | ||
3324 | 3324 | ||
@@ -4115,30 +4115,30 @@ static void debug_print_tree(struct pipe *pi, int lvl) | |||
4115 | }; | 4115 | }; |
4116 | static const char *RES[] = { | 4116 | static const char *RES[] = { |
4117 | [RES_NONE ] = "NONE" , | 4117 | [RES_NONE ] = "NONE" , |
4118 | #if ENABLE_HUSH_IF | 4118 | # if ENABLE_HUSH_IF |
4119 | [RES_IF ] = "IF" , | 4119 | [RES_IF ] = "IF" , |
4120 | [RES_THEN ] = "THEN" , | 4120 | [RES_THEN ] = "THEN" , |
4121 | [RES_ELIF ] = "ELIF" , | 4121 | [RES_ELIF ] = "ELIF" , |
4122 | [RES_ELSE ] = "ELSE" , | 4122 | [RES_ELSE ] = "ELSE" , |
4123 | [RES_FI ] = "FI" , | 4123 | [RES_FI ] = "FI" , |
4124 | #endif | 4124 | # endif |
4125 | #if ENABLE_HUSH_LOOPS | 4125 | # if ENABLE_HUSH_LOOPS |
4126 | [RES_FOR ] = "FOR" , | 4126 | [RES_FOR ] = "FOR" , |
4127 | [RES_WHILE] = "WHILE", | 4127 | [RES_WHILE] = "WHILE", |
4128 | [RES_UNTIL] = "UNTIL", | 4128 | [RES_UNTIL] = "UNTIL", |
4129 | [RES_DO ] = "DO" , | 4129 | [RES_DO ] = "DO" , |
4130 | [RES_DONE ] = "DONE" , | 4130 | [RES_DONE ] = "DONE" , |
4131 | #endif | 4131 | # endif |
4132 | #if ENABLE_HUSH_LOOPS || ENABLE_HUSH_CASE | 4132 | # if ENABLE_HUSH_LOOPS || ENABLE_HUSH_CASE |
4133 | [RES_IN ] = "IN" , | 4133 | [RES_IN ] = "IN" , |
4134 | #endif | 4134 | # endif |
4135 | #if ENABLE_HUSH_CASE | 4135 | # if ENABLE_HUSH_CASE |
4136 | [RES_CASE ] = "CASE" , | 4136 | [RES_CASE ] = "CASE" , |
4137 | [RES_CASE_IN ] = "CASE_IN" , | 4137 | [RES_CASE_IN ] = "CASE_IN" , |
4138 | [RES_MATCH] = "MATCH", | 4138 | [RES_MATCH] = "MATCH", |
4139 | [RES_CASE_BODY] = "CASE_BODY", | 4139 | [RES_CASE_BODY] = "CASE_BODY", |
4140 | [RES_ESAC ] = "ESAC" , | 4140 | [RES_ESAC ] = "ESAC" , |
4141 | #endif | 4141 | # endif |
4142 | [RES_XXXX ] = "XXXX" , | 4142 | [RES_XXXX ] = "XXXX" , |
4143 | [RES_SNTX ] = "SNTX" , | 4143 | [RES_SNTX ] = "SNTX" , |
4144 | }; | 4144 | }; |
@@ -4146,9 +4146,9 @@ static void debug_print_tree(struct pipe *pi, int lvl) | |||
4146 | "{}", | 4146 | "{}", |
4147 | "()", | 4147 | "()", |
4148 | "[noglob]", | 4148 | "[noglob]", |
4149 | #if ENABLE_HUSH_FUNCTIONS | 4149 | # if ENABLE_HUSH_FUNCTIONS |
4150 | "func()", | 4150 | "func()", |
4151 | #endif | 4151 | # endif |
4152 | }; | 4152 | }; |
4153 | 4153 | ||
4154 | int pin, prn; | 4154 | int pin, prn; |
@@ -4184,7 +4184,7 @@ static void debug_print_tree(struct pipe *pi, int lvl) | |||
4184 | pin++; | 4184 | pin++; |
4185 | } | 4185 | } |
4186 | } | 4186 | } |
4187 | #endif | 4187 | #endif /* debug_print_tree */ |
4188 | 4188 | ||
4189 | /* NB: called by pseudo_exec, and therefore must not modify any | 4189 | /* NB: called by pseudo_exec, and therefore must not modify any |
4190 | * global data until exec/_exit (we can be a child after vfork!) */ | 4190 | * global data until exec/_exit (we can be a child after vfork!) */ |
@@ -4658,25 +4658,25 @@ struct reserved_combo { | |||
4658 | }; | 4658 | }; |
4659 | enum { | 4659 | enum { |
4660 | FLAG_END = (1 << RES_NONE ), | 4660 | FLAG_END = (1 << RES_NONE ), |
4661 | #if ENABLE_HUSH_IF | 4661 | # if ENABLE_HUSH_IF |
4662 | FLAG_IF = (1 << RES_IF ), | 4662 | FLAG_IF = (1 << RES_IF ), |
4663 | FLAG_THEN = (1 << RES_THEN ), | 4663 | FLAG_THEN = (1 << RES_THEN ), |
4664 | FLAG_ELIF = (1 << RES_ELIF ), | 4664 | FLAG_ELIF = (1 << RES_ELIF ), |
4665 | FLAG_ELSE = (1 << RES_ELSE ), | 4665 | FLAG_ELSE = (1 << RES_ELSE ), |
4666 | FLAG_FI = (1 << RES_FI ), | 4666 | FLAG_FI = (1 << RES_FI ), |
4667 | #endif | 4667 | # endif |
4668 | #if ENABLE_HUSH_LOOPS | 4668 | # if ENABLE_HUSH_LOOPS |
4669 | FLAG_FOR = (1 << RES_FOR ), | 4669 | FLAG_FOR = (1 << RES_FOR ), |
4670 | FLAG_WHILE = (1 << RES_WHILE), | 4670 | FLAG_WHILE = (1 << RES_WHILE), |
4671 | FLAG_UNTIL = (1 << RES_UNTIL), | 4671 | FLAG_UNTIL = (1 << RES_UNTIL), |
4672 | FLAG_DO = (1 << RES_DO ), | 4672 | FLAG_DO = (1 << RES_DO ), |
4673 | FLAG_DONE = (1 << RES_DONE ), | 4673 | FLAG_DONE = (1 << RES_DONE ), |
4674 | FLAG_IN = (1 << RES_IN ), | 4674 | FLAG_IN = (1 << RES_IN ), |
4675 | #endif | 4675 | # endif |
4676 | #if ENABLE_HUSH_CASE | 4676 | # if ENABLE_HUSH_CASE |
4677 | FLAG_MATCH = (1 << RES_MATCH), | 4677 | FLAG_MATCH = (1 << RES_MATCH), |
4678 | FLAG_ESAC = (1 << RES_ESAC ), | 4678 | FLAG_ESAC = (1 << RES_ESAC ), |
4679 | #endif | 4679 | # endif |
4680 | FLAG_START = (1 << RES_XXXX ), | 4680 | FLAG_START = (1 << RES_XXXX ), |
4681 | }; | 4681 | }; |
4682 | 4682 | ||
@@ -4688,26 +4688,26 @@ static const struct reserved_combo* match_reserved_word(o_string *word) | |||
4688 | * FLAG_START means the word must start a new compound list. | 4688 | * FLAG_START means the word must start a new compound list. |
4689 | */ | 4689 | */ |
4690 | static const struct reserved_combo reserved_list[] = { | 4690 | static const struct reserved_combo reserved_list[] = { |
4691 | #if ENABLE_HUSH_IF | 4691 | # if ENABLE_HUSH_IF |
4692 | { "!", RES_NONE, NOT_ASSIGNMENT , 0 }, | 4692 | { "!", RES_NONE, NOT_ASSIGNMENT , 0 }, |
4693 | { "if", RES_IF, WORD_IS_KEYWORD, FLAG_THEN | FLAG_START }, | 4693 | { "if", RES_IF, WORD_IS_KEYWORD, FLAG_THEN | FLAG_START }, |
4694 | { "then", RES_THEN, WORD_IS_KEYWORD, FLAG_ELIF | FLAG_ELSE | FLAG_FI }, | 4694 | { "then", RES_THEN, WORD_IS_KEYWORD, FLAG_ELIF | FLAG_ELSE | FLAG_FI }, |
4695 | { "elif", RES_ELIF, WORD_IS_KEYWORD, FLAG_THEN }, | 4695 | { "elif", RES_ELIF, WORD_IS_KEYWORD, FLAG_THEN }, |
4696 | { "else", RES_ELSE, WORD_IS_KEYWORD, FLAG_FI }, | 4696 | { "else", RES_ELSE, WORD_IS_KEYWORD, FLAG_FI }, |
4697 | { "fi", RES_FI, NOT_ASSIGNMENT , FLAG_END }, | 4697 | { "fi", RES_FI, NOT_ASSIGNMENT , FLAG_END }, |
4698 | #endif | 4698 | # endif |
4699 | #if ENABLE_HUSH_LOOPS | 4699 | # if ENABLE_HUSH_LOOPS |
4700 | { "for", RES_FOR, NOT_ASSIGNMENT , FLAG_IN | FLAG_DO | FLAG_START }, | 4700 | { "for", RES_FOR, NOT_ASSIGNMENT , FLAG_IN | FLAG_DO | FLAG_START }, |
4701 | { "while", RES_WHILE, WORD_IS_KEYWORD, FLAG_DO | FLAG_START }, | 4701 | { "while", RES_WHILE, WORD_IS_KEYWORD, FLAG_DO | FLAG_START }, |
4702 | { "until", RES_UNTIL, WORD_IS_KEYWORD, FLAG_DO | FLAG_START }, | 4702 | { "until", RES_UNTIL, WORD_IS_KEYWORD, FLAG_DO | FLAG_START }, |
4703 | { "in", RES_IN, NOT_ASSIGNMENT , FLAG_DO }, | 4703 | { "in", RES_IN, NOT_ASSIGNMENT , FLAG_DO }, |
4704 | { "do", RES_DO, WORD_IS_KEYWORD, FLAG_DONE }, | 4704 | { "do", RES_DO, WORD_IS_KEYWORD, FLAG_DONE }, |
4705 | { "done", RES_DONE, NOT_ASSIGNMENT , FLAG_END }, | 4705 | { "done", RES_DONE, NOT_ASSIGNMENT , FLAG_END }, |
4706 | #endif | 4706 | # endif |
4707 | #if ENABLE_HUSH_CASE | 4707 | # if ENABLE_HUSH_CASE |
4708 | { "case", RES_CASE, NOT_ASSIGNMENT , FLAG_MATCH | FLAG_START }, | 4708 | { "case", RES_CASE, NOT_ASSIGNMENT , FLAG_MATCH | FLAG_START }, |
4709 | { "esac", RES_ESAC, NOT_ASSIGNMENT , FLAG_END }, | 4709 | { "esac", RES_ESAC, NOT_ASSIGNMENT , FLAG_END }, |
4710 | #endif | 4710 | # endif |
4711 | }; | 4711 | }; |
4712 | const struct reserved_combo *r; | 4712 | const struct reserved_combo *r; |
4713 | 4713 | ||
@@ -4721,11 +4721,11 @@ static const struct reserved_combo* match_reserved_word(o_string *word) | |||
4721 | */ | 4721 | */ |
4722 | static int reserved_word(o_string *word, struct parse_context *ctx) | 4722 | static int reserved_word(o_string *word, struct parse_context *ctx) |
4723 | { | 4723 | { |
4724 | #if ENABLE_HUSH_CASE | 4724 | # if ENABLE_HUSH_CASE |
4725 | static const struct reserved_combo reserved_match = { | 4725 | static const struct reserved_combo reserved_match = { |
4726 | "", RES_MATCH, NOT_ASSIGNMENT , FLAG_MATCH | FLAG_ESAC | 4726 | "", RES_MATCH, NOT_ASSIGNMENT , FLAG_MATCH | FLAG_ESAC |
4727 | }; | 4727 | }; |
4728 | #endif | 4728 | # endif |
4729 | const struct reserved_combo *r; | 4729 | const struct reserved_combo *r; |
4730 | 4730 | ||
4731 | if (word->o_quoted) | 4731 | if (word->o_quoted) |
@@ -4735,12 +4735,12 @@ static int reserved_word(o_string *word, struct parse_context *ctx) | |||
4735 | return 0; | 4735 | return 0; |
4736 | 4736 | ||
4737 | debug_printf("found reserved word %s, res %d\n", r->literal, r->res); | 4737 | debug_printf("found reserved word %s, res %d\n", r->literal, r->res); |
4738 | #if ENABLE_HUSH_CASE | 4738 | # if ENABLE_HUSH_CASE |
4739 | if (r->res == RES_IN && ctx->ctx_res_w == RES_CASE_IN) { | 4739 | if (r->res == RES_IN && ctx->ctx_res_w == RES_CASE_IN) { |
4740 | /* "case word IN ..." - IN part starts first MATCH part */ | 4740 | /* "case word IN ..." - IN part starts first MATCH part */ |
4741 | r = &reserved_match; | 4741 | r = &reserved_match; |
4742 | } else | 4742 | } else |
4743 | #endif | 4743 | # endif |
4744 | if (r->flag == 0) { /* '!' */ | 4744 | if (r->flag == 0) { /* '!' */ |
4745 | if (ctx->ctx_inverted) { /* bash doesn't accept '! ! true' */ | 4745 | if (ctx->ctx_inverted) { /* bash doesn't accept '! ! true' */ |
4746 | syntax_error("! ! command"); | 4746 | syntax_error("! ! command"); |
@@ -4781,19 +4781,19 @@ static int reserved_word(o_string *word, struct parse_context *ctx) | |||
4781 | old = ctx->stack; | 4781 | old = ctx->stack; |
4782 | old->command->group = ctx->list_head; | 4782 | old->command->group = ctx->list_head; |
4783 | old->command->cmd_type = CMD_NORMAL; | 4783 | old->command->cmd_type = CMD_NORMAL; |
4784 | #if !BB_MMU | 4784 | # if !BB_MMU |
4785 | o_addstr(&old->as_string, ctx->as_string.data); | 4785 | o_addstr(&old->as_string, ctx->as_string.data); |
4786 | o_free_unsafe(&ctx->as_string); | 4786 | o_free_unsafe(&ctx->as_string); |
4787 | old->command->group_as_string = xstrdup(old->as_string.data); | 4787 | old->command->group_as_string = xstrdup(old->as_string.data); |
4788 | debug_printf_parse("pop, remembering as:'%s'\n", | 4788 | debug_printf_parse("pop, remembering as:'%s'\n", |
4789 | old->command->group_as_string); | 4789 | old->command->group_as_string); |
4790 | #endif | 4790 | # endif |
4791 | *ctx = *old; /* physical copy */ | 4791 | *ctx = *old; /* physical copy */ |
4792 | free(old); | 4792 | free(old); |
4793 | } | 4793 | } |
4794 | return 1; | 4794 | return 1; |
4795 | } | 4795 | } |
4796 | #endif | 4796 | #endif /* HAS_KEYWORDS */ |
4797 | 4797 | ||
4798 | /* Word is complete, look at it and update parsing context. | 4798 | /* Word is complete, look at it and update parsing context. |
4799 | * Normal return is 0. Syntax errors return 1. | 4799 | * Normal return is 0. Syntax errors return 1. |
@@ -5200,9 +5200,9 @@ static FILE *generate_stream_from_string(const char *s) | |||
5200 | { | 5200 | { |
5201 | FILE *pf; | 5201 | FILE *pf; |
5202 | int pid, channel[2]; | 5202 | int pid, channel[2]; |
5203 | #if !BB_MMU | 5203 | # if !BB_MMU |
5204 | char **to_free; | 5204 | char **to_free; |
5205 | #endif | 5205 | # endif |
5206 | 5206 | ||
5207 | xpipe(channel); | 5207 | xpipe(channel); |
5208 | pid = BB_MMU ? fork() : vfork(); | 5208 | pid = BB_MMU ? fork() : vfork(); |
@@ -5266,11 +5266,11 @@ static FILE *generate_stream_from_string(const char *s) | |||
5266 | builtin_trap((char**)argv); | 5266 | builtin_trap((char**)argv); |
5267 | exit(0); /* not _exit() - we need to fflush */ | 5267 | exit(0); /* not _exit() - we need to fflush */ |
5268 | } | 5268 | } |
5269 | #if BB_MMU | 5269 | # if BB_MMU |
5270 | reset_traps_to_defaults(); | 5270 | reset_traps_to_defaults(); |
5271 | parse_and_run_string(s); | 5271 | parse_and_run_string(s); |
5272 | _exit(G.last_exitcode); | 5272 | _exit(G.last_exitcode); |
5273 | #else | 5273 | # else |
5274 | /* We re-execute after vfork on NOMMU. This makes this script safe: | 5274 | /* We re-execute after vfork on NOMMU. This makes this script safe: |
5275 | * yes "0123456789012345678901234567890" | dd bs=32 count=64k >BIG | 5275 | * yes "0123456789012345678901234567890" | dd bs=32 count=64k >BIG |
5276 | * huge=`cat BIG` # was blocking here forever | 5276 | * huge=`cat BIG` # was blocking here forever |
@@ -5281,18 +5281,18 @@ static FILE *generate_stream_from_string(const char *s) | |||
5281 | G.global_argv[0], | 5281 | G.global_argv[0], |
5282 | G.global_argv + 1, | 5282 | G.global_argv + 1, |
5283 | NULL); | 5283 | NULL); |
5284 | #endif | 5284 | # endif |
5285 | } | 5285 | } |
5286 | 5286 | ||
5287 | /* parent */ | 5287 | /* parent */ |
5288 | #if ENABLE_HUSH_FAST | 5288 | # if ENABLE_HUSH_FAST |
5289 | G.count_SIGCHLD++; | 5289 | G.count_SIGCHLD++; |
5290 | //bb_error_msg("[%d] fork in generate_stream_from_string: G.count_SIGCHLD:%d G.handled_SIGCHLD:%d", getpid(), G.count_SIGCHLD, G.handled_SIGCHLD); | 5290 | //bb_error_msg("[%d] fork in generate_stream_from_string: G.count_SIGCHLD:%d G.handled_SIGCHLD:%d", getpid(), G.count_SIGCHLD, G.handled_SIGCHLD); |
5291 | #endif | 5291 | # endif |
5292 | enable_restore_tty_pgrp_on_exit(); | 5292 | enable_restore_tty_pgrp_on_exit(); |
5293 | #if !BB_MMU | 5293 | # if !BB_MMU |
5294 | free(to_free); | 5294 | free(to_free); |
5295 | #endif | 5295 | # endif |
5296 | close(channel[1]); | 5296 | close(channel[1]); |
5297 | pf = fdopen(channel[0], "r"); | 5297 | pf = fdopen(channel[0], "r"); |
5298 | return pf; | 5298 | return pf; |
@@ -5336,7 +5336,7 @@ static int process_command_subs(o_string *dest, const char *s) | |||
5336 | debug_printf("closed FILE from child. return 0\n"); | 5336 | debug_printf("closed FILE from child. return 0\n"); |
5337 | return 0; | 5337 | return 0; |
5338 | } | 5338 | } |
5339 | #endif | 5339 | #endif /* ENABLE_HUSH_TICK */ |
5340 | 5340 | ||
5341 | static int parse_group(o_string *dest, struct parse_context *ctx, | 5341 | static int parse_group(o_string *dest, struct parse_context *ctx, |
5342 | struct in_str *input, int ch) | 5342 | struct in_str *input, int ch) |
@@ -5704,7 +5704,7 @@ static int handle_dollar(o_string *as_string, | |||
5704 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 5704 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
5705 | break; | 5705 | break; |
5706 | } | 5706 | } |
5707 | #if (ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_TICK) | 5707 | #if ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_TICK |
5708 | case '(': { | 5708 | case '(': { |
5709 | # if !BB_MMU | 5709 | # if !BB_MMU |
5710 | int pos; | 5710 | int pos; |
@@ -6169,8 +6169,9 @@ static struct pipe *parse_stream(char **pstring, | |||
6169 | /* Example: echo Hello \2>file | 6169 | /* Example: echo Hello \2>file |
6170 | * we need to know that word 2 is quoted */ | 6170 | * we need to know that word 2 is quoted */ |
6171 | dest.o_quoted = 1; | 6171 | dest.o_quoted = 1; |
6172 | } else { | 6172 | } |
6173 | #if !BB_MMU | 6173 | #if !BB_MMU |
6174 | else { | ||
6174 | /* It's "\<newline>". Remove trailing '\' from ctx.as_string */ | 6175 | /* It's "\<newline>". Remove trailing '\' from ctx.as_string */ |
6175 | ctx.as_string.data[--ctx.as_string.length] = '\0'; | 6176 | ctx.as_string.data[--ctx.as_string.length] = '\0'; |
6176 | #endif | 6177 | #endif |
@@ -6914,30 +6915,30 @@ static int FAST_FUNC builtin_true(char **argv UNUSED_PARAM) | |||
6914 | return 0; | 6915 | return 0; |
6915 | } | 6916 | } |
6916 | 6917 | ||
6917 | static int FAST_FUNC _builtin_applet(char **argv, int (applet)(int argc, char **argv)) | 6918 | static int FAST_FUNC run_applet_main(char **argv, int (*applet_main)(int argc, char **argv)) |
6918 | { | 6919 | { |
6919 | int argc = 0; | 6920 | int argc = 0; |
6920 | while (*argv) { | 6921 | while (*argv) { |
6921 | argc++; | 6922 | argc++; |
6922 | argv++; | 6923 | argv++; |
6923 | } | 6924 | } |
6924 | return applet(argc, argv - argc); | 6925 | return applet_main(argc, argv - argc); |
6925 | } | 6926 | } |
6926 | 6927 | ||
6927 | static int FAST_FUNC builtin_test(char **argv) | 6928 | static int FAST_FUNC builtin_test(char **argv) |
6928 | { | 6929 | { |
6929 | return _builtin_applet(argv, test_main); | 6930 | return run_applet_main(argv, test_main); |
6930 | } | 6931 | } |
6931 | 6932 | ||
6932 | static int FAST_FUNC builtin_echo(char **argv) | 6933 | static int FAST_FUNC builtin_echo(char **argv) |
6933 | { | 6934 | { |
6934 | return _builtin_applet(argv, echo_main); | 6935 | return run_applet_main(argv, echo_main); |
6935 | } | 6936 | } |
6936 | 6937 | ||
6937 | #if ENABLE_PRINTF | 6938 | #if ENABLE_PRINTF |
6938 | static int FAST_FUNC builtin_printf(char **argv) | 6939 | static int FAST_FUNC builtin_printf(char **argv) |
6939 | { | 6940 | { |
6940 | return _builtin_applet(argv, printf_main); | 6941 | return run_applet_main(argv, printf_main); |
6941 | } | 6942 | } |
6942 | #endif | 6943 | #endif |
6943 | 6944 | ||
@@ -7395,10 +7396,10 @@ static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM) | |||
7395 | void *p; | 7396 | void *p; |
7396 | unsigned long l; | 7397 | unsigned long l; |
7397 | 7398 | ||
7398 | #ifdef M_TRIM_THRESHOLD | 7399 | # ifdef M_TRIM_THRESHOLD |
7399 | /* Optional. Reduces probability of false positives */ | 7400 | /* Optional. Reduces probability of false positives */ |
7400 | malloc_trim(0); | 7401 | malloc_trim(0); |
7401 | #endif | 7402 | # endif |
7402 | /* Crude attempt to find where "free memory" starts, | 7403 | /* Crude attempt to find where "free memory" starts, |
7403 | * sans fragmentation. */ | 7404 | * sans fragmentation. */ |
7404 | p = malloc(240); | 7405 | p = malloc(240); |