File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,36 @@ pub fn test_local_peer_pid() {
6666 assert_eq ! ( pid, std:: process:: id( ) as _) ;
6767}
6868
69+ #[ cfg( apple_targets) ]
70+ #[ test]
71+ pub fn test_local_peer_token ( ) {
72+ use nix:: sys:: socket:: { audit_token_t, socketpair} ;
73+
74+ #[ link( name = "bsm" , kind = "dylib" ) ]
75+ extern "C" {
76+ /// Extract the process ID from an `audit_token_t`, used to identify
77+ /// Mach tasks and senders of Mach messages as subjects of the audit
78+ /// system.
79+ ///
80+ /// - `atoken`: The Mach audit token.
81+ /// - Returns: The process ID extracted from the Mach audit token.
82+ fn audit_token_to_pid ( atoken : audit_token_t ) -> libc:: pid_t ;
83+ }
84+
85+ let ( fd1, _fd2) = socketpair (
86+ AddressFamily :: Unix ,
87+ SockType :: Stream ,
88+ None ,
89+ SockFlag :: empty ( ) ,
90+ )
91+ . unwrap ( ) ;
92+ let audit_token = getsockopt ( & fd1, sockopt:: LocalPeerToken ) . unwrap ( ) ;
93+ assert_eq ! (
94+ unsafe { audit_token_to_pid( audit_token) } ,
95+ std:: process:: id( ) as _
96+ ) ;
97+ }
98+
6999#[ cfg( target_os = "linux" ) ]
70100#[ test]
71101fn is_so_mark_functional ( ) {
You can’t perform that action at this time.
0 commit comments