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:: {
@@ -377,6 +378,11 @@ impl ProcessInformation {
377378 self . get_uid_or_gid_field ( "Gid" , 1 )
378379 }
379380
381+ // Root directory of the process (which can be changed by chroot)
382+ pub fn root ( & mut self ) -> Result < PathBuf , io:: Error > {
383+ read_link ( format ! ( "/proc/{}/root" , self . pid) )
384+ }
385+
380386 /// Fetch run state from [ProcessInformation::cached_stat]
381387 ///
382388 /// - [The /proc Filesystem: Table 1-4](https://docs.kernel.org/filesystems/proc.html#id10)
@@ -612,4 +618,11 @@ mod tests {
612618 assert_eq ! ( pid_entry. gid( ) . unwrap( ) , uucore:: process:: getgid( ) ) ;
613619 assert_eq ! ( pid_entry. egid( ) . unwrap( ) , uucore:: process:: getegid( ) ) ;
614620 }
621+
622+ #[ test]
623+ #[ cfg( target_os = "linux" ) ]
624+ fn test_root ( ) {
625+ let mut pid_entry = ProcessInformation :: current_process_info ( ) . unwrap ( ) ;
626+ assert_eq ! ( pid_entry. root( ) . unwrap( ) , PathBuf :: from( "/" ) ) ;
627+ }
615628}
You can’t perform that action at this time.
0 commit comments