Rollup merge of #151072 - fix-pidfd-ioctl, r=jhpratt

also handle ENOTTY ioctl errors when checking pidfd -> pid support

Otherwise the std testsuite fails on older kernels.

Reported in https://github.com/rust-lang/rust/pull/150412#issuecomment-3744390883
This commit is contained in:
Jonathan Brouwer 2026-01-14 11:05:41 +01:00 committed by GitHub
commit be22fe2128
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View file

@ -33,7 +33,7 @@ impl PidFd {
match cvt(unsafe { libc::ioctl(self.0.as_raw_fd(), libc::PIDFD_GET_INFO, &mut pidfd_info) })
{
Ok(_) => {}
Err(e) if e.raw_os_error() == Some(libc::EINVAL) => {
Err(e) if matches!(e.raw_os_error(), Some(libc::EINVAL | libc::ENOTTY)) => {
// kernel doesn't support that ioctl, try the glibc helper that looks at procfs
weak!(
fn pidfd_getpid(pidfd: RawFd) -> libc::pid_t;

View file

@ -1,6 +1,5 @@
use super::PidFd as InternalPidFd;
use crate::assert_matches::assert_matches;
use crate::io::ErrorKind;
use crate::os::fd::AsRawFd;
use crate::os::linux::process::{ChildExt, CommandExt as _};
use crate::os::unix::process::{CommandExt as _, ExitStatusExt};
@ -62,7 +61,9 @@ fn test_command_pidfd() {
if let Ok(pidfd) = child.pidfd() {
match pidfd.as_inner().pid() {
Ok(pid) => assert_eq!(pid, id),
Err(e) if e.kind() == ErrorKind::InvalidInput => { /* older kernel */ }
Err(e) if matches!(e.raw_os_error(), Some(libc::EINVAL | libc::ENOTTY)) => {
/* older kernel */
}
Err(e) => panic!("unexpected error getting pid from pidfd: {}", e),
}
}