6
6
// For reference, the link is here: https://github.com/tokio-rs/tokio-uds/pull/13
7
7
// Credit to Martin Habovštiak (GitHub username Kixunil) and contributors for this work.
8
8
9
- use libc:: { gid_t, uid_t} ;
9
+ use libc:: { gid_t, pid_t , uid_t} ;
10
10
11
11
/// Credentials for a UNIX process for credentials passing.
12
12
#[ unstable( feature = "peer_credentials_unix_socket" , issue = "42839" , reason = "unstable" ) ]
13
13
#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
14
14
pub struct UCred {
15
15
pub uid : uid_t ,
16
16
pub gid : gid_t ,
17
+ // pid field is an option because it is not supported on some platforms.
18
+ pub pid : Option < pid_t > ,
17
19
}
18
20
19
21
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
@@ -57,7 +59,7 @@ pub mod impl_linux {
57
59
) ;
58
60
59
61
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 ) } )
61
63
} else {
62
64
Err ( io:: Error :: last_os_error ( ) )
63
65
}
@@ -79,7 +81,7 @@ pub mod impl_bsd {
79
81
use crate :: os:: unix:: net:: UnixStream ;
80
82
81
83
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 } ;
83
85
unsafe {
84
86
let ret = libc:: getpeereid ( socket. as_raw_fd ( ) , & mut cred. uid , & mut cred. gid ) ;
85
87
0 commit comments