66// For reference, the link is here: https://github.com/tokio-rs/tokio-uds/pull/13
77// Credit to Martin Habovštiak (GitHub username Kixunil) and contributors for this work.
88
9- use libc:: { gid_t, uid_t} ;
9+ use libc:: { gid_t, pid_t , uid_t} ;
1010
1111/// Credentials for a UNIX process for credentials passing.
1212#[ unstable( feature = "peer_credentials_unix_socket" , issue = "42839" , reason = "unstable" ) ]
1313#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
1414pub struct UCred {
1515 pub uid : uid_t ,
1616 pub gid : gid_t ,
17+ // pid field is an option because it is not supported on some platforms.
18+ pub pid : Option < pid_t > ,
1719}
1820
1921#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
@@ -57,7 +59,7 @@ pub mod impl_linux {
5759 ) ;
5860
5961 if ret == 0 && ucred_size as usize == mem:: size_of :: < ucred > ( ) {
60- Ok ( UCred { uid : ucred. uid , gid : ucred. gid } )
62+ Ok ( UCred { uid : ucred. uid , gid : ucred. gid , pid : Some ( ucred . pid ) } )
6163 } else {
6264 Err ( io:: Error :: last_os_error ( ) )
6365 }
@@ -79,7 +81,7 @@ pub mod impl_bsd {
7981 use crate :: os:: unix:: net:: UnixStream ;
8082
8183 pub fn peer_cred ( socket : & UnixStream ) -> io:: Result < UCred > {
82- let mut cred = UCred { uid : 1 , gid : 1 } ;
84+ let mut cred = UCred { uid : 1 , gid : 1 , pid : None } ;
8385 unsafe {
8486 let ret = libc:: getpeereid ( socket. as_raw_fd ( ) , & mut cred. uid , & mut cred. gid ) ;
8587
0 commit comments