11extern crate libc;
22
33use std:: env;
4- #[ cfg( target_os = "linux" ) ]
4+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
55use std:: ffi:: CString ;
6- #[ cfg( target_os = "linux" ) ]
6+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
77use std:: fs;
88#[ cfg( target_os = "macos" ) ]
99use std:: mem;
1010use std:: path:: PathBuf ;
1111
1212use libc:: pid_t;
13- #[ cfg( target_os = "linux" ) ]
13+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
1414use libc:: PATH_MAX ;
1515
1616#[ cfg( target_os = "macos" ) ]
@@ -29,7 +29,7 @@ use crate::osx_libproc_bindings::{
2929
3030#[ cfg( target_os = "macos" ) ]
3131use self :: libc:: c_void;
32- #[ cfg( target_os = "linux" ) ]
32+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
3333use self :: libc:: { c_char, readlink} ;
3434
3535use crate :: processes;
@@ -242,7 +242,7 @@ pub fn pidinfo<T: PIDInfo>(pid: i32, arg: u64) -> Result<T, String> {
242242}
243243
244244/// pidinfo not implemented on linux - Pull Requests welcome - TODO
245- #[ cfg( not ( target_os = "macos " ) ) ]
245+ #[ cfg( any ( target_os = "linux" , target_os = "redox ") ) ]
246246pub fn pidinfo < T : PIDInfo > ( _pid : i32 , _arg : u64 ) -> Result < T , String > {
247247 unimplemented ! ( )
248248}
@@ -295,7 +295,7 @@ pub fn regionfilename(pid: i32, address: u64) -> Result<String, String> {
295295/// }
296296/// }
297297/// ```
298- #[ cfg( not ( target_os = "macos " ) ) ]
298+ #[ cfg( any ( target_os = "linux" , target_os = "redox ") ) ]
299299pub fn regionfilename ( _pid : i32 , _address : u64 ) -> Result < String , String > {
300300 Err ( "'regionfilename' not implemented on linux" . to_owned ( ) )
301301}
@@ -340,7 +340,7 @@ pub fn pidpath(pid: i32) -> Result<String, String> {
340340/// _ => panic!("Unknown error")
341341/// }
342342/// ```
343- #[ cfg( target_os = "linux" ) ]
343+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
344344pub fn pidpath ( pid : i32 ) -> Result < String , String > {
345345 let exe_path = CString :: new ( format ! ( "/proc/{pid}/exe" ) )
346346 . map_err ( |_| "Could not create CString" ) ?;
@@ -396,7 +396,7 @@ pub fn libversion() -> Result<(i32, i32), String> {
396396/// Err(err) => eprintln!("Error: {}", err)
397397/// }
398398/// ```
399- #[ cfg( not ( target_os = "macos " ) ) ]
399+ #[ cfg( any ( target_os = "linux" , target_os = "redox ") ) ]
400400pub fn libversion ( ) -> Result < ( i32 , i32 ) , String > {
401401 Err ( "Linux does not use a library, so no library version number" . to_owned ( ) )
402402}
@@ -440,7 +440,7 @@ pub fn name(pid: i32) -> Result<String, String> {
440440
441441
442442/// Get the name of a process, using it's process id (pid)
443- #[ cfg( target_os = "linux" ) ]
443+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
444444pub fn name ( pid : i32 ) -> Result < String , String > {
445445 helpers:: procfile_field ( & format ! ( "/proc/{pid}/status" ) , "Name" )
446446}
@@ -495,7 +495,7 @@ pub fn listpidinfo<T: ListPIDInfo>(pid: i32, max_len: usize) -> Result<Vec<T::It
495495}
496496
497497/// listpidinfo is not implemented on Linux - Pull Requests welcome - TODO
498- #[ cfg( not ( target_os = "macos " ) ) ]
498+ #[ cfg( any ( target_os = "linux" , target_os = "redox ") ) ]
499499pub fn listpidinfo < T : ListPIDInfo > ( _pid : i32 , _max_len : usize ) -> Result < Vec < T :: Item > , String > {
500500 unimplemented ! ( )
501501}
@@ -517,7 +517,7 @@ pub fn pidcwd(_pid: pid_t) -> Result<PathBuf, String> {
517517 Err ( "pidcwd is not implemented for macos" . into ( ) )
518518}
519519
520- #[ cfg( target_os = "linux" ) ]
520+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
521521/// Gets the path of current working directory for the process with the provided pid.
522522///
523523/// # Examples
@@ -573,7 +573,7 @@ pub fn am_root() -> bool {
573573}
574574
575575/// Return true if the calling process is being run by the root user, false otherwise
576- #[ cfg( target_os = "linux" ) ]
576+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
577577pub fn am_root ( ) -> bool {
578578 // when this becomes stable in rust libc then we can remove this function or combine for mac and linux
579579 unsafe { libc:: geteuid ( ) == 0 }
@@ -595,10 +595,10 @@ mod test {
595595 #[ cfg( target_os = "macos" ) ]
596596 use super :: { libversion, listpidinfo, ListThreads , pidinfo} ;
597597 use super :: { name, cwdself, pidpath} ;
598- #[ cfg( target_os = "linux" ) ]
598+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
599599 use super :: pidcwd;
600600 use super :: am_root;
601- #[ cfg( target_os = "linux" ) ]
601+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
602602 use crate :: libproc:: helpers;
603603 #[ cfg( target_os = "macos" ) ]
604604 use crate :: libproc:: task_info:: TaskInfo ;
@@ -687,7 +687,7 @@ mod test {
687687
688688 #[ test]
689689 fn name_test ( ) {
690- if am_root ( ) || cfg ! ( target_os = "linux" ) {
690+ if am_root ( ) || cfg ! ( any ( target_os = "linux" , target_os = "redox" ) ) {
691691 assert ! ( & name( process:: id( ) as i32 ) . expect( "Could not get the process name" )
692692 . starts_with( "libproc" ) , "Incorrect process name" ) ;
693693 } else {
@@ -700,7 +700,7 @@ mod test {
700700 fn pidpath_test_unknown_pid_test ( ) {
701701 #[ cfg( target_os = "macos" ) ]
702702 let error_message = "No such process" ;
703- #[ cfg( target_os = "linux" ) ]
703+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
704704 let error_message = "No such file or directory" ;
705705
706706 match pidpath ( -1 ) {
@@ -724,7 +724,7 @@ mod test {
724724 cwdself( ) . expect( "cwdself() failed" ) ) ;
725725 }
726726
727- #[ cfg( target_os = "linux" ) ]
727+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
728728 #[ test]
729729 fn pidcwd_of_self_test ( ) {
730730 assert_eq ! ( env:: current_dir( ) . expect( "Could not get current directory" ) ,
@@ -741,7 +741,7 @@ mod test {
741741 }
742742
743743 #[ test]
744- #[ cfg( target_os = "linux" ) ]
744+ #[ cfg( any ( target_os = "linux" , target_os = "redox" ) ) ]
745745 fn procfile_field_test ( ) {
746746 if am_root ( ) {
747747 assert ! ( helpers:: procfile_field( "/proc/1/status" , "invalid" ) . is_err( ) ) ;
0 commit comments