From: Sebastien GODARD Date: Sat, 21 Mar 2020 09:22:35 +0000 (+0100) Subject: pidstat: Remove extra space at end of command name X-Git-Tag: v12.3.2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6134d6432a331b2dda24efb3ac7db0bdd6715dd8;p=sysstat pidstat: Remove extra space at end of command name 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 --- diff --git a/pidstat.c b/pidstat.c index 69fd9fd..2c9dfb4 100644 --- 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'; }