aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shell/hush.c70
1 files changed, 27 insertions, 43 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 707b77c9c..6b6ec7c6b 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -390,7 +390,6 @@
390#define BASH_TEST2 (ENABLE_HUSH_BASH_COMPAT && ENABLE_HUSH_TEST) 390#define BASH_TEST2 (ENABLE_HUSH_BASH_COMPAT && ENABLE_HUSH_TEST)
391#define BASH_READ_D ENABLE_HUSH_BASH_COMPAT 391#define BASH_READ_D ENABLE_HUSH_BASH_COMPAT
392 392
393
394/* Build knobs */ 393/* Build knobs */
395#define LEAK_HUNTING 0 394#define LEAK_HUNTING 0
396#define BUILD_AS_NOMMU 0 395#define BUILD_AS_NOMMU 0
@@ -411,7 +410,6 @@
411 */ 410 */
412#define ENABLE_HUSH_DOLLAR_OPS 1 411#define ENABLE_HUSH_DOLLAR_OPS 1
413 412
414
415#if BUILD_AS_NOMMU 413#if BUILD_AS_NOMMU
416# undef BB_MMU 414# undef BB_MMU
417# undef USE_FOR_NOMMU 415# undef USE_FOR_NOMMU
@@ -640,7 +638,6 @@ typedef enum redir_type {
640 HEREDOC_QUOTED = 2, 638 HEREDOC_QUOTED = 2,
641} redir_type; 639} redir_type;
642 640
643
644struct command { 641struct command {
645 pid_t pid; /* 0 if exited */ 642 pid_t pid; /* 0 if exited */
646 unsigned assignment_cnt; /* how many argv[i] are assignments? */ 643 unsigned assignment_cnt; /* how many argv[i] are assignments? */
@@ -798,7 +795,6 @@ struct function {
798}; 795};
799#endif 796#endif
800 797
801
802/* set -/+o OPT support. (TODO: make it optional) 798/* set -/+o OPT support. (TODO: make it optional)
803 * bash supports the following opts: 799 * bash supports the following opts:
804 * allexport off 800 * allexport off
@@ -1046,7 +1042,6 @@ struct globals {
1046 G.sa.sa_flags = SA_RESTART; \ 1042 G.sa.sa_flags = SA_RESTART; \
1047} while (0) 1043} while (0)
1048 1044
1049
1050/* Function prototypes for builtins */ 1045/* Function prototypes for builtins */
1051static int builtin_cd(char **argv) FAST_FUNC; 1046static int builtin_cd(char **argv) FAST_FUNC;
1052#if ENABLE_HUSH_ECHO 1047#if ENABLE_HUSH_ECHO
@@ -1248,8 +1243,8 @@ static const struct built_in_command bltins2[] ALIGN_PTR = {
1248#endif 1243#endif
1249}; 1244};
1250 1245
1251 1246/*
1252/* Debug printouts. 1247 * Debug printouts.
1253 */ 1248 */
1254#if HUSH_DEBUG >= 2 1249#if HUSH_DEBUG >= 2
1255/* prevent disasters with G.debug_indent < 0 */ 1250/* prevent disasters with G.debug_indent < 0 */
@@ -1342,8 +1337,8 @@ static void debug_print_strings(const char *prefix, char **vv)
1342# define debug_print_strings(prefix, vv) ((void)0) 1337# define debug_print_strings(prefix, vv) ((void)0)
1343#endif 1338#endif
1344 1339
1345 1340/*
1346/* Leak hunting. Use hush_leaktool.sh for post-processing. 1341 * Leak hunting. Use hush_leaktool.sh for post-processing.
1347 */ 1342 */
1348#if LEAK_HUNTING 1343#if LEAK_HUNTING
1349static void *xxmalloc(int lineno, size_t size) 1344static void *xxmalloc(int lineno, size_t size)
@@ -1375,8 +1370,8 @@ static void xxfree(void *ptr)
1375# define free(p) xxfree(p) 1370# define free(p) xxfree(p)
1376#endif 1371#endif
1377 1372
1378 1373/*
1379/* Syntax and runtime errors. They always abort scripts. 1374 * Syntax and runtime errors. They always abort scripts.
1380 * In interactive use they usually discard unparsed and/or unexecuted commands 1375 * In interactive use they usually discard unparsed and/or unexecuted commands
1381 * and return to the prompt. 1376 * and return to the prompt.
1382 * HUSH_DEBUG >= 2 prints line number in this file where it was detected. 1377 * HUSH_DEBUG >= 2 prints line number in this file where it was detected.
@@ -1469,8 +1464,8 @@ static void syntax_error_unexpected_ch(unsigned lineno UNUSED_PARAM, int ch)
1469# define syntax_error_unexpected_ch(ch) syntax_error_unexpected_ch(__LINE__, ch) 1464# define syntax_error_unexpected_ch(ch) syntax_error_unexpected_ch(__LINE__, ch)
1470#endif 1465#endif
1471 1466
1472 1467/*
1473/* Utility functions 1468 * Utility functions
1474 */ 1469 */
1475/* Replace each \x with x in place, return ptr past NUL. */ 1470/* Replace each \x with x in place, return ptr past NUL. */
1476static char *unbackslash(char *src) 1471static char *unbackslash(char *src)
@@ -1616,8 +1611,9 @@ static int xdup_CLOEXEC_and_close(int fd, int avoid_fd)
1616 return newfd; 1611 return newfd;
1617} 1612}
1618 1613
1619 1614/*
1620/* Manipulating HFILEs */ 1615 * Manipulating HFILEs
1616 */
1621static HFILE *hfopen(const char *name) 1617static HFILE *hfopen(const char *name)
1622{ 1618{
1623 HFILE *fp; 1619 HFILE *fp;
@@ -1763,8 +1759,8 @@ static int fd_in_HFILEs(int fd)
1763 return 0; 1759 return 0;
1764} 1760}
1765 1761
1766 1762/*
1767/* Helpers for setting new $n and restoring them back 1763 * Helpers for setting new $n and restoring them back
1768 */ 1764 */
1769typedef struct save_arg_t { 1765typedef struct save_arg_t {
1770 char *sv_argv0; 1766 char *sv_argv0;
@@ -1804,8 +1800,8 @@ static void restore_G_args(save_arg_t *sv, char **argv)
1804 IF_HUSH_SET(G.global_args_malloced = sv->sv_g_malloced;) 1800 IF_HUSH_SET(G.global_args_malloced = sv->sv_g_malloced;)
1805} 1801}
1806 1802
1807 1803/*
1808/* Basic theory of signal handling in shell 1804 * Basic theory of signal handling in shell
1809 * ======================================== 1805 * ========================================
1810 * This does not describe what hush does, rather, it is current understanding 1806 * This does not describe what hush does, rather, it is current understanding
1811 * what it _should_ do. If it doesn't, it's a bug. 1807 * what it _should_ do. If it doesn't, it's a bug.
@@ -2246,7 +2242,9 @@ static int check_and_run_traps(void)
2246 return last_sig; 2242 return last_sig;
2247} 2243}
2248 2244
2249 2245/*
2246 * Shell and environment variable support
2247 */
2250static const char *get_cwd(int force) 2248static const char *get_cwd(int force)
2251{ 2249{
2252 if (force || G.cwd == NULL) { 2250 if (force || G.cwd == NULL) {
@@ -2261,10 +2259,6 @@ static const char *get_cwd(int force)
2261 return G.cwd; 2259 return G.cwd;
2262} 2260}
2263 2261
2264
2265/*
2266 * Shell and environment variable support
2267 */
2268static struct variable **get_ptr_to_local_var(const char *name) 2262static struct variable **get_ptr_to_local_var(const char *name)
2269{ 2263{
2270 struct variable **pp; 2264 struct variable **pp;
@@ -2538,7 +2532,6 @@ static int unset_local_var(const char *name)
2538} 2532}
2539#endif 2533#endif
2540 2534
2541
2542/* 2535/*
2543 * Helpers for "var1=val1 var2=val2 cmd" feature 2536 * Helpers for "var1=val1 var2=val2 cmd" feature
2544 */ 2537 */
@@ -2612,7 +2605,6 @@ static void set_vars_and_save_old(char **strings)
2612 free(strings); 2605 free(strings);
2613} 2606}
2614 2607
2615
2616/* 2608/*
2617 * Unicode helper 2609 * Unicode helper
2618 */ 2610 */
@@ -2971,7 +2963,6 @@ static void setup_string_in_str(struct in_str *i, const char *s)
2971 i->p = s; 2963 i->p = s;
2972} 2964}
2973 2965
2974
2975/* 2966/*
2976 * o_string support 2967 * o_string support
2977 */ 2968 */
@@ -3703,9 +3694,9 @@ static void free_pipe_list(struct pipe *pi)
3703 } 3694 }
3704} 3695}
3705 3696
3706 3697/*
3707/*** Parsing routines ***/ 3698 * Parsing routines
3708 3699 */
3709#ifndef debug_print_tree 3700#ifndef debug_print_tree
3710static void debug_print_tree(struct pipe *pi, int lvl) 3701static void debug_print_tree(struct pipe *pi, int lvl)
3711{ 3702{
@@ -4339,7 +4330,6 @@ static int done_word(struct parse_context *ctx)
4339 return 0; 4330 return 0;
4340} 4331}
4341 4332
4342
4343/* Peek ahead in the input to find out if we have a "&n" construct, 4333/* Peek ahead in the input to find out if we have a "&n" construct,
4344 * as in "2>&1", that represents duplicating a file descriptor. 4334 * as in "2>&1", that represents duplicating a file descriptor.
4345 * Return: 4335 * Return:
@@ -4635,7 +4625,6 @@ static int fetch_heredocs(o_string *as_string, struct pipe *pi, int heredoc_cnt,
4635 return heredoc_cnt; 4625 return heredoc_cnt;
4636} 4626}
4637 4627
4638
4639static int run_list(struct pipe *pi); 4628static int run_list(struct pipe *pi);
4640#if BB_MMU 4629#if BB_MMU
4641#define parse_stream(pstring, heredoc_cnt_ptr, input, end_trigger) \ 4630#define parse_stream(pstring, heredoc_cnt_ptr, input, end_trigger) \
@@ -6082,9 +6071,9 @@ static struct pipe *parse_stream(char **pstring,
6082 } 6071 }
6083} 6072}
6084 6073
6085 6074/*
6086/*** Execution routines ***/ 6075 * Execution routines
6087 6076 */
6088/* Expansion can recurse, need forward decls: */ 6077/* Expansion can recurse, need forward decls: */
6089#if !BASH_PATTERN_SUBST && !ENABLE_HUSH_CASE 6078#if !BASH_PATTERN_SUBST && !ENABLE_HUSH_CASE
6090#define expand_string_to_string(str, EXP_flags, do_unbackslash) \ 6079#define expand_string_to_string(str, EXP_flags, do_unbackslash) \
@@ -7347,7 +7336,6 @@ static char **expand_assignments(char **argv, int count)
7347 return p; 7336 return p;
7348} 7337}
7349 7338
7350
7351static void switch_off_special_sigs(unsigned mask) 7339static void switch_off_special_sigs(unsigned mask)
7352{ 7340{
7353 unsigned sig = 0; 7341 unsigned sig = 0;
@@ -7565,7 +7553,6 @@ static void re_execute_shell(char ***to_free, const char *s,
7565} 7553}
7566#endif /* !BB_MMU */ 7554#endif /* !BB_MMU */
7567 7555
7568
7569static int run_and_free_list(struct pipe *pi); 7556static int run_and_free_list(struct pipe *pi);
7570 7557
7571/* Executing from string: eval, sh -c '...' 7558/* Executing from string: eval, sh -c '...'
@@ -7796,7 +7783,6 @@ static int process_command_subs(o_string *dest, const char *s)
7796} 7783}
7797#endif /* ENABLE_HUSH_TICK */ 7784#endif /* ENABLE_HUSH_TICK */
7798 7785
7799
7800static void setup_heredoc(struct redir_struct *redir) 7786static void setup_heredoc(struct redir_struct *redir)
7801{ 7787{
7802 struct fd_pair pair; 7788 struct fd_pair pair;
@@ -8524,7 +8510,6 @@ static int run_function(const struct function *funcp, char **argv)
8524} 8510}
8525#endif /* ENABLE_HUSH_FUNCTIONS */ 8511#endif /* ENABLE_HUSH_FUNCTIONS */
8526 8512
8527
8528#if BB_MMU 8513#if BB_MMU
8529#define exec_builtin(to_free, x, argv) \ 8514#define exec_builtin(to_free, x, argv) \
8530 exec_builtin(x, argv) 8515 exec_builtin(x, argv)
@@ -8558,7 +8543,6 @@ static void exec_builtin(char ***to_free,
8558#endif 8543#endif
8559} 8544}
8560 8545
8561
8562static void execvp_or_die(char **argv) NORETURN; 8546static void execvp_or_die(char **argv) NORETURN;
8563static void execvp_or_die(char **argv) 8547static void execvp_or_die(char **argv)
8564{ 8548{
@@ -10184,7 +10168,9 @@ static int run_and_free_list(struct pipe *pi)
10184 return rcode; 10168 return rcode;
10185} 10169}
10186 10170
10187 10171/*
10172 * Initialization and main
10173 */
10188static void install_sighandlers(unsigned mask) 10174static void install_sighandlers(unsigned mask)
10189{ 10175{
10190 sighandler_t old_handler; 10176 sighandler_t old_handler;
@@ -10861,7 +10847,6 @@ int hush_main(int argc, char **argv)
10861 hush_exit(G.last_exitcode); 10847 hush_exit(G.last_exitcode);
10862} 10848}
10863 10849
10864
10865/* 10850/*
10866 * Built-ins 10851 * Built-ins
10867 */ 10852 */
@@ -12340,7 +12325,6 @@ static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM)
12340 if (l < (unsigned long)p) l = (unsigned long)p; 12325 if (l < (unsigned long)p) l = (unsigned long)p;
12341 free(p); 12326 free(p);
12342 12327
12343
12344# if 0 /* debug */ 12328# if 0 /* debug */
12345 { 12329 {
12346 struct mallinfo mi = mallinfo(); 12330 struct mallinfo mi = mallinfo();