@@ -23,7 +23,6 @@ pub struct ProcDesc<'a> {
2323#[ derive( Debug , PartialEq , Eq , PartialOrd , Ord ) ]
2424pub struct ProcNamePre {
2525 pub name : Option < String > ,
26- pub comm : Option < String > ,
2726 pub exe : Option < PathBuf > ,
2827 pub cmdline : Option < Vec < String > > ,
2928}
@@ -63,24 +62,15 @@ impl<'a> ProcDesc<'a> {
6362}
6463
6564fn ps_name ( p : & Process ) -> ( Option < String > , ProcNamePre ) {
66- let comm = p. stat ( ) . ok ( ) . map ( |s| remove_paren ( s. comm ) ) ;
6765 let exe = p. exe ( ) . ok ( ) ;
6866 let cmdline = p. cmdline ( ) . ok ( ) ;
69- let name = comm
70- . clone ( )
71- . or_else ( || {
72- // I considered checking whether to check if the exe file_name is on $PATH
73- // and print the whole path if not. Nah.
74- exe. as_ref ( )
75- . and_then ( |p| p. file_name ( ) . map ( |p| p. to_string_lossy ( ) . into_owned ( ) ) )
76- } )
67+ // I considered checking whether to check if the exe file_name is on $PATH
68+ // and print the whole path if not. Nah.
69+ let name = exe
70+ . as_ref ( )
71+ . and_then ( |p| p. file_name ( ) . map ( |p| p. to_string_lossy ( ) . into_owned ( ) ) )
7772 . or_else ( || cmdline. as_ref ( ) . and_then ( |v| v. get ( 0 ) . cloned ( ) ) ) ;
78- let proc_name_pre = ProcNamePre {
79- comm,
80- exe,
81- cmdline,
82- name,
83- } ;
73+ let proc_name_pre = ProcNamePre { exe, cmdline, name } ;
8474 let name = if let py @ Some ( _) = py_ps_name ( & proc_name_pre) {
8575 py
8676 } else if let lua @ Some ( _) = lua_ps_name ( & proc_name_pre) {
@@ -283,7 +273,7 @@ fn interpreter_ps_name(
283273) -> Option < String > {
284274 let name = proc_name_pre. name . as_ref ( ) ?;
285275 let cmdline = proc_name_pre. cmdline . as_ref ( ) ?;
286- if !looks_ish ( interpreter, proc_name_pre. comm . as_ref ( ) ?)
276+ if !looks_ish ( interpreter, proc_name_pre. name . as_ref ( ) ?)
287277 || !looks_ish (
288278 interpreter,
289279 & proc_name_pre. exe . as_ref ( ) ?. file_name ( ) ?. to_string_lossy ( ) ,
@@ -329,13 +319,6 @@ fn looks_ish(name: &str, comm: &str) -> bool {
329319 }
330320}
331321
332- fn remove_paren ( x : String ) -> String {
333- x. strip_prefix ( '(' )
334- . and_then ( |x| x. strip_suffix ( ')' ) )
335- . map ( |x| x. into ( ) )
336- . unwrap_or ( x)
337- }
338-
339322impl PartialOrd for ProcDesc < ' _ > {
340323 fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
341324 Some ( self . cmp ( other) )
@@ -378,7 +361,6 @@ mod test {
378361 . collect ( ) ;
379362 let name = super :: py_ps_name ( & ProcNamePre {
380363 name : Some ( "python" . into ( ) ) ,
381- comm : Some ( "python" . into ( ) ) ,
382364 exe : Some ( "/usr/bin/python3" . into ( ) ) ,
383365 cmdline : Some ( cmdline) ,
384366 } ) ;
@@ -394,7 +376,6 @@ mod test {
394376
395377 let name = super :: py_ps_name ( & ProcNamePre {
396378 name : Some ( "python" . into ( ) ) ,
397- comm : Some ( "python" . into ( ) ) ,
398379 exe : Some ( "/usr/bin/python3.10" . into ( ) ) ,
399380 cmdline : Some ( cmdline) ,
400381 } ) ;
@@ -435,7 +416,6 @@ mod test {
435416 . collect ( ) ;
436417 let name = super :: java_ps_name ( & ProcNamePre {
437418 name : Some ( "java" . to_owned ( ) ) ,
438- comm : Some ( "java" . to_owned ( ) ) ,
439419 exe : Some ( "/opt/java/openjdk/bin/java" . into ( ) ) ,
440420 cmdline : Some ( cmdline) ,
441421 } ) ;
@@ -454,7 +434,6 @@ mod test {
454434
455435 let name = super :: node_ps_name ( & ProcNamePre {
456436 name : Some ( "node" . into ( ) ) ,
457- comm : Some ( "node" . into ( ) ) ,
458437 exe : Some ( "/usr/bin/node" . into ( ) ) ,
459438 cmdline : Some ( cmdline) ,
460439 } ) ;
0 commit comments