]> granicus.if.org Git - sysstat/commitdiff
pidstat: Remove extra space at end of command name
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 21 Mar 2020 09:22:35 +0000 (10:22 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 21 Mar 2020 09:22:35 +0000 (10:22 +0100)
When pidstat was used with option "-l" to display the command name and
all its arguments, a space was added at the end after all the arguments.
Remove it as it is unneeded and it may prevent the user from displaying
lines based on a pattern located at the end of line
(e.g. pidstat -l -C "pattern$" ...)

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
pidstat.c

index 69fd9fda6967e9f764fc6bada23ff0535679edcd..2c9dfb40201421aef5d1cc61fd1e92b1686c68a1 100644 (file)
--- a/pidstat.c
+++ b/pidstat.c
@@ -632,13 +632,12 @@ int read_proc_pid_cmdline(unsigned int pid, struct pid_stats *pst,
        len = fread(line, 1, MAX_CMDLINE_LEN - 1, fp);
        fclose(fp);
 
-       for (i = 0; i < len; i++) {
-               if (line[i] == '\0') {
-                       line[i] = ' ';
-               }
-       }
-
        if (len) {
+               for (i = 0; i < len - 1; i++) {
+                       if (line[i] == '\0') {
+                               line[i] = ' ';
+                       }
+               }
                strncpy(pst->cmdline, line, MAX_CMDLINE_LEN - 1);
                pst->cmdline[MAX_CMDLINE_LEN - 1] = '\0';
        }