about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/fs.rs5
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))
     }