aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-07-26 15:21:50 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-07-26 15:21:50 +0200
commit7c5f18a3bab721cdfa515220ad8d481643aaae23 (patch)
treedf44c85afeae3ad0b247223f0641eef534220f21
parent871bd2abaccd042cba757831fc4461806e8f446d (diff)
downloadbusybox-w32-7c5f18a3bab721cdfa515220ad8d481643aaae23.tar.gz
busybox-w32-7c5f18a3bab721cdfa515220ad8d481643aaae23.tar.bz2
busybox-w32-7c5f18a3bab721cdfa515220ad8d481643aaae23.zip
hush: improve set -x: make "+++" indent level increase in `cmd` and eval.
function old new delta dump_cmd_in_x_mode 126 144 +18 run_pipe 1873 1883 +10 builtin_eval 119 127 +8 expand_vars_to_list 1100 1103 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 39/0) Total: 39 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/shell/hush.c b/shell/hush.c
index e3c6e2de9..02fb1b5ef 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -896,6 +896,7 @@ struct globals {
896 896
897 char o_opt[NUM_OPT_O]; 897 char o_opt[NUM_OPT_O];
898#if ENABLE_HUSH_MODE_X 898#if ENABLE_HUSH_MODE_X
899 smalluint x_mode_depth;
899# define G_x_mode (G.o_opt[OPT_O_XTRACE]) 900# define G_x_mode (G.o_opt[OPT_O_XTRACE])
900#else 901#else
901# define G_x_mode 0 902# define G_x_mode 0
@@ -7182,11 +7183,8 @@ static int generate_stream_from_string(const char *s, pid_t *pid_p)
7182 + (1 << SIGTTIN) 7183 + (1 << SIGTTIN)
7183 + (1 << SIGTTOU) 7184 + (1 << SIGTTOU)
7184 , SIG_IGN); 7185 , SIG_IGN);
7185 CLEAR_RANDOM_T(&G.random_gen); /* or else $RANDOM repeats in child */
7186 close(channel[0]); /* NB: close _first_, then move fd! */ 7186 close(channel[0]); /* NB: close _first_, then move fd! */
7187 xmove_fd(channel[1], 1); 7187 xmove_fd(channel[1], 1);
7188 /* Prevent it from trying to handle ctrl-z etc */
7189 IF_HUSH_JOB(G.run_list_level = 1;)
7190# if ENABLE_HUSH_TRAP 7188# if ENABLE_HUSH_TRAP
7191 /* Awful hack for `trap` or $(trap). 7189 /* Awful hack for `trap` or $(trap).
7192 * 7190 *
@@ -7233,7 +7231,11 @@ static int generate_stream_from_string(const char *s, pid_t *pid_p)
7233 } 7231 }
7234# endif 7232# endif
7235# if BB_MMU 7233# if BB_MMU
7234 /* Prevent it from trying to handle ctrl-z etc */
7235 IF_HUSH_JOB(G.run_list_level = 1;)
7236 CLEAR_RANDOM_T(&G.random_gen); /* or else $RANDOM repeats in child */
7236 reset_traps_to_defaults(); 7237 reset_traps_to_defaults();
7238 IF_HUSH_MODE_X(G.x_mode_depth++;)
7237 parse_and_run_string(s); 7239 parse_and_run_string(s);
7238 _exit(G.last_exitcode); 7240 _exit(G.last_exitcode);
7239# else 7241# else
@@ -8022,13 +8024,14 @@ static void dump_cmd_in_x_mode(char **argv)
8022 int len; 8024 int len;
8023 int n; 8025 int n;
8024 8026
8025 len = 3; 8027 len = G.x_mode_depth + 3; /* "+[+++...]<cmd...>\n\0" */
8026 n = 0; 8028 n = 0;
8027 while (argv[n]) 8029 while (argv[n])
8028 len += strlen(argv[n++]) + 1; 8030 len += strlen(argv[n++]) + 1;
8029 buf = xmalloc(len); 8031 p = buf = xmalloc(len);
8030 buf[0] = '+'; 8032 n = G.x_mode_depth;
8031 p = buf + 1; 8033 while (n-- >= 0)
8034 *p++ = '+';
8032 n = 0; 8035 n = 0;
8033 while (argv[n]) 8036 while (argv[n])
8034 p += sprintf(p, " %s", argv[n++]); 8037 p += sprintf(p, " %s", argv[n++]);
@@ -8821,8 +8824,13 @@ static NOINLINE int run_pipe(struct pipe *pi)
8821 restore_redirects(squirrel); 8824 restore_redirects(squirrel);
8822 8825
8823 /* Set shell variables */ 8826 /* Set shell variables */
8824 if (G_x_mode) 8827#if ENABLE_HUSH_MODE_X
8825 bb_putchar_stderr('+'); 8828 if (G_x_mode) {
8829 int n = G.x_mode_depth;
8830 while (n-- >= 0)
8831 bb_putchar_stderr('+');
8832 }
8833#endif
8826 i = 0; 8834 i = 0;
8827 while (i < command->assignment_cnt) { 8835 while (i < command->assignment_cnt) {
8828 char *p = expand_string_to_string(argv[i], 8836 char *p = expand_string_to_string(argv[i],
@@ -10226,6 +10234,7 @@ static int FAST_FUNC builtin_eval(char **argv)
10226 if (!argv[0]) 10234 if (!argv[0])
10227 return EXIT_SUCCESS; 10235 return EXIT_SUCCESS;
10228 10236
10237 IF_HUSH_MODE_X(G.x_mode_depth++;)
10229 if (!argv[1]) { 10238 if (!argv[1]) {
10230 /* bash: 10239 /* bash:
10231 * eval "echo Hi; done" ("done" is syntax error): 10240 * eval "echo Hi; done" ("done" is syntax error):
@@ -10255,6 +10264,7 @@ static int FAST_FUNC builtin_eval(char **argv)
10255 parse_and_run_string(str); 10264 parse_and_run_string(str);
10256 free(str); 10265 free(str);
10257 } 10266 }
10267 IF_HUSH_MODE_X(G.x_mode_depth--;)
10258 return G.last_exitcode; 10268 return G.last_exitcode;
10259} 10269}
10260 10270