diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs index 9f50722141..40309cc3d4 100644 --- a/daemon/src/lib.rs +++ b/daemon/src/lib.rs @@ -21,12 +21,12 @@ unsafe fn get_fd(var: &str) -> RawFd { fd } -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(()) @@ -60,13 +60,14 @@ impl Daemon { pub fn spawn(mut cmd: Command) { let (mut read_pipe, write_pipe) = io::pipe().unwrap(); - unsafe { pass_fd(&mut cmd, "INIT_NOTIFY", write_pipe.into()) }; + unsafe { pass_fd(&mut cmd, "INIT_NOTIFY", write_pipe.as_raw_fd()) }; if let Err(err) = cmd.spawn() { eprintln!("daemon: failed to execute {cmd:?}: {err}"); return; } + drop(write_pipe); let mut data = [0]; match read_pipe.read_exact(&mut data) { Ok(()) => {}