[PATCH] pgrep: make --terminal respect other criteria

"Jason Cox" <[email protected]> ("me") Fri, 9 Dec 2022 13:33:13 -0500
Newsgroups gmane.linux.procps.devel
Message-ID <[email protected]>
---

I discovered today that 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. This simple patch fixes it for me.

 src/pgrep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/pgrep.c b/src/pgrep.c
index eeebf3e8..eec67361 100644
--- a/src/pgrep.c
+++ b/src/pgrep.c
@@ -685,8 +685,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))
-- 
2.38.1