From 40c2d01da2ebfccf060a487f946bc79df0d33011 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 6 Aug 2025 14:02:05 +0200 Subject: [PATCH] libbb: make read_cmdline() replace chars 1..31 with '?', not space Space was too inconspicuous on output Signed-off-by: Denys Vlasenko --- libbb/procps.c | 2 +- procps/top.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libbb/procps.c b/libbb/procps.c index fc31c075d..94bbd9eb5 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -578,7 +578,7 @@ int FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) */ while (sz >= 0) { if ((unsigned char)(buf[sz]) < ' ') - buf[sz] = ' '; + buf[sz] = (buf[sz] ? /*ctrl*/'?' : /*NUL*/' '); sz--; } diff --git a/procps/top.c b/procps/top.c index 96b3e2d4e..7902e82f0 100644 --- a/procps/top.c +++ b/procps/top.c @@ -166,7 +166,7 @@ struct globals { top_status_t *top; int ntop; smallint inverted; - smallint not_first_line; + smallint first_line_printed; #if ENABLE_FEATURE_TOPMEM smallint sort_field; #endif @@ -420,8 +420,8 @@ static void print_line_buf(void) G.lines_remaining--; fmt = OPT_BATCH_MODE ? "\n""%.*s" : "\n""%.*s"CLREOL; - if (!G.not_first_line) { - G.not_first_line = 1; + if (!G.first_line_printed) { + G.first_line_printed = 1; /* Go to top */ fmt = OPT_BATCH_MODE ? "%.*s" : HOME"%.*s"CLREOL; } @@ -432,9 +432,9 @@ static void print_line_bold(void) { G.lines_remaining--; //we never print first line in bold -// if (!G.not_first_line) { +// if (!G.first_line_printed) { // printf(OPT_BATCH_MODE ? "%.*s" : HOME"%.*s"CLREOL, G.scr_width - 1, G.line_buf); -// G.not_first_line = 1; +// G.first_line_printed = 1; // } else { printf(OPT_BATCH_MODE ? "\n""%.*s" : "\n"REVERSE"%.*s"NORMAL CLREOL, G.scr_width - 1, G.line_buf); // } @@ -443,7 +443,8 @@ static void print_line_bold(void) static void print_end(void) { fputs_stdout(OPT_BATCH_MODE ? "\n" : CLREOS"\r"); - G.not_first_line = 0; /* next print will be "first line" (will clear the screen) */ + /* next print will be "first line" (will clear the screen) */ + G.first_line_printed = 0; } #if ENABLE_FEATURE_TOP_CPU_GLOBAL_PERCENTS && ENABLE_FEATURE_TOP_DECIMALS @@ -1204,6 +1205,9 @@ int top_main(int argc UNUSED_PARAM, char **argv) INIT_G(); +//worth it? +// setvbuf(stdout, /*buf*/ NULL, _IOFBF, /*size*/ 0); + interval = 5; /* default update interval is 5 seconds */ iterations = 0; /* infinite */ #if ENABLE_FEATURE_TOP_SMP_CPU