2022-06-22 14:09:59 -04:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
2022-07-20 08:05:01 -07:00
|
|
|
use color_eyre::eyre::{ContextCompat, Result, WrapErr};
|
2022-08-12 09:14:26 -07:00
|
|
|
use nix::fcntl;
|
2022-09-19 13:47:44 -04:00
|
|
|
use std::os::unix::prelude::*;
|
2022-07-20 08:05:01 -07:00
|
|
|
|
2022-08-12 09:14:26 -07:00
|
|
|
fn mark_as_not_cloexec(file: &impl AsFd) -> Result<()> {
|
|
|
|
|
let raw_fd = file.as_fd().as_raw_fd();
|
2022-07-20 08:05:01 -07:00
|
|
|
let fd_flags = fcntl::FdFlag::from_bits(
|
|
|
|
|
fcntl::fcntl(raw_fd, fcntl::FcntlArg::F_GETFD)
|
|
|
|
|
.wrap_err("failed to get GETFD value of stream")?,
|
|
|
|
|
)
|
|
|
|
|
.wrap_err("failed to get fd flags from file")?;
|
|
|
|
|
fcntl::fcntl(
|
|
|
|
|
raw_fd,
|
|
|
|
|
fcntl::FcntlArg::F_SETFD(fd_flags.difference(fcntl::FdFlag::FD_CLOEXEC)),
|
|
|
|
|
)
|
|
|
|
|
.wrap_err("failed to set CLOEXEC on file")?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|