File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed
Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -45,15 +45,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
4545 // pgrep from procps-ng outputs the process name inside square brackets
4646 // if /proc/<PID>/cmdline is empty
4747 if it. cmdline . is_empty ( ) {
48- format ! ( "{} [{}]" , it. pid, it. clone( ) . status ( ) . get ( "Name" ) . unwrap( ) )
48+ format ! ( "{} [{}]" , it. pid, it. clone( ) . name ( ) . unwrap( ) )
4949 } else {
5050 format ! ( "{} {}" , it. pid, it. cmdline)
5151 }
5252 } )
5353 . collect ( )
5454 } else if matches. get_flag ( "list-name" ) {
5555 pids. into_iter ( )
56- . map ( |it| format ! ( "{} {}" , it. pid, it. clone( ) . status ( ) . get ( "Name" ) . unwrap( ) ) )
56+ . map ( |it| format ! ( "{} {}" , it. pid, it. clone( ) . name ( ) . unwrap( ) ) )
5757 . collect ( )
5858 } else {
5959 pids. into_iter ( ) . map ( |it| format ! ( "{}" , it. pid) ) . collect ( )
Original file line number Diff line number Diff line change @@ -274,6 +274,13 @@ impl ProcessInformation {
274274 Rc :: clone ( & result)
275275 }
276276
277+ pub fn name ( & mut self ) -> Result < String , io:: Error > {
278+ self . status ( )
279+ . get ( "Name" )
280+ . cloned ( )
281+ . ok_or ( io:: ErrorKind :: InvalidData . into ( ) )
282+ }
283+
277284 fn get_numeric_stat_field ( & mut self , index : usize ) -> Result < u64 , io:: Error > {
278285 self . stat ( )
279286 . get ( index)
Original file line number Diff line number Diff line change @@ -208,12 +208,11 @@ fn collect_matched_pids(settings: &Settings) -> Vec<ProcessInformation> {
208208 _ => true ,
209209 } ;
210210
211- let binding = pid. status ( ) ;
212- let name = binding. get ( "Name" ) . unwrap ( ) ;
211+ let name = pid. name ( ) . unwrap ( ) ;
213212 let name = if settings. ignore_case {
214213 name. to_lowercase ( )
215214 } else {
216- name. into ( )
215+ name
217216 } ;
218217 let pattern_matched = {
219218 let want = if settings. full {
You can’t perform that action at this time.
0 commit comments