Skip to content

Commit

Permalink
Set the close-on-exec flag for the duplicate epoll_fd
Browse files Browse the repository at this point in the history
The close-on-exec flag (FD_CLOEXEC; see fcntl(2)) for the
duplicate descriptor created by dup(2) is off.

We can use fcntl + F_DUPFD_CLOEXEC to dup the epoll_fd to fix this
issue.

Fixes: tokio-rs/tokio#3809

Signed-off-by: Tim Zhang <tim@hyper.sh>
  • Loading branch information
Tim-Zhang authored and Thomasdezeeuw committed Jun 9, 2021
1 parent 2246ffb commit c52635c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/sys/unix/selector/epoll.rs
Expand Up @@ -41,7 +41,7 @@ impl Selector {
}

pub fn try_clone(&self) -> io::Result<Selector> {
syscall!(dup(self.ep)).map(|ep| Selector {
syscall!(fcntl(self.ep, libc::F_DUPFD_CLOEXEC, 0)).map(|ep| Selector {
// It's the same selector, so we use the same id.
#[cfg(debug_assertions)]
id: self.id,
Expand Down

0 comments on commit c52635c

Please sign in to comment.