]> granicus.if.org Git - sysstat/commitdiff
Fix #228: pidstat's -l replaces "\0" with " ", displaying unnecesary data
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 4 Apr 2020 08:45:48 +0000 (10:45 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 4 Apr 2020 08:45:48 +0000 (10:45 +0200)
Fix issue #228.
Also add use cases to simulation test environment.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
pidstat.c
tests/root1/proc/8407/cmdline
tests/root1/proc/8407/task/8407/cmdline
tests/root2/proc/7900/task/10334/cmdline
tests/root2/proc/8407/cmdline
tests/root2/proc/8407/task/8407/cmdline
tests/root3/proc/7900/task/10334/cmdline

index 46b8771a365ad1288444a0a610a7dc7ff41ccb19..0b4362e8510bfbee7ea97ce10059da6c319d4b0c 100644 (file)
--- 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] = ' ';
                        }
                }
index 8d4f0e64e8b76ad18e3d37bcc9f2773ae0477391..349685443ad97ccf07765f9579579087034e85d4 100644 (file)
Binary files a/tests/root1/proc/8407/cmdline and b/tests/root1/proc/8407/cmdline differ
index 8d4f0e64e8b76ad18e3d37bcc9f2773ae0477391..349685443ad97ccf07765f9579579087034e85d4 100644 (file)
Binary files a/tests/root1/proc/8407/task/8407/cmdline and b/tests/root1/proc/8407/task/8407/cmdline differ
index f6669f2a99b1b2056fcbe8cc684bf27e254bb96a..334128be67ace9881b3ba105fa1791c64845a1b8 100644 (file)
Binary files a/tests/root2/proc/7900/task/10334/cmdline and b/tests/root2/proc/7900/task/10334/cmdline differ
index 8d4f0e64e8b76ad18e3d37bcc9f2773ae0477391..349685443ad97ccf07765f9579579087034e85d4 100644 (file)
Binary files a/tests/root2/proc/8407/cmdline and b/tests/root2/proc/8407/cmdline differ
index 8d4f0e64e8b76ad18e3d37bcc9f2773ae0477391..349685443ad97ccf07765f9579579087034e85d4 100644 (file)
Binary files a/tests/root2/proc/8407/task/8407/cmdline and b/tests/root2/proc/8407/task/8407/cmdline differ
index f6669f2a99b1b2056fcbe8cc684bf27e254bb96a..334128be67ace9881b3ba105fa1791c64845a1b8 100644 (file)
Binary files a/tests/root3/proc/7900/task/10334/cmdline and b/tests/root3/proc/7900/task/10334/cmdline differ