Skip to content

Commit

Permalink
add pid to tokio::net::unix::UCred
Browse files Browse the repository at this point in the history
  • Loading branch information
Kloenk committed Oct 11, 2020
1 parent b047f64 commit eb86bb4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tokio/src/net/unix/ucred.rs
@@ -1,8 +1,11 @@
use libc::{gid_t, uid_t};
use libc::{pid_t, gid_t, uid_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
Expand All @@ -19,6 +22,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"))]
Expand Down Expand Up @@ -75,6 +84,7 @@ pub(crate) mod impl_linux {
);
if ret == 0 && ucred_size as usize == mem::size_of::<ucred>() {
Ok(super::UCred {
pid: ucred.pid,
uid: ucred.uid,
gid: ucred.gid,
})
Expand Down

0 comments on commit eb86bb4

Please sign in to comment.