From 6fa7ac62b5a1e096c623c06fb7cd4269db3d032b Mon Sep 17 00:00:00 2001 From: drifting-shard Date: Fri, 7 Aug 2026 14:04:48 +0530 Subject: [PATCH] fix: set close-on-exec on log file descriptors Signed-off-by: drifting-shard --- src/env/log_fd/unix.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/env/log_fd/unix.rs b/src/env/log_fd/unix.rs index 6f4cd4de..8d463c2f 100644 --- a/src/env/log_fd/unix.rs +++ b/src/env/log_fd/unix.rs @@ -41,11 +41,11 @@ pub struct LogFd(RawFd); impl LogFd { /// Opens a file with the given `path`. pub fn open(path: &P, perm: Permission) -> IoResult { + let flags = OFlag::from(perm) | OFlag::O_CLOEXEC; // Permission 644 let mode = Mode::S_IRUSR | Mode::S_IWUSR | Mode::S_IRGRP | Mode::S_IROTH; fail_point!("log_fd::open::fadvise_dontneed", |_| { - let fd = - LogFd(fcntl::open(path, perm.into(), mode).map_err(|e| from_nix_error(e, "open"))?); + let fd = LogFd(fcntl::open(path, flags, mode).map_err(|e| from_nix_error(e, "open"))?); #[cfg(target_os = "linux")] unsafe { extern crate libc; @@ -54,14 +54,14 @@ impl LogFd { Ok(fd) }); Ok(LogFd( - fcntl::open(path, perm.into(), mode).map_err(|e| from_nix_error(e, "open"))?, + fcntl::open(path, flags, mode).map_err(|e| from_nix_error(e, "open"))?, )) } /// Opens a file with the given `path`. The specified file will be created /// first if not exists. pub fn create(path: &P) -> IoResult { - let flags = OFlag::O_RDWR | OFlag::O_CREAT; + let flags = OFlag::O_RDWR | OFlag::O_CREAT | OFlag::O_CLOEXEC; // Permission 644 let mode = Mode::S_IRUSR | Mode::S_IWUSR | Mode::S_IRGRP | Mode::S_IROTH; let fd = fcntl::open(path, flags, mode).map_err(|e| from_nix_error(e, "open"))?;