From 049b007865e2dfcfd2093db732b3bfbcb75b5c77 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 24 Oct 2015 03:45:57 +0200 Subject: pmap: fix bogus {no such process} comm field text function old new delta read_cmdline 246 266 +20 procps_get_maps 196 193 -3 packed_usage 30413 30404 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 20/-12) Total: 8 bytes Signed-off-by: Denys Vlasenko --- libbb/procps.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libbb/procps.c') diff --git a/libbb/procps.c b/libbb/procps.c index 05eefe0da..4edc54d48 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -588,12 +588,14 @@ void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) buf[sz] = ' '; sz--; } + if (base[0] == '-') /* "-sh" (login shell)? */ + base++; /* If comm differs from argv0, prepend "{comm} ". * It allows to see thread names set by prctl(PR_SET_NAME). */ - if (base[0] == '-') /* "-sh" (login shell)? */ - base++; + if (!comm) + return; comm_len = strlen(comm); /* Why compare up to comm_len, not COMM_LEN-1? * Well, some processes rewrite argv, and use _spaces_ there @@ -612,7 +614,7 @@ void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) buf[col - 1] = '\0'; } } else { - snprintf(buf, col, "[%s]", comm); + snprintf(buf, col, "[%s]", comm ? comm : "?"); } } -- cgit v1.2.3