diff --git a/daemonize/src/lib.rs b/daemonize/src/lib.rs index 28a5750a2..1798bc01e 100644 --- a/daemonize/src/lib.rs +++ b/daemonize/src/lib.rs @@ -54,6 +54,7 @@ use std::fs::File; use std::mem::transmute; use std::os::unix::ffi::OsStringExt; use std::os::unix::io::AsRawFd; +use std::os::unix::io::RawFd; use std::path::{Path, PathBuf}; use std::process::exit; @@ -135,6 +136,7 @@ impl From for Mask { enum StdioImpl { Devnull, RedirectToFile(File), + RedirectToRawFd(RawFd), Keep, } @@ -166,6 +168,14 @@ impl From for Stdio { } } +impl From for Stdio { + fn from(fd: RawFd) -> Self { + Self { + inner: StdioImpl::RedirectToRawFd(fd), + } + } +} + /// Parent process execution outcome. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] #[non_exhaustive] @@ -457,6 +467,9 @@ unsafe fn redirect_standard_streams( let raw_fd = file.as_raw_fd(); check_err(libc::dup2(raw_fd, fd), ErrorKind::RedirectStreams)?; } + StdioImpl::RedirectToRawFd(raw_fd) => { + check_err(libc::dup2(raw_fd, fd), ErrorKind::RedirectStreams)?; + } StdioImpl::Keep => (), }; Ok(())