@@ -115,6 +115,7 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult<Settings> {
115115 && settings. gid . is_none ( )
116116 && settings. pgroup . is_none ( )
117117 && settings. session . is_none ( )
118+ && !settings. require_handler
118119 && pattern. is_empty ( )
119120 {
120121 return Err ( USimpleError :: new (
@@ -138,21 +139,6 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult<Settings> {
138139
139140pub fn find_matching_pids ( settings : & Settings ) -> Vec < ProcessInformation > {
140141 let mut pids = collect_matched_pids ( settings) ;
141- #[ cfg( unix) ]
142- if settings. require_handler {
143- // Bits in SigCgt are off by one (ie. bit 0 represents signal 1, etc.)
144- let mask_to_test = if settings. signal == 0 {
145- // In original pgrep, testing for signal 0 seems to return results for signal 64 instead.
146- 1 << ( 64 - 1 )
147- } else {
148- 1 << ( settings. signal - 1 )
149- } ;
150- pids. retain ( |pid| {
151- let mask =
152- u64:: from_str_radix ( pid. clone ( ) . status ( ) . get ( "SigCgt" ) . unwrap ( ) , 16 ) . unwrap ( ) ;
153- mask & mask_to_test != 0
154- } ) ;
155- }
156142 if pids. is_empty ( ) {
157143 uucore:: error:: set_exit_code ( 1 ) ;
158144 pids
@@ -254,14 +240,33 @@ fn collect_matched_pids(settings: &Settings) -> Vec<ProcessInformation> {
254240 && any_matches ( & settings. euid , pid. euid ( ) . unwrap ( ) )
255241 && any_matches ( & settings. gid , pid. gid ( ) . unwrap ( ) ) ;
256242
243+ #[ cfg( unix) ]
244+ let handler_matched = if settings. require_handler {
245+ // Bits in SigCgt are off by one (ie. bit 0 represents signal 1, etc.)
246+ let mask_to_test = if settings. signal == 0 {
247+ // In original pgrep, testing for signal 0 seems to return results for signal 64 instead.
248+ 1 << ( 64 - 1 )
249+ } else {
250+ 1 << ( settings. signal - 1 )
251+ } ;
252+ let mask =
253+ u64:: from_str_radix ( pid. clone ( ) . status ( ) . get ( "SigCgt" ) . unwrap ( ) , 16 ) . unwrap ( ) ;
254+ mask & mask_to_test != 0
255+ } else {
256+ true
257+ } ;
258+ #[ cfg( not( unix) ) ]
259+ let handler_matched = true ;
260+
257261 if ( run_state_matched
258262 && pattern_matched
259263 && tty_matched
260264 && older_matched
261265 && parent_matched
262266 && pgroup_matched
263267 && session_matched
264- && ids_matched)
268+ && ids_matched
269+ && handler_matched)
265270 ^ settings. inverse
266271 {
267272 tmp_vec. push ( pid) ;
0 commit comments