@@ -47,8 +47,22 @@ pub struct ProcessSelectionSettings {
4747 /// - `-x` Lift "must have a tty" restriction.
4848 pub dont_require_tty : bool ,
4949
50+ /// - `-C` Select by command name
51+ pub command_names : Option < HashSet < String > > ,
5052 /// - `-p, --pid` Select specific process IDs
5153 pub pids : Option < HashSet < usize > > ,
54+ /// - `--ppid` Select specific parent process IDs
55+ pub ppids : Option < HashSet < usize > > ,
56+ /// - `--sid` Select specific session IDs
57+ pub sids : Option < HashSet < usize > > ,
58+ /// - `-G, --Group` Select by real group ID or name
59+ pub real_groups : Option < HashSet < u32 > > ,
60+ /// - `-g, --group` Select by effective group ID or name
61+ pub eff_groups : Option < HashSet < u32 > > ,
62+ /// - `-U, --User` Select by real user ID or name
63+ pub real_users : Option < HashSet < u32 > > ,
64+ /// - `-u, --user` Select by effective user ID or name
65+ pub eff_users : Option < HashSet < u32 > > ,
5266
5367 /// - `-r` Restrict the selection to only running processes.
5468 pub only_running : bool ,
@@ -64,9 +78,30 @@ impl ProcessSelectionSettings {
6478 select_non_session_leaders_with_tty : matches. get_flag ( "a" ) ,
6579 select_non_session_leaders : matches. get_flag ( "d" ) ,
6680 dont_require_tty : matches. get_flag ( "x" ) ,
81+ command_names : matches
82+ . get_many :: < Vec < String > > ( "command" )
83+ . map ( |xs| xs. flatten ( ) . cloned ( ) . collect ( ) ) ,
6784 pids : matches
6885 . get_many :: < Vec < usize > > ( "pid" )
6986 . map ( |xs| xs. flatten ( ) . copied ( ) . collect ( ) ) ,
87+ ppids : matches
88+ . get_many :: < Vec < usize > > ( "ppid" )
89+ . map ( |xs| xs. flatten ( ) . copied ( ) . collect ( ) ) ,
90+ sids : matches
91+ . get_many :: < Vec < usize > > ( "sid" )
92+ . map ( |xs| xs. flatten ( ) . copied ( ) . collect ( ) ) ,
93+ real_groups : matches
94+ . get_many :: < Vec < u32 > > ( "real-group" )
95+ . map ( |xs| xs. flatten ( ) . copied ( ) . collect ( ) ) ,
96+ eff_groups : matches
97+ . get_many :: < Vec < u32 > > ( "effective-group" )
98+ . map ( |xs| xs. flatten ( ) . copied ( ) . collect ( ) ) ,
99+ real_users : matches
100+ . get_many :: < Vec < u32 > > ( "real-user" )
101+ . map ( |xs| xs. flatten ( ) . copied ( ) . collect ( ) ) ,
102+ eff_users : matches
103+ . get_many :: < Vec < u32 > > ( "effective-user" )
104+ . map ( |xs| xs. flatten ( ) . copied ( ) . collect ( ) ) ,
70105 only_running : matches. get_flag ( "r" ) ,
71106 negate_selection : matches. get_flag ( "deselect" ) ,
72107 }
@@ -86,8 +121,30 @@ impl ProcessSelectionSettings {
86121 return Ok ( true ) ;
87122 }
88123
89- if let Some ( ref pids) = self . pids {
90- return Ok ( pids. contains ( & process. pid ) ) ;
124+ // Flags in this group seem to cause rest of the flags to be ignored
125+ let mut matched: Option < bool > = None ;
126+ fn update_match < T , U > (
127+ matched : & mut Option < bool > ,
128+ set_opt : & Option < HashSet < T > > ,
129+ value : U ,
130+ ) where
131+ T : std:: cmp:: Eq + std:: hash:: Hash + std:: borrow:: Borrow < U > ,
132+ U : std:: cmp:: Eq + std:: hash:: Hash ,
133+ {
134+ if let Some ( ref set) = set_opt {
135+ * matched. get_or_insert_default ( ) |= set. contains ( & value) ;
136+ }
137+ }
138+ update_match ( & mut matched, & self . command_names , process. name ( ) . unwrap ( ) ) ;
139+ update_match ( & mut matched, & self . pids , process. pid ) ;
140+ update_match ( & mut matched, & self . ppids , process. ppid ( ) . unwrap ( ) as usize ) ;
141+ update_match ( & mut matched, & self . sids , process. sid ( ) . unwrap ( ) as usize ) ;
142+ update_match ( & mut matched, & self . real_users , process. uid ( ) . unwrap ( ) ) ;
143+ update_match ( & mut matched, & self . eff_users , process. euid ( ) . unwrap ( ) ) ;
144+ update_match ( & mut matched, & self . real_groups , process. gid ( ) . unwrap ( ) ) ;
145+ update_match ( & mut matched, & self . eff_groups , process. egid ( ) . unwrap ( ) ) ;
146+ if let Some ( m) = matched {
147+ return Ok ( m) ;
91148 }
92149
93150 if self . select_non_session_leaders_with_tty {
0 commit comments