From 6a45c49c259544ce34c745d23b01886b559b7e4f Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Tue, 30 Jul 2019 19:50:06 -0700 Subject: [PATCH] Add RHEL 5 compat --- src/util_libc.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util_libc.rs b/src/util_libc.rs index 9bcd02b2..dea5a436 100644 --- a/src/util_libc.rs +++ b/src/util_libc.rs @@ -128,10 +128,13 @@ cfg_if! { // SAFETY: path must be null terminated, FD must be manually closed. pub unsafe fn open_readonly(path: &str) -> Option { debug_assert!(path.as_bytes().last() == Some(&0)); - // We don't care about Linux OSes too old to support O_CLOEXEC. let fd = open(path.as_ptr() as *mut _, libc::O_RDONLY | libc::O_CLOEXEC); if fd < 0 { return None; } + // O_CLOEXEC works on all Unix targets except for older Linux kernels (pre + // 2.6.23), so we also use an ioctl to make sure FD_CLOEXEC is set. + #[cfg(target_os = "linux")] + libc::ioctl(self.fd, libc::FIOCLEX); Some(fd) }