aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--procps/pgrep.c16
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 */