From 936333b39a949f473540cd51bedcf76e4d8136e1 Mon Sep 17 00:00:00 2001 From: Finn Behrens Date: Thu, 25 Jun 2020 20:40:19 +0200 Subject: [PATCH] add pid to tokio::net::unix::UCred --- tokio/src/net/unix/ucred.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tokio/src/net/unix/ucred.rs b/tokio/src/net/unix/ucred.rs index ef214a702fa..e1a5182b145 100644 --- a/tokio/src/net/unix/ucred.rs +++ b/tokio/src/net/unix/ucred.rs @@ -1,8 +1,14 @@ use libc::{gid_t, uid_t}; +#[cfg(any(target_os = "linux", target_os = "android"))] +use libc::pid_t; + /// Credentials of a process #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct UCred { + /// PID (process ID) of the process + #[cfg(any(target_os = "linux", target_os = "android"))] + pid: pid_t, // TODO: how to get it under macos? /// UID (user ID) of the process uid: uid_t, /// GID (group ID) of the process @@ -19,6 +25,12 @@ impl UCred { pub fn gid(&self) -> gid_t { self.gid } + + /// Gets PID (process ID) of the process. + #[cfg(any(target_os = "linux", target_os = "android"))] + pub fn pid(&self) -> pid_t { + self.pid + } } #[cfg(any(target_os = "linux", target_os = "android"))] @@ -75,6 +87,7 @@ pub(crate) mod impl_linux { ); if ret == 0 && ucred_size as usize == mem::size_of::() { Ok(super::UCred { + pid: ucred.pid, uid: ucred.uid, gid: ucred.gid, })