diff --git a/init/src/service.rs b/init/src/service.rs index ed0023e921..86f24079bf 100644 --- a/init/src/service.rs +++ b/init/src/service.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, BTreeSet}; use std::ffi::OsString; use std::io::Read; -use std::os::fd::{AsRawFd, OwnedFd}; +use std::os::fd::{AsRawFd, RawFd}; use std::os::unix::process::CommandExt; use std::process::Command; use std::{env, io}; @@ -47,7 +47,7 @@ impl Service { command.envs(base_envs).envs(&self.envs); let (mut read_pipe, write_pipe) = io::pipe().unwrap(); - unsafe { pass_fd(&mut command, "INIT_NOTIFY", write_pipe.into()) }; + unsafe { pass_fd(&mut command, "INIT_NOTIFY", write_pipe.as_raw_fd()) }; let mut child = match command.spawn() { Ok(child) => child, @@ -56,6 +56,7 @@ impl Service { return; } }; + drop(write_pipe); match &self.type_ { ServiceType::Notify => match read_pipe.read_exact(&mut [0]) { @@ -117,12 +118,12 @@ impl Service { } } -unsafe fn pass_fd(cmd: &mut Command, env: &str, fd: OwnedFd) { - cmd.env(env, format!("{}", fd.as_raw_fd())); +unsafe fn pass_fd(cmd: &mut Command, env: &str, fd: RawFd) { + cmd.env(env, format!("{}", fd)); unsafe { cmd.pre_exec(move || { // Pass notify pipe to child - if libc::fcntl(fd.as_raw_fd(), libc::F_SETFD, 0) == -1 { + if libc::fcntl(fd, libc::F_SETFD, 0) == -1 { Err(io::Error::last_os_error()) } else { Ok(())