Skip to content

Commit d06cbf7

Browse files
ariel-miculasoold
authored andcommitted
Implement From<RawFd> for Stdio
1 parent e19a4ac commit d06cbf7

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

daemonize/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use std::fs::File;
6565
use std::mem::transmute;
6666
use std::os::unix::ffi::OsStringExt;
6767
use std::os::unix::io::AsRawFd;
68+
use std::os::unix::io::RawFd;
6869
use std::path::{Path, PathBuf};
6970
use std::process::exit;
7071

@@ -146,6 +147,7 @@ impl From<u32> for Mask {
146147
enum StdioImpl {
147148
Devnull,
148149
RedirectToFile(File),
150+
RedirectToRawFd(RawFd),
149151
Keep,
150152
}
151153

@@ -177,6 +179,14 @@ impl From<File> for Stdio {
177179
}
178180
}
179181

182+
impl From<RawFd> for Stdio {
183+
fn from(fd: RawFd) -> Self {
184+
Self {
185+
inner: StdioImpl::RedirectToRawFd(fd),
186+
}
187+
}
188+
}
189+
180190
/// Parent process execution outcome.
181191
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
182192
#[non_exhaustive]
@@ -483,6 +493,9 @@ unsafe fn redirect_standard_streams(
483493
let raw_fd = file.as_raw_fd();
484494
check_err(libc::dup2(raw_fd, fd), ErrorKind::RedirectStreams)?;
485495
}
496+
StdioImpl::RedirectToRawFd(raw_fd) => {
497+
check_err(libc::dup2(raw_fd, fd), ErrorKind::RedirectStreams)?;
498+
}
486499
StdioImpl::Keep => (),
487500
};
488501
Ok(())

0 commit comments

Comments
 (0)