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:
parent
a061bcff3e
commit
2a778374a5
14
src/linux.cc
14
src/linux.cc
@ -2675,10 +2675,18 @@ static void process_parse_stat(struct process *process)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Some processes have null-separated arguments, let's fix it */
|
||||
for(int i = 0; i < endl; i++)
|
||||
if (cmdline[i] == 0)
|
||||
/* Some processes have null-separated arguments (see proc(5)); let's fix it */
|
||||
int i = endl;
|
||||
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[endl] = 0;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user