File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 44// file that was distributed with this source code.
55
66use regex:: Regex ;
7+ use std:: fs:: read_link;
78use std:: hash:: Hash ;
89use std:: sync:: LazyLock ;
910use std:: {
@@ -373,6 +374,11 @@ impl ProcessInformation {
373374 self . get_uid_or_gid_field ( "Gid" , 1 )
374375 }
375376
377+ // Root directory of the process (which can be changed by chroot)
378+ pub fn root ( & mut self ) -> Result < PathBuf , io:: Error > {
379+ read_link ( format ! ( "/proc/{}/root" , self . pid) )
380+ }
381+
376382 /// Fetch run state from [ProcessInformation::cached_stat]
377383 ///
378384 /// - [The /proc Filesystem: Table 1-4](https://docs.kernel.org/filesystems/proc.html#id10)
@@ -608,4 +614,11 @@ mod tests {
608614 assert_eq ! ( pid_entry. gid( ) . unwrap( ) , uucore:: process:: getgid( ) ) ;
609615 assert_eq ! ( pid_entry. egid( ) . unwrap( ) , uucore:: process:: getegid( ) ) ;
610616 }
617+
618+ #[ test]
619+ #[ cfg( target_os = "linux" ) ]
620+ fn test_root ( ) {
621+ let mut pid_entry = ProcessInformation :: current_process_info ( ) . unwrap ( ) ;
622+ assert_eq ! ( pid_entry. root( ) . unwrap( ) , PathBuf :: from( "/" ) ) ;
623+ }
611624}
You can’t perform that action at this time.
0 commit comments