diff --git a/cros_async/src/fd_executor.rs b/cros_async/src/fd_executor.rs index 08ca2f4fb2..2f332bfefc 100644 --- a/cros_async/src/fd_executor.rs +++ b/cros_async/src/fd_executor.rs @@ -279,7 +279,7 @@ impl Drop for FdExecutor { // Used to `dup` the FDs passed to the executor so there is a guarantee they aren't closed while // waiting in TLS to be added to the main polling context. unsafe fn dup_fd(fd: RawFd) -> Result { - let ret = libc::dup(fd); + let ret = libc::fcntl(fd, libc::F_DUPFD_CLOEXEC, 0); if ret < 0 { Err(Error::DuplicatingFd(sys_util::Error::last())) } else { diff --git a/cros_async/src/uring_executor.rs b/cros_async/src/uring_executor.rs index 462582f6f7..bbd7a22470 100644 --- a/cros_async/src/uring_executor.rs +++ b/cros_async/src/uring_executor.rs @@ -677,7 +677,7 @@ impl Drop for URingExecutor { // Used to dup the FDs passed to the executor so there is a guarantee they aren't closed while // waiting in TLS to be added to the main polling context. unsafe fn dup_fd(fd: RawFd) -> Result { - let ret = libc::dup(fd); + let ret = libc::fcntl(fd, libc::F_DUPFD_CLOEXEC, 0); if ret < 0 { Err(Error::DuplicatingFd(sys_util::Error::last())) } else {