2023-04-09 20:03:20 +08:00
|
|
|
use crate::common::wcs2zstring;
|
2023-12-10 05:47:24 +08:00
|
|
|
use crate::flog::FLOG;
|
2024-01-23 23:38:03 +08:00
|
|
|
use crate::signal::signal_check_cancel;
|
2024-01-04 03:57:28 +08:00
|
|
|
#[cfg(test)]
|
|
|
|
use crate::tests::prelude::*;
|
2023-08-09 06:16:04 +08:00
|
|
|
use crate::wchar::prelude::*;
|
2023-04-09 20:03:20 +08:00
|
|
|
use crate::wutil::perror;
|
2024-01-23 23:38:03 +08:00
|
|
|
use errno::{errno, set_errno};
|
2024-02-10 11:49:07 +08:00
|
|
|
use libc::{c_int, EINTR, FD_CLOEXEC, F_GETFD, F_GETFL, F_SETFD, F_SETFL, O_NONBLOCK};
|
|
|
|
use nix::fcntl::FcntlArg;
|
2024-01-21 06:13:13 +08:00
|
|
|
use nix::{fcntl::OFlag, unistd};
|
2023-04-09 20:03:20 +08:00
|
|
|
use std::ffi::CStr;
|
2024-03-23 14:34:23 +08:00
|
|
|
use std::fs::File;
|
2023-07-20 23:38:54 +08:00
|
|
|
use std::io::{self, Read, Write};
|
2023-08-06 20:56:30 +08:00
|
|
|
use std::os::unix::prelude::*;
|
2023-01-15 06:56:24 +08:00
|
|
|
|
2023-10-09 05:22:27 +08:00
|
|
|
pub const PIPE_ERROR: &str = "An error occurred while setting up pipe";
|
2023-04-09 20:03:20 +08:00
|
|
|
|
|
|
|
/// The first "high fd", which is considered outside the range of valid user-specified redirections
|
|
|
|
/// (like >&5).
|
|
|
|
pub const FIRST_HIGH_FD: RawFd = 10;
|
|
|
|
|
|
|
|
/// A sentinel value indicating no timeout.
|
|
|
|
pub const NO_TIMEOUT: u64 = u64::MAX;
|
|
|
|
|
2023-01-15 06:56:24 +08:00
|
|
|
/// A helper type for managing and automatically closing a file descriptor
|
2023-02-18 09:21:44 +08:00
|
|
|
///
|
|
|
|
/// This was implemented in rust as a port of the existing C++ code but it didn't take its place
|
|
|
|
/// (yet) and there's still the original cpp implementation in `src/fds.h`, so its name is
|
|
|
|
/// disambiguated because some code uses a mix of both for interop purposes.
|
|
|
|
pub struct AutoCloseFd {
|
2023-01-15 06:56:24 +08:00
|
|
|
fd_: RawFd,
|
|
|
|
}
|
|
|
|
|
2023-03-05 14:20:18 +08:00
|
|
|
impl Read for AutoCloseFd {
|
|
|
|
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
|
2024-01-21 01:45:36 +08:00
|
|
|
nix::unistd::read(self.as_raw_fd(), buf).map_err(std::io::Error::from)
|
2023-03-05 14:20:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Write for AutoCloseFd {
|
|
|
|
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
2024-06-05 23:02:57 +08:00
|
|
|
nix::unistd::write(self, buf).map_err(std::io::Error::from)
|
2023-03-05 14:20:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn flush(&mut self) -> std::io::Result<()> {
|
|
|
|
// We don't buffer anything so this is a no-op.
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-18 09:21:44 +08:00
|
|
|
impl AutoCloseFd {
|
2023-01-15 06:56:24 +08:00
|
|
|
// Closes the fd if not already closed.
|
|
|
|
pub fn close(&mut self) {
|
|
|
|
if self.fd_ != -1 {
|
|
|
|
_ = unistd::close(self.fd_);
|
|
|
|
self.fd_ = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the fd.
|
|
|
|
pub fn fd(&self) -> RawFd {
|
|
|
|
self.fd_
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the fd, transferring ownership to the caller.
|
|
|
|
pub fn acquire(&mut self) -> RawFd {
|
|
|
|
let temp = self.fd_;
|
|
|
|
self.fd_ = -1;
|
|
|
|
temp
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resets to a new fd, taking ownership.
|
|
|
|
pub fn reset(&mut self, fd: RawFd) {
|
|
|
|
if fd == self.fd_ {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.close();
|
|
|
|
self.fd_ = fd;
|
|
|
|
}
|
|
|
|
|
2023-02-18 09:21:44 +08:00
|
|
|
// Returns if this has a valid fd.
|
|
|
|
pub fn is_valid(&self) -> bool {
|
2023-01-15 06:56:24 +08:00
|
|
|
self.fd_ >= 0
|
|
|
|
}
|
|
|
|
|
2023-02-18 09:21:44 +08:00
|
|
|
// Create a new AutoCloseFd instance taking ownership of the passed fd
|
|
|
|
pub fn new(fd: RawFd) -> Self {
|
|
|
|
AutoCloseFd { fd_: fd }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new AutoCloseFd without an open fd
|
|
|
|
pub fn empty() -> Self {
|
|
|
|
AutoCloseFd { fd_: -1 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromRawFd for AutoCloseFd {
|
|
|
|
unsafe fn from_raw_fd(fd: RawFd) -> Self {
|
|
|
|
AutoCloseFd { fd_: fd }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRawFd for AutoCloseFd {
|
|
|
|
fn as_raw_fd(&self) -> RawFd {
|
|
|
|
self.fd()
|
2023-01-15 06:56:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-23 12:58:12 +08:00
|
|
|
impl AsFd for AutoCloseFd {
|
|
|
|
fn as_fd(&self) -> BorrowedFd<'_> {
|
|
|
|
unsafe { BorrowedFd::borrow_raw(self.fd()) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-18 09:21:44 +08:00
|
|
|
impl Default for AutoCloseFd {
|
|
|
|
fn default() -> AutoCloseFd {
|
|
|
|
AutoCloseFd { fd_: -1 }
|
2023-01-15 06:56:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-18 09:21:44 +08:00
|
|
|
impl Drop for AutoCloseFd {
|
2023-01-15 06:56:24 +08:00
|
|
|
fn drop(&mut self) {
|
|
|
|
self.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Helper type returned from make_autoclose_pipes.
|
2023-04-23 01:15:17 +08:00
|
|
|
pub struct AutoClosePipes {
|
2023-01-15 06:56:24 +08:00
|
|
|
/// Read end of the pipe.
|
2024-01-29 02:07:06 +08:00
|
|
|
pub read: OwnedFd,
|
2023-01-15 06:56:24 +08:00
|
|
|
|
|
|
|
/// Write end of the pipe.
|
2024-01-29 02:07:06 +08:00
|
|
|
pub write: OwnedFd,
|
2023-01-15 06:56:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Construct a pair of connected pipes, set to close-on-exec.
|
2024-05-07 03:58:10 +08:00
|
|
|
/// Return None on fd exhaustion.
|
2024-02-10 11:49:07 +08:00
|
|
|
pub fn make_autoclose_pipes() -> nix::Result<AutoClosePipes> {
|
2024-01-14 05:41:47 +08:00
|
|
|
#[allow(unused_mut, unused_assignments)]
|
|
|
|
let mut already_cloexec = false;
|
2023-12-10 05:47:24 +08:00
|
|
|
#[cfg(HAVE_PIPE2)]
|
2024-02-10 11:49:07 +08:00
|
|
|
let pipes = match nix::unistd::pipe2(OFlag::O_CLOEXEC) {
|
|
|
|
Ok(pipes) => {
|
|
|
|
already_cloexec = true;
|
|
|
|
pipes
|
|
|
|
}
|
|
|
|
Err(err) => {
|
2023-12-10 05:47:24 +08:00
|
|
|
FLOG!(warning, PIPE_ERROR);
|
|
|
|
perror("pipe2");
|
2024-02-10 11:49:07 +08:00
|
|
|
return Err(err);
|
2023-12-10 05:47:24 +08:00
|
|
|
}
|
2024-02-10 11:49:07 +08:00
|
|
|
};
|
2023-12-10 05:47:24 +08:00
|
|
|
#[cfg(not(HAVE_PIPE2))]
|
2024-02-10 11:49:07 +08:00
|
|
|
let pipes = match nix::unistd::pipe() {
|
|
|
|
Ok(pipes) => pipes,
|
|
|
|
Err(err) => {
|
|
|
|
FLOG!(warning, PIPE_ERROR);
|
2024-02-12 04:16:58 +08:00
|
|
|
perror("pipe");
|
2024-02-10 11:49:07 +08:00
|
|
|
return Err(err);
|
|
|
|
}
|
|
|
|
};
|
2023-01-15 06:56:24 +08:00
|
|
|
|
2024-06-05 23:02:57 +08:00
|
|
|
let readp = pipes.0;
|
|
|
|
let writep = pipes.1;
|
2023-12-10 05:47:24 +08:00
|
|
|
|
|
|
|
// Ensure our fds are out of the user range.
|
2024-01-29 02:07:06 +08:00
|
|
|
let readp = heightenize_fd(readp, already_cloexec)?;
|
|
|
|
let writep = heightenize_fd(writep, already_cloexec)?;
|
2023-12-10 05:47:24 +08:00
|
|
|
|
2024-02-10 11:49:07 +08:00
|
|
|
Ok(AutoClosePipes {
|
2023-12-10 05:47:24 +08:00
|
|
|
read: readp,
|
|
|
|
write: writep,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// If the given fd is in the "user range", move it to a new fd in the "high range".
|
|
|
|
/// zsh calls this movefd().
|
2024-05-07 03:52:36 +08:00
|
|
|
/// `input_has_cloexec` describes whether the input has CLOEXEC already set, so we can avoid
|
2023-12-10 05:47:24 +08:00
|
|
|
/// setting it again.
|
2024-05-07 03:58:10 +08:00
|
|
|
/// Return the fd, which always has CLOEXEC set; or an invalid fd on failure, in
|
2023-12-10 05:47:24 +08:00
|
|
|
/// which case an error will have been printed, and the input fd closed.
|
2024-02-10 11:49:07 +08:00
|
|
|
fn heightenize_fd(fd: OwnedFd, input_has_cloexec: bool) -> nix::Result<OwnedFd> {
|
2024-01-29 02:07:06 +08:00
|
|
|
let raw_fd = fd.as_raw_fd();
|
|
|
|
|
|
|
|
if raw_fd >= FIRST_HIGH_FD {
|
2023-12-10 05:47:24 +08:00
|
|
|
if !input_has_cloexec {
|
2024-01-29 02:07:06 +08:00
|
|
|
set_cloexec(raw_fd, true);
|
2023-12-10 05:47:24 +08:00
|
|
|
}
|
2024-02-10 11:49:07 +08:00
|
|
|
return Ok(fd);
|
2023-12-10 05:47:24 +08:00
|
|
|
}
|
2024-02-10 11:49:07 +08:00
|
|
|
|
2023-12-10 05:47:24 +08:00
|
|
|
// Here we are asking the kernel to give us a cloexec fd.
|
2024-02-10 11:49:07 +08:00
|
|
|
let newfd = match nix::fcntl::fcntl(raw_fd, FcntlArg::F_DUPFD_CLOEXEC(FIRST_HIGH_FD)) {
|
|
|
|
Ok(newfd) => newfd,
|
|
|
|
Err(err) => {
|
|
|
|
perror("fcntl");
|
|
|
|
return Err(err);
|
|
|
|
}
|
|
|
|
};
|
2024-01-29 02:07:06 +08:00
|
|
|
|
2024-02-10 11:49:07 +08:00
|
|
|
Ok(unsafe { OwnedFd::from_raw_fd(newfd) })
|
2023-01-15 06:56:24 +08:00
|
|
|
}
|
2023-04-09 20:03:20 +08:00
|
|
|
|
2024-05-07 03:52:36 +08:00
|
|
|
/// Sets CLO_EXEC on a given fd according to the value of `should_set`.
|
2023-12-03 23:54:52 +08:00
|
|
|
pub fn set_cloexec(fd: RawFd, should_set: bool /* = true */) -> c_int {
|
2023-10-09 05:22:27 +08:00
|
|
|
// Note we don't want to overwrite existing flags like O_NONBLOCK which may be set. So fetch the
|
|
|
|
// existing flags and modify them.
|
|
|
|
let flags = unsafe { libc::fcntl(fd, F_GETFD, 0) };
|
|
|
|
if flags < 0 {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
let mut new_flags = flags;
|
|
|
|
if should_set {
|
|
|
|
new_flags |= FD_CLOEXEC;
|
|
|
|
} else {
|
|
|
|
new_flags &= !FD_CLOEXEC;
|
|
|
|
}
|
|
|
|
if flags == new_flags {
|
|
|
|
0
|
|
|
|
} else {
|
|
|
|
unsafe { libc::fcntl(fd, F_SETFD, new_flags) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-09 20:03:20 +08:00
|
|
|
/// Wide character version of open() that also sets the close-on-exec flag (atomically when
|
|
|
|
/// possible).
|
2024-01-21 06:57:34 +08:00
|
|
|
pub fn wopen_cloexec(
|
|
|
|
pathname: &wstr,
|
2024-01-21 07:21:49 +08:00
|
|
|
flags: OFlag,
|
2024-01-21 06:57:34 +08:00
|
|
|
mode: nix::sys::stat::Mode,
|
2024-03-23 14:34:23 +08:00
|
|
|
) -> nix::Result<File> {
|
2023-04-09 20:03:20 +08:00
|
|
|
open_cloexec(wcs2zstring(pathname).as_c_str(), flags, mode)
|
|
|
|
}
|
|
|
|
|
2024-03-23 14:15:43 +08:00
|
|
|
/// Narrow versions of wopen_cloexec().
|
2024-03-23 14:34:23 +08:00
|
|
|
pub fn open_cloexec(path: &CStr, flags: OFlag, mode: nix::sys::stat::Mode) -> nix::Result<File> {
|
2023-07-05 10:30:26 +08:00
|
|
|
// Port note: the C++ version of this function had a fallback for platforms where
|
|
|
|
// O_CLOEXEC is not supported, using fcntl. In 2023, this is no longer needed.
|
2024-01-23 23:38:03 +08:00
|
|
|
let saved_errno = errno();
|
|
|
|
errno::set_errno(errno::Errno(0));
|
|
|
|
// We retry this in case of signals,
|
|
|
|
// if we get EINTR and it's not a SIGINIT, we continue.
|
|
|
|
// If it is that's our cancel signal, so we abort.
|
|
|
|
loop {
|
2024-01-21 06:13:13 +08:00
|
|
|
let ret = nix::fcntl::open(path, flags | OFlag::O_CLOEXEC, mode);
|
2024-03-23 14:34:23 +08:00
|
|
|
let ret = ret.map(|raw_fd| unsafe { File::from_raw_fd(raw_fd) });
|
2024-01-21 06:13:13 +08:00
|
|
|
match ret {
|
2024-03-23 14:34:23 +08:00
|
|
|
Ok(file) => {
|
2024-01-21 06:13:13 +08:00
|
|
|
set_errno(saved_errno);
|
2024-03-23 14:34:23 +08:00
|
|
|
return Ok(file);
|
2024-01-21 06:13:13 +08:00
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
if err != nix::Error::EINTR || signal_check_cancel() != 0 {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2024-01-23 23:38:03 +08:00
|
|
|
}
|
|
|
|
}
|
2023-04-09 20:03:20 +08:00
|
|
|
}
|
|
|
|
|
2024-04-15 18:19:21 +08:00
|
|
|
/// POSIX specifies an open option O_SEARCH for opening directories for later
|
|
|
|
/// `fchdir` or `openat`, not for `readdir`. The read permission is not checked,
|
|
|
|
/// and the x permission is checked on opening. Not all platforms have this,
|
|
|
|
/// so we fall back to O_PATH or O_RDONLY according to the platform.
|
|
|
|
pub use o_search::BEST_O_SEARCH;
|
|
|
|
|
|
|
|
mod o_search {
|
|
|
|
use super::OFlag;
|
2024-04-30 03:08:44 +08:00
|
|
|
/// On macOS we have O_SEARCH, which is defined as O_EXEC | O_DIRECTORY,
|
|
|
|
/// where O_EXEC is 0x40000000. This is only on macOS 12.0+ or later; however
|
|
|
|
/// prior macOS versions ignores O_EXEC so it is treated the same as O_RDONLY.
|
|
|
|
#[cfg(target_os = "macos")]
|
2024-06-05 23:02:57 +08:00
|
|
|
pub const BEST_O_SEARCH: OFlag = OFlag::from_bits_truncate(libc::O_DIRECTORY | 0x40000000);
|
2024-04-30 03:08:44 +08:00
|
|
|
|
|
|
|
/// On FreeBSD, we have O_SEARCH = 0x00040000.
|
|
|
|
#[cfg(target_os = "freebsd")]
|
2024-06-05 23:02:57 +08:00
|
|
|
pub const BEST_O_SEARCH: OFlag = OFlag::from_bits_truncate(0x00040000);
|
2024-04-30 03:08:44 +08:00
|
|
|
|
2024-04-15 18:19:21 +08:00
|
|
|
/// On Linux we can use O_PATH, it has nearly the same semantics. we can use the fd for openat / fchdir, with only requiring
|
|
|
|
/// x permission on the directory.
|
2024-04-30 03:08:44 +08:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2024-06-05 23:02:57 +08:00
|
|
|
pub const BEST_O_SEARCH: OFlag = OFlag::from_bits_truncate(libc::O_PATH);
|
2024-04-15 18:19:21 +08:00
|
|
|
|
2024-04-30 03:08:44 +08:00
|
|
|
/// Fall back to O_RDONLY.
|
2024-04-15 18:40:27 +08:00
|
|
|
#[cfg(not(any(
|
|
|
|
target_os = "linux",
|
|
|
|
target_os = "android",
|
|
|
|
target_os = "freebsd",
|
|
|
|
target_os = "macos"
|
|
|
|
)))]
|
2024-04-15 18:19:21 +08:00
|
|
|
pub const BEST_O_SEARCH: OFlag = OFlag::O_RDONLY;
|
|
|
|
}
|
|
|
|
|
2024-03-23 14:15:43 +08:00
|
|
|
/// Wide character version of open_dir() that also sets the close-on-exec flag (atomically when
|
|
|
|
/// possible).
|
2024-04-15 18:19:21 +08:00
|
|
|
pub fn wopen_dir(pathname: &wstr, flags: OFlag) -> nix::Result<OwnedFd> {
|
|
|
|
open_dir(wcs2zstring(pathname).as_c_str(), flags)
|
2024-03-23 14:15:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Narrow version of wopen_dir().
|
2024-04-15 18:19:21 +08:00
|
|
|
pub fn open_dir(path: &CStr, flags: OFlag) -> nix::Result<OwnedFd> {
|
2024-04-15 18:40:27 +08:00
|
|
|
let mode = nix::sys::stat::Mode::empty();
|
|
|
|
open_cloexec(path, flags | OFlag::O_DIRECTORY, mode).map(OwnedFd::from)
|
2024-03-23 14:15:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-07 03:52:36 +08:00
|
|
|
/// Close a file descriptor `fd`, retrying on EINTR.
|
2023-04-09 20:03:20 +08:00
|
|
|
pub fn exec_close(fd: RawFd) {
|
|
|
|
assert!(fd >= 0, "Invalid fd");
|
|
|
|
while unsafe { libc::close(fd) } == -1 {
|
|
|
|
if errno::errno().0 != EINTR {
|
|
|
|
perror("close");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-20 23:38:54 +08:00
|
|
|
|
|
|
|
/// Mark an fd as nonblocking
|
|
|
|
pub fn make_fd_nonblocking(fd: RawFd) -> Result<(), io::Error> {
|
2023-10-09 05:22:27 +08:00
|
|
|
let flags = unsafe { libc::fcntl(fd, F_GETFL, 0) };
|
2023-07-20 23:38:54 +08:00
|
|
|
let nonblocking = (flags & O_NONBLOCK) == O_NONBLOCK;
|
|
|
|
if !nonblocking {
|
2023-10-09 05:22:27 +08:00
|
|
|
match unsafe { libc::fcntl(fd, F_SETFL, flags | O_NONBLOCK) } {
|
|
|
|
-1 => return Err(io::Error::last_os_error()),
|
|
|
|
_ => return Ok(()),
|
2023-07-20 23:38:54 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Mark an fd as blocking
|
|
|
|
pub fn make_fd_blocking(fd: RawFd) -> Result<(), io::Error> {
|
2023-10-09 05:22:27 +08:00
|
|
|
let flags = unsafe { libc::fcntl(fd, F_GETFL, 0) };
|
2023-07-20 23:38:54 +08:00
|
|
|
let nonblocking = (flags & O_NONBLOCK) == O_NONBLOCK;
|
|
|
|
if nonblocking {
|
2023-10-09 05:22:27 +08:00
|
|
|
match unsafe { libc::fcntl(fd, F_SETFL, flags & !O_NONBLOCK) } {
|
|
|
|
-1 => return Err(io::Error::last_os_error()),
|
|
|
|
_ => return Ok(()),
|
2023-07-20 23:38:54 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-12-10 00:18:51 +08:00
|
|
|
|
2024-01-04 03:57:28 +08:00
|
|
|
#[test]
|
|
|
|
#[serial]
|
|
|
|
fn test_pipes() {
|
2024-03-24 18:55:03 +08:00
|
|
|
let _cleanup = test_init();
|
2023-12-10 00:18:51 +08:00
|
|
|
// Here we just test that each pipe has CLOEXEC set and is in the high range.
|
|
|
|
// Note pipe creation may fail due to fd exhaustion; don't fail in that case.
|
|
|
|
let mut pipes = vec![];
|
|
|
|
for _i in 0..10 {
|
2024-02-10 11:49:07 +08:00
|
|
|
if let Ok(pipe) = make_autoclose_pipes() {
|
2023-12-10 00:18:51 +08:00
|
|
|
pipes.push(pipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for pipe in pipes {
|
2024-01-29 02:07:06 +08:00
|
|
|
for fd in [&pipe.read, &pipe.write] {
|
|
|
|
let fd = fd.as_raw_fd();
|
2023-12-10 00:18:51 +08:00
|
|
|
assert!(fd >= FIRST_HIGH_FD);
|
|
|
|
let flags = unsafe { libc::fcntl(fd, F_GETFD, 0) };
|
|
|
|
assert!(flags >= 0);
|
|
|
|
assert!(flags & FD_CLOEXEC != 0);
|
|
|
|
}
|
|
|
|
}
|
2024-01-04 03:57:28 +08:00
|
|
|
}
|