8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9d04e3a commit 6a45c49Copy full SHA for 6a45c49
src/util_libc.rs
@@ -128,10 +128,13 @@ cfg_if! {
128
// SAFETY: path must be null terminated, FD must be manually closed.
129
pub unsafe fn open_readonly(path: &str) -> Option<libc::c_int> {
130
debug_assert!(path.as_bytes().last() == Some(&0));
131
- // We don't care about Linux OSes too old to support O_CLOEXEC.
132
let fd = open(path.as_ptr() as *mut _, libc::O_RDONLY | libc::O_CLOEXEC);
133
if fd < 0 {
134
return None;
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);
139
Some(fd)
140
0 commit comments