Skip to content

Commit 7ef47c8

Browse files
committed
Use std::os::unix::io::BorrowedFd::try_clone_to_owned in stdio
instead of wrapping `libc::dup` Signed-off-by: Jiahao XU <[email protected]>
1 parent f0b2887 commit 7ef47c8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/stdio.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use super::native_mux_impl;
55

66
use std::fs::File;
77
use std::io;
8-
use std::os::unix::io::OwnedFd;
98
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
9+
use std::os::unix::io::{BorrowedFd, OwnedFd};
1010
use std::pin::Pin;
1111
use std::process;
1212
use std::task::{Context, Poll};
@@ -145,7 +145,13 @@ macro_rules! impl_from_impl_child_io {
145145
let fd = arg.as_raw_fd();
146146

147147
// safety: arg.as_raw_fd() is guaranteed to return a valid fd.
148-
let fd = unsafe { dup(fd) }?.into_raw_fd();
148+
let fd = unsafe { BorrowedFd::borrow_raw(fd) };
149+
150+
let fd = fd
151+
.try_clone_to_owned()
152+
.map_err(Error::ChildIo)?
153+
.into_raw_fd();
154+
149155
<$inner>::from_raw_fd_checked(fd)
150156
.map(Self)
151157
.map_err(Error::ChildIo)

0 commit comments

Comments
 (0)