pgrep: make --terminal respect other criteria

In some cases the --terminal option to pgrep will cause all processes
matching the terminal to be output, even if other criteria would exclude them.
Specifically, I noticed that it overrides the --runstates option.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
This commit is contained in:
Jason Cox
2023-01-25 20:34:21 +11:00
committed by Craig Small
parent 356730edbb
commit 848be2b1e2
3 changed files with 12 additions and 7 deletions

View File

@@ -706,8 +706,8 @@ static struct el * select_procs (int *num)
match = 0;
else if (opt_older && (int)PIDS_GETFLT(ELAPSED) < opt_older)
match = 0;
else if (opt_term)
match = match_strlist(PIDS_GETSTR(TTYNAME), opt_term);
else if (opt_term && ! match_strlist(PIDS_GETSTR(TTYNAME), opt_term))
match = 0;
else if (opt_runstates && ! strchr(opt_runstates, PIDS_GETSCH(STA)))
match = 0;
else if (opt_cgroup && ! match_cgroup_list (PIDS_GETSTV(CGROUP), opt_cgroup))