From fe258f5e6d39a604b67d3cf54559d5918a3f353a Mon Sep 17 00:00:00 2001 From: kai-xlr <62360539+kai-xlr@users.noreply.github.com> Date: Mon, 13 Jul 2026 06:36:10 -0400 Subject: [PATCH] net: use getpeereid for QNX peer credentials (#8270) QNX (nto) does not provide LOCAL_PEEREID, which is used by the impl_netbsd module. This causes a compilation failure on QNX. Use getpeereid() instead, following the same pattern as impl_dragonfly and impl_aix. This provides uid/gid but not pid, so UCred::pid() returns None on QNX. --- tokio/src/net/unix/ucred.rs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tokio/src/net/unix/ucred.rs b/tokio/src/net/unix/ucred.rs index 6b94b3d7f..3be73eee4 100644 --- a/tokio/src/net/unix/ucred.rs +++ b/tokio/src/net/unix/ucred.rs @@ -43,7 +43,7 @@ impl UCred { ))] pub(crate) use self::impl_linux::get_peer_cred; -#[cfg(any(target_os = "netbsd", target_os = "nto"))] +#[cfg(target_os = "netbsd")] pub(crate) use self::impl_netbsd::get_peer_cred; #[cfg(target_os = "dragonfly")] @@ -75,6 +75,9 @@ pub(crate) use self::impl_aix::get_peer_cred; ))] pub(crate) use self::impl_noproc::get_peer_cred; +#[cfg(target_os = "nto")] +pub(crate) use self::impl_nto::get_peer_cred; + #[cfg(any( target_os = "linux", target_os = "redox", @@ -413,3 +416,34 @@ pub(crate) mod impl_noproc { }) } } + +#[cfg(target_os = "nto")] +pub(crate) mod impl_nto { + use crate::net::unix::{self, UnixStream}; + + use libc::getpeereid; + use std::io; + use std::mem::MaybeUninit; + use std::os::unix::io::AsRawFd; + + pub(crate) fn get_peer_cred(sock: &UnixStream) -> io::Result { + unsafe { + let raw_fd = sock.as_raw_fd(); + + let mut uid = MaybeUninit::uninit(); + let mut gid = MaybeUninit::uninit(); + + let ret = getpeereid(raw_fd, uid.as_mut_ptr(), gid.as_mut_ptr()); + + if ret == 0 { + Ok(super::UCred { + uid: uid.assume_init() as unix::uid_t, + gid: gid.assume_init() as unix::gid_t, + pid: None, + }) + } else { + Err(io::Error::last_os_error()) + } + } + } +}