aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libbb.h4
-rw-r--r--libbb/procps.c7
-rw-r--r--procps/ps.c2
-rw-r--r--procps/top.c2
4 files changed, 8 insertions, 7 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 14a16674c..fd61517c2 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1359,9 +1359,9 @@ enum {
1359//procps_status_t* alloc_procps_scan(void) FAST_FUNC; 1359//procps_status_t* alloc_procps_scan(void) FAST_FUNC;
1360void free_procps_scan(procps_status_t* sp) FAST_FUNC; 1360void free_procps_scan(procps_status_t* sp) FAST_FUNC;
1361procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC; 1361procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC;
1362/* Format cmdline (up to col chars) into char buf[col+1] */ 1362/* Format cmdline (up to col chars) into char buf[size] */
1363/* Puts [comm] if cmdline is empty (-> process is a kernel thread) */ 1363/* Puts [comm] if cmdline is empty (-> process is a kernel thread) */
1364void read_cmdline(char *buf, int col, unsigned pid, const char *comm) FAST_FUNC; 1364void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC;
1365pid_t *find_pid_by_name(const char* procName) FAST_FUNC; 1365pid_t *find_pid_by_name(const char* procName) FAST_FUNC;
1366pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; 1366pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC;
1367 1367
diff --git a/libbb/procps.c b/libbb/procps.c
index 9a8e42df7..974661785 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -464,18 +464,19 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
464 464
465void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) 465void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm)
466{ 466{
467 ssize_t sz; 467 int sz;
468 char filename[sizeof("/proc//cmdline") + sizeof(int)*3]; 468 char filename[sizeof("/proc//cmdline") + sizeof(int)*3];
469 469
470 sprintf(filename, "/proc/%u/cmdline", pid); 470 sprintf(filename, "/proc/%u/cmdline", pid);
471 sz = open_read_close(filename, buf, col); 471 sz = open_read_close(filename, buf, col - 1);
472 if (sz > 0) { 472 if (sz > 0) {
473 buf[sz] = '\0'; 473 buf[sz] = '\0';
474 while (--sz >= 0 && buf[sz] == '\0') 474 while (--sz >= 0 && buf[sz] == '\0')
475 continue; 475 continue;
476 while (--sz >= 0) 476 do {
477 if ((unsigned char)(buf[sz]) < ' ') 477 if ((unsigned char)(buf[sz]) < ' ')
478 buf[sz] = ' '; 478 buf[sz] = ' ';
479 } while (--sz >= 0);
479 } else { 480 } else {
480 snprintf(buf, col, "[%s]", comm); 481 snprintf(buf, col, "[%s]", comm);
481 } 482 }
diff --git a/procps/ps.c b/procps/ps.c
index 4a6b60bdc..6523f0f38 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -186,7 +186,7 @@ static void func_comm(char *buf, int size, const procps_status_t *ps)
186 186
187static void func_args(char *buf, int size, const procps_status_t *ps) 187static void func_args(char *buf, int size, const procps_status_t *ps)
188{ 188{
189 read_cmdline(buf, size, ps->pid, ps->comm); 189 read_cmdline(buf, size+1, ps->pid, ps->comm);
190} 190}
191 191
192static void func_pid(char *buf, int size, const procps_status_t *ps) 192static void func_pid(char *buf, int size, const procps_status_t *ps)
diff --git a/procps/top.c b/procps/top.c
index 92360a005..7133e5c99 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -617,7 +617,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
617#endif 617#endif
618 ); 618 );
619 if ((int)(col + 1) < scr_width) 619 if ((int)(col + 1) < scr_width)
620 read_cmdline(line_buf + col, scr_width - col - 1, s->pid, s->comm); 620 read_cmdline(line_buf + col, scr_width - col, s->pid, s->comm);
621 fputs(line_buf, stdout); 621 fputs(line_buf, stdout);
622 /* printf(" %d/%d %lld/%lld", s->pcpu, total_pcpu, 622 /* printf(" %d/%d %lld/%lld", s->pcpu, total_pcpu,
623 cur_jif.busy - prev_jif.busy, cur_jif.total - prev_jif.total); */ 623 cur_jif.busy - prev_jif.busy, cur_jif.total - prev_jif.total); */