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.
This commit is contained in:
parent
34af2de409
commit
64d7eca0e5
1 changed files with 12 additions and 4 deletions
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue