From 6134d6432a331b2dda24efb3ac7db0bdd6715dd8 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sat, 21 Mar 2020 10:22:35 +0100 Subject: [PATCH] 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 --- pidstat.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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'; } -- 2.40.0