1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-05 05:28:32 +00:00

Do not add trailing whitespace to proc cmdline

According to proc(5), /proc/<pid>/cmdline is supposed to have a NUL between each
argument, plus an additional NUL at the end. Instead of replacing each NUL with
a space, just replace the ones between arguments and ignore the rest.

Partial fix for #121.
This commit is contained in:
Marc Payne 2015-08-26 00:50:08 -06:00
parent a061bcff3e
commit 2a778374a5

View File

@ -2675,10 +2675,18 @@ static void process_parse_stat(struct process *process)
return; return;
} }
/* Some processes have null-separated arguments, let's fix it */ /* Some processes have null-separated arguments (see proc(5)); let's fix it */
for(int i = 0; i < endl; i++) int i = endl;
if (cmdline[i] == 0) while (i && cmdline[i-1] == 0) {
/* Skip past any trailing null characters */
--i;
}
while (i--) {
/* Replace null character between arguments with a space */
if (cmdline[i] == 0) {
cmdline[i] = ' '; cmdline[i] = ' ';
}
}
cmdline[endl] = 0; cmdline[endl] = 0;