Use STDERR_FILENO rather than 2 in debug print statements, so they'll properly go to stderr on GNO.

This commit is contained in:
Stephen Heumann 2014-11-03 19:20:20 -06:00
parent 32e9dccc33
commit 9850090331

View File

@ -975,7 +975,7 @@ static const struct built_in_command bltins2[] = {
*/ */
#if HUSH_DEBUG #if HUSH_DEBUG
/* prevent disasters with G.debug_indent < 0 */ /* prevent disasters with G.debug_indent < 0 */
# define indent() fdprintf(2, "%*s", (G.debug_indent * 2) & 0xff, "") # define indent() fdprintf(STDERR_FILENO, "%*s", (G.debug_indent * 2) & 0xff, "")
# define debug_enter() (G.debug_indent++) # define debug_enter() (G.debug_indent++)
# define debug_leave() (G.debug_indent--) # define debug_leave() (G.debug_indent--)
#else #else
@ -1061,9 +1061,9 @@ static void real_debug_printf(const char *fmt, ...) {
static void debug_print_strings(const char *prefix, char **vv) static void debug_print_strings(const char *prefix, char **vv)
{ {
indent(); indent();
fdprintf(2, "%s:\n", prefix); fdprintf(STDERR_FILENO, "%s:\n", prefix);
while (*vv) while (*vv)
fdprintf(2, " '%s'\n", *vv++); fdprintf(STDERR_FILENO, " '%s'\n", *vv++);
} }
#else #else
# define debug_print_strings(prefix, vv) ((void)0) # define debug_print_strings(prefix, vv) ((void)0)
@ -1076,24 +1076,24 @@ static void debug_print_strings(const char *prefix, char **vv)
static void *xxmalloc(int lineno, size_t size) static void *xxmalloc(int lineno, size_t size)
{ {
void *ptr = xmalloc((size + 0xff) & ~0xff); void *ptr = xmalloc((size + 0xff) & ~0xff);
fdprintf(2, "line %d: malloc %p\n", lineno, ptr); fdprintf(STDERR_FILENO, "line %d: malloc %p\n", lineno, ptr);
return ptr; return ptr;
} }
static void *xxrealloc(int lineno, void *ptr, size_t size) static void *xxrealloc(int lineno, void *ptr, size_t size)
{ {
ptr = xrealloc(ptr, (size + 0xff) & ~0xff); ptr = xrealloc(ptr, (size + 0xff) & ~0xff);
fdprintf(2, "line %d: realloc %p\n", lineno, ptr); fdprintf(STDERR_FILENO, "line %d: realloc %p\n", lineno, ptr);
return ptr; return ptr;
} }
static char *xxstrdup(int lineno, const char *str) static char *xxstrdup(int lineno, const char *str)
{ {
char *ptr = xstrdup(str); char *ptr = xstrdup(str);
fdprintf(2, "line %d: strdup %p\n", lineno, ptr); fdprintf(STDERR_FILENO, "line %d: strdup %p\n", lineno, ptr);
return ptr; return ptr;
} }
static void xxfree(void *ptr) static void xxfree(void *ptr)
{ {
fdprintf(2, "free %p\n", ptr); fdprintf(STDERR_FILENO, "free %p\n", ptr);
free(ptr); free(ptr);
} }
# define xmalloc(s) xxmalloc(__LINE__, s) # define xmalloc(s) xxmalloc(__LINE__, s)
@ -1231,7 +1231,7 @@ static char **add_strings_to_strings(char **strings, char **add, int need_to_dup
static char **xx_add_strings_to_strings(int lineno, char **strings, char **add, int need_to_dup) static char **xx_add_strings_to_strings(int lineno, char **strings, char **add, int need_to_dup)
{ {
char **ptr = add_strings_to_strings(strings, add, need_to_dup); char **ptr = add_strings_to_strings(strings, add, need_to_dup);
fdprintf(2, "line %d: add_strings_to_strings %p\n", lineno, ptr); fdprintf(STDERR_FILENO, "line %d: add_strings_to_strings %p\n", lineno, ptr);
return ptr; return ptr;
} }
#define add_strings_to_strings(strings, add, need_to_dup) \ #define add_strings_to_strings(strings, add, need_to_dup) \
@ -1250,7 +1250,7 @@ static char **add_string_to_strings(char **strings, char *add)
static char **xx_add_string_to_strings(int lineno, char **strings, char *add) static char **xx_add_string_to_strings(int lineno, char **strings, char *add)
{ {
char **ptr = add_string_to_strings(strings, add); char **ptr = add_string_to_strings(strings, add);
fdprintf(2, "line %d: add_string_to_strings %p\n", lineno, ptr); fdprintf(STDERR_FILENO, "line %d: add_string_to_strings %p\n", lineno, ptr);
return ptr; return ptr;
} }
#define add_string_to_strings(strings, add) \ #define add_string_to_strings(strings, add) \
@ -2376,14 +2376,14 @@ static void debug_print_list(const char *prefix, o_string *o, int n)
int i = 0; int i = 0;
indent(); indent();
fdprintf(2, "%s: list:%p n:%d string_start:%d length:%d maxlen:%d glob:%d quoted:%d escape:%d\n", fdprintf(STDERR_FILENO, "%s: list:%p n:%d string_start:%d length:%d maxlen:%d glob:%d quoted:%d escape:%d\n",
prefix, list, n, string_start, o->length, o->maxlen, prefix, list, n, string_start, o->length, o->maxlen,
!!(o->o_expflags & EXP_FLAG_GLOB), !!(o->o_expflags & EXP_FLAG_GLOB),
o->has_quoted_part, o->has_quoted_part,
!!(o->o_expflags & EXP_FLAG_ESC_GLOB_CHARS)); !!(o->o_expflags & EXP_FLAG_ESC_GLOB_CHARS));
while (i < n) { while (i < n) {
indent(); indent();
fdprintf(2, " list[%d]=%d '%s' %p\n", i, (int)(uintptr_t)list[i], fdprintf(STDERR_FILENO, " list[%d]=%d '%s' %p\n", i, (int)(uintptr_t)list[i],
o->data + (int)(uintptr_t)list[i] + string_start, o->data + (int)(uintptr_t)list[i] + string_start,
o->data + (int)(uintptr_t)list[i] + string_start); o->data + (int)(uintptr_t)list[i] + string_start);
i++; i++;
@ -2391,7 +2391,7 @@ static void debug_print_list(const char *prefix, o_string *o, int n)
if (n) { if (n) {
const char *p = o->data + (int)(uintptr_t)list[n - 1] + string_start; const char *p = o->data + (int)(uintptr_t)list[n - 1] + string_start;
indent(); indent();
fdprintf(2, " total_sz:%ld\n", (long)((p + strlen(p) + 1) - o->data)); fdprintf(STDERR_FILENO, " total_sz:%ld\n", (long)((p + strlen(p) + 1) - o->data));
} }
} }
#else #else
@ -2891,18 +2891,18 @@ static void debug_print_tree(struct pipe *pi, int lvl)
pin = 0; pin = 0;
while (pi) { while (pi) {
fdprintf(2, "%*spipe %d res_word=%s followup=%d %s\n", lvl*2, "", fdprintf(STDERR_FILENO, "%*spipe %d res_word=%s followup=%d %s\n", lvl*2, "",
pin, RES[pi->res_word], pi->followup, PIPE[pi->followup]); pin, RES[pi->res_word], pi->followup, PIPE[pi->followup]);
prn = 0; prn = 0;
while (prn < pi->num_cmds) { while (prn < pi->num_cmds) {
struct command *command = &pi->cmds[prn]; struct command *command = &pi->cmds[prn];
char **argv = command->argv; char **argv = command->argv;
fdprintf(2, "%*s cmd %d assignment_cnt:%d", fdprintf(STDERR_FILENO, "%*s cmd %d assignment_cnt:%d",
lvl*2, "", prn, lvl*2, "", prn,
command->assignment_cnt); command->assignment_cnt);
if (command->group) { if (command->group) {
fdprintf(2, " group %s: (argv=%p)%s%s\n", fdprintf(STDERR_FILENO, " group %s: (argv=%p)%s%s\n",
CMDTYPE[command->cmd_type], CMDTYPE[command->cmd_type],
argv argv
# if !BB_MMU # if !BB_MMU
@ -2916,10 +2916,10 @@ static void debug_print_tree(struct pipe *pi, int lvl)
continue; continue;
} }
if (argv) while (*argv) { if (argv) while (*argv) {
fdprintf(2, " '%s'", *argv); fdprintf(STDERR_FILENO, " '%s'", *argv);
argv++; argv++;
} }
fdprintf(2, "\n"); fdprintf(STDERR_FILENO, "\n");
prn++; prn++;
} }
pi = pi->next; pi = pi->next;