diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-06-26 14:41:53 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-06-26 14:41:53 +0200 |
| commit | 4add757929a33203e6b5f829eb518654a73ad4e4 (patch) | |
| tree | fcb331398ef5975074657358e675dfdc2ddadff3 | |
| parent | 1c013fae2845a6062fb4ad9e7720b5e5d1117cac (diff) | |
| download | busybox-w32-4add757929a33203e6b5f829eb518654a73ad4e4.tar.gz busybox-w32-4add757929a33203e6b5f829eb518654a73ad4e4.tar.bz2 busybox-w32-4add757929a33203e6b5f829eb518654a73ad4e4.zip | |
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.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/procps/pgrep.c b/procps/pgrep.c index e932a32bc..461abfa34 100644 --- a/procps/pgrep.c +++ b/procps/pgrep.c | |||
| @@ -156,22 +156,28 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) | |||
| 156 | if (proc->pid == pid) | 156 | if (proc->pid == pid) |
| 157 | continue; | 157 | continue; |
| 158 | 158 | ||
| 159 | if (ppid2match >= 0 && ppid2match != proc->ppid) | ||
| 160 | continue; | ||
| 161 | if (sid2match >= 0 && sid2match != proc->sid) | ||
| 162 | continue; | ||
| 163 | |||
| 159 | cmd = proc->argv0; | 164 | cmd = proc->argv0; |
| 160 | if (!cmd) { | 165 | if (!cmd) { |
| 161 | cmd = proc->comm; | 166 | cmd = proc->comm; |
| 162 | } else { | 167 | } else { |
| 163 | int i = proc->argv_len; | 168 | int i = proc->argv_len; |
| 169 | /* | ||
| 170 | * "sleep 11" looks like "sleep""\0""11""\0" in argv0. | ||
| 171 | * Make sure last "\0" does not get converted to " ": | ||
| 172 | */ | ||
| 173 | if (i && cmd[i-1] == '\0') | ||
| 174 | i--; | ||
| 164 | while (--i >= 0) { | 175 | while (--i >= 0) { |
| 165 | if ((unsigned char)cmd[i] < ' ') | 176 | if ((unsigned char)cmd[i] < ' ') |
| 166 | cmd[i] = ' '; | 177 | cmd[i] = ' '; |
| 167 | } | 178 | } |
| 168 | } | 179 | } |
| 169 | 180 | ||
| 170 | if (ppid2match >= 0 && ppid2match != proc->ppid) | ||
| 171 | continue; | ||
| 172 | if (sid2match >= 0 && sid2match != proc->sid) | ||
| 173 | continue; | ||
| 174 | |||
| 175 | /* NB: OPT_INVERT is always 0 or 1 */ | 181 | /* NB: OPT_INVERT is always 0 or 1 */ |
| 176 | if (!argv[0] | 182 | if (!argv[0] |
| 177 | || (regexec(&re_buffer, cmd, 1, re_match, 0) == 0 /* match found */ | 183 | || (regexec(&re_buffer, cmd, 1, re_match, 0) == 0 /* match found */ |
