From: Sebastien GODARD Date: Sat, 4 Apr 2020 08:45:48 +0000 (+0200) Subject: Fix #228: pidstat's -l replaces "\0" with " ", displaying unnecesary data X-Git-Tag: v12.3.2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dab3cff7a17364cd87201e3f58080d523eaf44a6;p=sysstat Fix #228: pidstat's -l replaces "\0" with " ", displaying unnecesary data Fix issue #228. Also add use cases to simulation test environment. Signed-off-by: Sebastien GODARD --- diff --git a/pidstat.c b/pidstat.c index 46b8771..0b4362e 100644 --- a/pidstat.c +++ b/pidstat.c @@ -650,7 +650,7 @@ int read_proc_pid_cmdline(pid_t pid, struct st_pid *plist, pid_t tgid) FILE *fp; char filename[128], line[MAX_CMDLINE_LEN]; size_t len; - int i; + int i, found = FALSE; if (tgid) { sprintf(filename, TASK_CMDLINE, tgid, pid); @@ -669,8 +669,11 @@ int read_proc_pid_cmdline(pid_t pid, struct st_pid *plist, pid_t tgid) fclose(fp); if (len) { - for (i = 0; i < len - 1; i++) { - if (line[i] == '\0') { + for (i = len - 2; i >= 0; i--) { + if (line[i]) { + found = TRUE; + } + else if (found) { line[i] = ' '; } } diff --git a/tests/root1/proc/8407/cmdline b/tests/root1/proc/8407/cmdline index 8d4f0e6..3496854 100644 Binary files a/tests/root1/proc/8407/cmdline and b/tests/root1/proc/8407/cmdline differ diff --git a/tests/root1/proc/8407/task/8407/cmdline b/tests/root1/proc/8407/task/8407/cmdline index 8d4f0e6..3496854 100644 Binary files a/tests/root1/proc/8407/task/8407/cmdline and b/tests/root1/proc/8407/task/8407/cmdline differ diff --git a/tests/root2/proc/7900/task/10334/cmdline b/tests/root2/proc/7900/task/10334/cmdline index f6669f2..334128b 100644 Binary files a/tests/root2/proc/7900/task/10334/cmdline and b/tests/root2/proc/7900/task/10334/cmdline differ diff --git a/tests/root2/proc/8407/cmdline b/tests/root2/proc/8407/cmdline index 8d4f0e6..3496854 100644 Binary files a/tests/root2/proc/8407/cmdline and b/tests/root2/proc/8407/cmdline differ diff --git a/tests/root2/proc/8407/task/8407/cmdline b/tests/root2/proc/8407/task/8407/cmdline index 8d4f0e6..3496854 100644 Binary files a/tests/root2/proc/8407/task/8407/cmdline and b/tests/root2/proc/8407/task/8407/cmdline differ diff --git a/tests/root3/proc/7900/task/10334/cmdline b/tests/root3/proc/7900/task/10334/cmdline index f6669f2..334128b 100644 Binary files a/tests/root3/proc/7900/task/10334/cmdline and b/tests/root3/proc/7900/task/10334/cmdline differ