diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-12 00:15:34 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-12 00:15:34 +0200 |
commit | 3a0f6f23286ad4352830613c6a8aea1bd56ca2d2 (patch) | |
tree | 6781fe0614bf8a544550535abca7897468bae970 /libbb | |
parent | ae357bd7138a179a1433b7d6e1aca48cc6438966 (diff) | |
download | busybox-3a0f6f23286ad4352830613c6a8aea1bd56ca2d2.tar.gz |
fix read_cmdline API and a small buglet where "[comm]" may be too narrow
function old new delta
func_args 25 26 +1
read_cmdline 119 114 -5
display_process_list 1462 1447 -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 1/-20) Total: -19 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/procps.c | 7 |
1 files changed, 4 insertions, 3 deletions
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) void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) { - ssize_t sz; + int sz; char filename[sizeof("/proc//cmdline") + sizeof(int)*3]; sprintf(filename, "/proc/%u/cmdline", pid); - sz = open_read_close(filename, buf, col); + sz = open_read_close(filename, buf, col - 1); if (sz > 0) { buf[sz] = '\0'; while (--sz >= 0 && buf[sz] == '\0') continue; - while (--sz >= 0) + do { if ((unsigned char)(buf[sz]) < ' ') buf[sz] = ' '; + } while (--sz >= 0); } else { snprintf(buf, col, "[%s]", comm); } |