diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2016-02-04 11:59:31 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-02-05 16:58:10 -0800 |
| commit | 64d7eca0e5a80a961c022eed3581f0ab3f00adfc (patch) | |
| tree | 3339d394642fa43d4fcb64a1770ebbeee02178bf /src/libstd/sys | |
| parent | 34af2de4096b3b1c5d3a5b70171c6e27822aaefb (diff) | |
| download | rust-64d7eca0e5a80a961c022eed3581f0ab3f00adfc.tar.gz rust-64d7eca0e5a80a961c022eed3581f0ab3f00adfc.zip | |
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.
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index e672d9f1586..fc387dbbd47 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -413,10 +413,18 @@ impl File { libc::open(path.as_ptr(), flags, opts.mode as c_int) })); let fd = FileDesc::new(fd); - // Even though we open with the O_CLOEXEC flag, still set CLOEXEC here, - // in case the open flag is not supported (it's just ignored by the OS - // in that case). - fd.set_cloexec(); + + // Currently the standard library supports Linux 2.6.18 which did not + // have the O_CLOEXEC flag (passed above). If we're running on an older + // Linux kernel then the flag is just ignored by the OS, so we continue + // to explicitly ask for a CLOEXEC fd here. + // + // The CLOEXEC flag, however, is supported on versions of OSX/BSD/etc + // that we support, so we only do this on Linux currently. + if cfg!(target_os = "linux") { + fd.set_cloexec(); + } + Ok(File(fd)) } |
