Don't leak fds, and don't unset cloexec except/until needed (#3)

This may still leak fds in some error cases. That can be solved by using
`OwnedFd` when the next Rust stable releases.
This commit is contained in:
Ian Douglas Scott 2022-07-20 08:05:01 -07:00 committed by GitHub
parent b614753cff
commit cefd13692b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 32 deletions

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::process::{ProcessEvent, ProcessHandler};
use std::os::unix::io::RawFd;
use tokio::sync::mpsc::unbounded_channel;
use tokio_util::sync::CancellationToken;
use tracing::{Instrument, Span};
@ -10,12 +11,13 @@ pub fn run_executable(
executable: &'static str,
args: Vec<String>,
env_vars: Vec<(String, String)>,
fds: Vec<RawFd>,
) {
let span_2 = span.clone();
let (tx, mut rx) = unbounded_channel::<ProcessEvent>();
tokio::spawn(
async move {
ProcessHandler::new(tx, &token).run(executable, args, env_vars, &span);
ProcessHandler::new(tx, &token).run(executable, args, env_vars, fds, &span);
while let Some(event) = rx.recv().await {
match event {
ProcessEvent::Started => {