Skip to content

Commit fef3abd

Browse files
committed
Follow polarathene's suggestion of using OwnedFd
Raised in this comment: knsd/daemonize#50 (comment)
1 parent d06cbf7 commit fef3abd

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

daemonize/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ use std::ffi::CString;
6363
use std::fmt;
6464
use std::fs::File;
6565
use std::mem::transmute;
66+
use std::os::fd::OwnedFd;
6667
use std::os::unix::ffi::OsStringExt;
6768
use std::os::unix::io::AsRawFd;
68-
use std::os::unix::io::RawFd;
6969
use std::path::{Path, PathBuf};
7070
use std::process::exit;
7171

@@ -147,7 +147,7 @@ impl From<u32> for Mask {
147147
enum StdioImpl {
148148
Devnull,
149149
RedirectToFile(File),
150-
RedirectToRawFd(RawFd),
150+
RedirectToFd(OwnedFd),
151151
Keep,
152152
}
153153

@@ -179,10 +179,10 @@ impl From<File> for Stdio {
179179
}
180180
}
181181

182-
impl From<RawFd> for Stdio {
183-
fn from(fd: RawFd) -> Self {
182+
impl From<OwnedFd> for Stdio {
183+
fn from(fd: OwnedFd) -> Self {
184184
Self {
185-
inner: StdioImpl::RedirectToRawFd(fd),
185+
inner: StdioImpl::RedirectToFd(fd),
186186
}
187187
}
188188
}
@@ -493,8 +493,11 @@ unsafe fn redirect_standard_streams(
493493
let raw_fd = file.as_raw_fd();
494494
check_err(libc::dup2(raw_fd, fd), ErrorKind::RedirectStreams)?;
495495
}
496-
StdioImpl::RedirectToRawFd(raw_fd) => {
497-
check_err(libc::dup2(raw_fd, fd), ErrorKind::RedirectStreams)?;
496+
StdioImpl::RedirectToFd(owned_fd) => {
497+
check_err(
498+
libc::dup2(owned_fd.as_raw_fd(), fd),
499+
ErrorKind::RedirectStreams,
500+
)?;
498501
}
499502
StdioImpl::Keep => (),
500503
};

0 commit comments

Comments
 (0)