Skip to content

Commit 6a45c49

Browse files
committed
Add RHEL 5 compat
1 parent 9d04e3a commit 6a45c49

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/util_libc.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,13 @@ cfg_if! {
128128
// SAFETY: path must be null terminated, FD must be manually closed.
129129
pub unsafe fn open_readonly(path: &str) -> Option<libc::c_int> {
130130
debug_assert!(path.as_bytes().last() == Some(&0));
131-
// We don't care about Linux OSes too old to support O_CLOEXEC.
132131
let fd = open(path.as_ptr() as *mut _, libc::O_RDONLY | libc::O_CLOEXEC);
133132
if fd < 0 {
134133
return None;
135134
}
135+
// O_CLOEXEC works on all Unix targets except for older Linux kernels (pre
136+
// 2.6.23), so we also use an ioctl to make sure FD_CLOEXEC is set.
137+
#[cfg(target_os = "linux")]
138+
libc::ioctl(self.fd, libc::FIOCLEX);
136139
Some(fd)
137140
}

0 commit comments

Comments
 (0)