summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2017-06-26 14:41:53 +0200
committerDenys Vlasenko2017-06-26 14:41:53 +0200
commit4add757929a33203e6b5f829eb518654a73ad4e4 (patch)
treefcb331398ef5975074657358e675dfdc2ddadff3
parent1c013fae2845a6062fb4ad9e7720b5e5d1117cac (diff)
downloadbusybox-4add757929a33203e6b5f829eb518654a73ad4e4.zip
busybox-4add757929a33203e6b5f829eb518654a73ad4e4.tar.gz
pgrep: fix pgrep -flx "sleep 11" - saw "sleep 11" processes as "sleep 11 "
function old new delta pgrep_main 584 597 +13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--procps/pgrep.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/procps/pgrep.c b/procps/pgrep.c
index e932a32..461abfa 100644
--- a/procps/pgrep.c
+++ b/procps/pgrep.c
@@ -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 */