Skip to content

Commit

Permalink
Set FD_CLOEXEC for duped 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 is off
and we should set it manually.

Fixes: tokio-rs/tokio#3809

Signed-off-by: Tim Zhang <tim@hyper.sh>
  • Loading branch information
Tim-Zhang committed May 25, 2021
1 parent 22e8858 commit d3db03e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/sys/unix/selector/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ impl Selector {
}

pub fn try_clone(&self) -> io::Result<Selector> {
syscall!(dup(self.ep)).map(|ep| Selector {
// It's the same selector, so we use the same id.
#[cfg(debug_assertions)]
id: self.id,
ep,
#[cfg(debug_assertions)]
has_waker: AtomicBool::new(self.has_waker.load(Ordering::Acquire)),
syscall!(dup(self.ep)).and_then(|ep| {
syscall!(fcntl(ep, libc::F_SETFD, libc::FD_CLOEXEC))?;

Ok(Selector {
// It's the same selector, so we use the same id.
#[cfg(debug_assertions)]
id: self.id,
ep,
#[cfg(debug_assertions)]
has_waker: AtomicBool::new(self.has_waker.load(Ordering::Acquire)),
})
})
}

Expand Down

0 comments on commit d3db03e

Please sign in to comment.