mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
set CLOEXEC on pidfd received from child process
This commit is contained in:
parent
531cb83fcf
commit
10127d9eb5
@ -748,7 +748,7 @@ impl Command {
|
||||
msg.msg_controllen = mem::size_of::<Cmsg>() as _;
|
||||
msg.msg_control = &mut cmsg as *mut _ as *mut _;
|
||||
|
||||
match cvt_r(|| libc::recvmsg(sock.as_raw(), &mut msg, 0)) {
|
||||
match cvt_r(|| libc::recvmsg(sock.as_raw(), &mut msg, libc::MSG_CMSG_CLOEXEC)) {
|
||||
Err(_) => return -1,
|
||||
Ok(_) => {}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ fn test_command_fork_no_unwind() {
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_command_pidfd() {
|
||||
use crate::os::fd::RawFd;
|
||||
use crate::os::fd::{AsRawFd, RawFd};
|
||||
use crate::os::linux::process::{ChildExt, CommandExt};
|
||||
use crate::process::Command;
|
||||
|
||||
@ -82,6 +82,10 @@ fn test_command_pidfd() {
|
||||
|
||||
// but only check if we know that the kernel supports pidfds
|
||||
if pidfd_open_available {
|
||||
assert!(child.pidfd().is_ok())
|
||||
assert!(child.pidfd().is_ok());
|
||||
}
|
||||
if let Ok(pidfd) = child.pidfd() {
|
||||
let flags = super::cvt(unsafe { libc::fcntl(pidfd.as_raw_fd(), libc::F_GETFD) }).unwrap();
|
||||
assert!(flags & libc::FD_CLOEXEC != 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user