diff options
| author | Tobias Bucher <tobiasbucher5991@gmail.com> | 2015-08-23 20:10:22 +0200 |
|---|---|---|
| committer | Tobias Bucher <tobiasbucher5991@gmail.com> | 2015-08-24 20:02:09 +0200 |
| commit | 6de7f609ddc6027b4148b7a458f9f766b44cd09f (patch) | |
| tree | 821d3b0671a88cca79620466c3ec0de794851976 /src/libstd/sys/unix | |
| parent | 63ba780fd7ab506bfd0f92d34a39172b412cfbe1 (diff) | |
| download | rust-6de7f609ddc6027b4148b7a458f9f766b44cd09f.tar.gz rust-6de7f609ddc6027b4148b7a458f9f766b44cd09f.zip | |
Atomically open files with O_CLOEXEC where possible
On Linux the flag is just ignored if it is not supported: https://lwn.net/Articles/588444/ Touches #24237.
Diffstat (limited to 'src/libstd/sys/unix')
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 751b8e48263..cbbdd223dc2 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -212,7 +212,7 @@ impl DirEntry { impl OpenOptions { pub fn new() -> OpenOptions { OpenOptions { - flags: 0, + flags: libc::O_CLOEXEC, read: false, write: false, mode: 0o666, @@ -269,6 +269,9 @@ impl File { libc::open(path.as_ptr(), flags, opts.mode) })); 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(); Ok(File(fd)) } |
