hush: fix "set -x" output prefix overlapping for v="..cmd
.." case
Was printing initial "+" prefix for the assignment, that printing "+ cmd" then printing the expanded " v=VAL" string. Delay printing of "+" prefix for the assignment to after expansion. function old new delta run_pipe 1883 1902 +19 builtin_eval 127 133 +6 expand_vars_to_list 1103 1106 +3 dump_cmd_in_x_mode 144 142 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 28/-2) Total: 26 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
186cf49767
commit
9dda9270df
34
shell/hush.c
34
shell/hush.c
@ -896,7 +896,6 @@ struct globals {
|
|||||||
|
|
||||||
char o_opt[NUM_OPT_O];
|
char o_opt[NUM_OPT_O];
|
||||||
#if ENABLE_HUSH_MODE_X
|
#if ENABLE_HUSH_MODE_X
|
||||||
smalluint x_mode_depth;
|
|
||||||
# define G_x_mode (G.o_opt[OPT_O_XTRACE])
|
# define G_x_mode (G.o_opt[OPT_O_XTRACE])
|
||||||
#else
|
#else
|
||||||
# define G_x_mode 0
|
# define G_x_mode 0
|
||||||
@ -955,6 +954,9 @@ struct globals {
|
|||||||
unsigned func_nest_level; /* solely to prevent "local v" in non-functions */
|
unsigned func_nest_level; /* solely to prevent "local v" in non-functions */
|
||||||
# endif
|
# endif
|
||||||
struct function *top_func;
|
struct function *top_func;
|
||||||
|
#endif
|
||||||
|
#if ENABLE_HUSH_MODE_X
|
||||||
|
unsigned x_mode_depth;
|
||||||
#endif
|
#endif
|
||||||
/* Signal and trap handling */
|
/* Signal and trap handling */
|
||||||
#if ENABLE_HUSH_FAST
|
#if ENABLE_HUSH_FAST
|
||||||
@ -7247,6 +7249,7 @@ static int generate_stream_from_string(const char *s, pid_t *pid_p)
|
|||||||
CLEAR_RANDOM_T(&G.random_gen); /* or else $RANDOM repeats in child */
|
CLEAR_RANDOM_T(&G.random_gen); /* or else $RANDOM repeats in child */
|
||||||
reset_traps_to_defaults();
|
reset_traps_to_defaults();
|
||||||
IF_HUSH_MODE_X(G.x_mode_depth++;)
|
IF_HUSH_MODE_X(G.x_mode_depth++;)
|
||||||
|
//bb_error_msg("%s: ++x_mode_depth=%d", __func__, G.x_mode_depth);
|
||||||
parse_and_run_string(s);
|
parse_and_run_string(s);
|
||||||
_exit(G.last_exitcode);
|
_exit(G.last_exitcode);
|
||||||
# else
|
# else
|
||||||
@ -8032,17 +8035,16 @@ static void dump_cmd_in_x_mode(char **argv)
|
|||||||
if (G_x_mode && argv) {
|
if (G_x_mode && argv) {
|
||||||
/* We want to output the line in one write op */
|
/* We want to output the line in one write op */
|
||||||
char *buf, *p;
|
char *buf, *p;
|
||||||
int len;
|
unsigned len;
|
||||||
int n;
|
unsigned n;
|
||||||
|
|
||||||
len = G.x_mode_depth + 3; /* "+[+++...]<cmd...>\n\0" */
|
len = G.x_mode_depth + 3; /* "+[+++...][ cmd...]\n\0" */
|
||||||
n = 0;
|
n = 0;
|
||||||
while (argv[n])
|
while (argv[n])
|
||||||
len += strlen(argv[n++]) + 1;
|
len += strlen(argv[n++]) + 1;
|
||||||
p = buf = xmalloc(len);
|
p = buf = xmalloc(len);
|
||||||
n = G.x_mode_depth;
|
n = G.x_mode_depth;
|
||||||
while (n-- >= 0)
|
do *p++ = '+'; while ((int)(--n) >= 0);
|
||||||
*p++ = '+';
|
|
||||||
n = 0;
|
n = 0;
|
||||||
while (argv[n])
|
while (argv[n])
|
||||||
p += sprintf(p, " %s", argv[n++]);
|
p += sprintf(p, " %s", argv[n++]);
|
||||||
@ -8835,21 +8837,23 @@ static NOINLINE int run_pipe(struct pipe *pi)
|
|||||||
restore_redirects(squirrel);
|
restore_redirects(squirrel);
|
||||||
|
|
||||||
/* Set shell variables */
|
/* Set shell variables */
|
||||||
#if ENABLE_HUSH_MODE_X
|
|
||||||
if (G_x_mode) {
|
|
||||||
int n = G.x_mode_depth;
|
|
||||||
while (n-- >= 0)
|
|
||||||
bb_putchar_stderr('+');
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < command->assignment_cnt) {
|
while (i < command->assignment_cnt) {
|
||||||
char *p = expand_string_to_string(argv[i],
|
char *p = expand_string_to_string(argv[i],
|
||||||
EXP_FLAG_ESC_GLOB_CHARS,
|
EXP_FLAG_ESC_GLOB_CHARS,
|
||||||
/*unbackslash:*/ 1
|
/*unbackslash:*/ 1
|
||||||
);
|
);
|
||||||
if (G_x_mode)
|
#if ENABLE_HUSH_MODE_X
|
||||||
|
if (G_x_mode) {
|
||||||
|
if (i == 0) {
|
||||||
|
unsigned n = G.x_mode_depth;
|
||||||
|
do
|
||||||
|
bb_putchar_stderr('+');
|
||||||
|
while ((int)(--n) >= 0);
|
||||||
|
}
|
||||||
fprintf(stderr, " %s", p);
|
fprintf(stderr, " %s", p);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
debug_printf_env("set shell var:'%s'->'%s'\n", *argv, p);
|
debug_printf_env("set shell var:'%s'->'%s'\n", *argv, p);
|
||||||
if (set_local_var(p, /*flag:*/ 0)) {
|
if (set_local_var(p, /*flag:*/ 0)) {
|
||||||
/* assignment to readonly var / putenv error? */
|
/* assignment to readonly var / putenv error? */
|
||||||
@ -10246,6 +10250,7 @@ static int FAST_FUNC builtin_eval(char **argv)
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
IF_HUSH_MODE_X(G.x_mode_depth++;)
|
IF_HUSH_MODE_X(G.x_mode_depth++;)
|
||||||
|
//bb_error_msg("%s: ++x_mode_depth=%d", __func__, G.x_mode_depth);
|
||||||
if (!argv[1]) {
|
if (!argv[1]) {
|
||||||
/* bash:
|
/* bash:
|
||||||
* eval "echo Hi; done" ("done" is syntax error):
|
* eval "echo Hi; done" ("done" is syntax error):
|
||||||
@ -10276,6 +10281,7 @@ static int FAST_FUNC builtin_eval(char **argv)
|
|||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
IF_HUSH_MODE_X(G.x_mode_depth--;)
|
IF_HUSH_MODE_X(G.x_mode_depth--;)
|
||||||
|
//bb_error_msg("%s: --x_mode_depth=%d", __func__, G.x_mode_depth);
|
||||||
return G.last_exitcode;
|
return G.last_exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user