Skip to content

Commit 64d7eca

Browse files
committed
std: Only have extra set_cloexec for files on Linux
On Linux we have to do this for binary compatibility with 2.6.18, but for other OSes (e.g. OSX/BSDs/etc) they all support this flag so we don't need to pass it.
1 parent 34af2de commit 64d7eca

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/libstd/sys/unix/fs.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,18 @@ impl File {
413413
libc::open(path.as_ptr(), flags, opts.mode as c_int)
414414
}));
415415
let fd = FileDesc::new(fd);
416-
// Even though we open with the O_CLOEXEC flag, still set CLOEXEC here,
417-
// in case the open flag is not supported (it's just ignored by the OS
418-
// in that case).
419-
fd.set_cloexec();
416+
417+
// Currently the standard library supports Linux 2.6.18 which did not
418+
// have the O_CLOEXEC flag (passed above). If we're running on an older
419+
// Linux kernel then the flag is just ignored by the OS, so we continue
420+
// to explicitly ask for a CLOEXEC fd here.
421+
//
422+
// The CLOEXEC flag, however, is supported on versions of OSX/BSD/etc
423+
// that we support, so we only do this on Linux currently.
424+
if cfg!(target_os = "linux") {
425+
fd.set_cloexec();
426+
}
427+
420428
Ok(File(fd))
421429
}
422430

0 commit comments

Comments
 (0)