Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 40a8303

Browse files
author
Joe Ellis
committed
Add pid as an option to UCred struct
Currently, PID will be populated for Linux, and set to None for BSDs.
1 parent cbcf387 commit 40a8303

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

library/std/src/sys/unix/ext/ucred.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
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)]
1414
pub 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

Comments
 (0)