feat: use privileged sockets

This commit is contained in:
Ashley Wulber 2023-11-09 09:50:58 -05:00 committed by Ashley Wulber
parent 6d0826f319
commit fd2dc23fac
6 changed files with 186 additions and 42 deletions

View file

@ -1,19 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only
use color_eyre::eyre::{ContextCompat, Result, WrapErr};
use nix::fcntl;
use color_eyre::eyre::{Result, WrapErr};
use rustix::io::FdFlags;
use std::os::unix::prelude::*;
pub(crate) fn mark_as_not_cloexec(file: &impl AsFd) -> Result<()> {
let raw_fd = file.as_fd().as_raw_fd();
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(())
let flags = rustix::io::fcntl_getfd(file).wrap_err("failed to get GETFD value of stream")?;
rustix::io::fcntl_setfd(file, flags.difference(FdFlags::CLOEXEC))
.wrap_err("failed to unset CLOEXEC on file")
}