← Commit list

4add75792

Denys Vlasenko
Denys Vlasenko
2017-06-26
SUCCESS Duration: 143s

Subject

pgrep: fix pgrep -flx "sleep 11" - saw "sleep 11" processes as "sleep 11 "

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

procps/pgrep.c+11 -5
@@ -156,22 +156,28 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
if (proc->pid == pid)
continue;
+ if (ppid2match >= 0 && ppid2match != proc->ppid)
+ continue;
+ if (sid2match >= 0 && sid2match != proc->sid)
+ continue;
+
cmd = proc->argv0;
if (!cmd) {
cmd = proc->comm;
} else {
int i = proc->argv_len;
+ /*
+ * "sleep 11" looks like "sleep""\0""11""\0" in argv0.
+ * Make sure last "\0" does not get converted to " ":
+ */
+ if (i && cmd[i-1] == '\0')
+ i--;
while (--i >= 0) {
if ((unsigned char)cmd[i] < ' ')
cmd[i] = ' ';
}
}
- if (ppid2match >= 0 && ppid2match != proc->ppid)
- continue;
- if (sid2match >= 0 && sid2match != proc->sid)
- continue;
-
/* NB: OPT_INVERT is always 0 or 1 */
if (!argv[0]
|| (regexec(&re_buffer, cmd, 1, re_match, 0) == 0 /* match found */