Use OwnedFd, now that it's stable

This commit is contained in:
Ian Douglas Scott 2022-08-12 09:14:26 -07:00
parent e822a87072
commit 46047f4a58
3 changed files with 18 additions and 21 deletions

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
use color_eyre::eyre::{ContextCompat, Result, WrapErr};
use nix::{fcntl, unistd};
use nix::fcntl;
use std::{
os::unix::prelude::*,
process::{ExitStatus, Stdio},
@ -39,7 +39,7 @@ impl ProcessHandler {
executable: impl ToString,
args: Vec<String>,
vars: Vec<(String, String)>,
fds: Vec<RawFd>,
fds: Vec<OwnedFd>,
span: &Span,
) {
let executable = executable.to_string();
@ -71,9 +71,7 @@ impl ProcessHandler {
return;
}
};
for fd in &fds {
let _ = unistd::close(*fd);
}
drop(fds);
let mut stdout = BufReader::new(child.stdout.take().unwrap()).lines();
let mut stderr = BufReader::new(child.stderr.take().unwrap()).lines();
std::mem::drop(self.tx.send(ProcessEvent::Started));
@ -133,8 +131,8 @@ impl ProcessHandler {
}
}
fn mark_as_not_cloexec(file: &impl AsRawFd) -> Result<()> {
let raw_fd = file.as_raw_fd();
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")?,