[PATCH] D28854: raw_fd_ostream: Make file handles non-inheritable by default

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 18 07:42:49 PST 2017


labath updated this revision to Diff 84833.
labath added a comment.

After the round of comments, the patch has significantly decreased in size. :)

- I have removed the F_Inheritable flag, as we don't care about inheritable handles now
- I reverted the windows changes, as they already create non-inheritable handles
- I reverted the cmake code checking for O_CLOEXEC. I will watch out for buildbot emails to see if anything breaks.

I also added the O_CLOEXEC flag to openFileForRead(), for symmetry.


https://reviews.llvm.org/D28854

Files:
  lib/Support/Unix/Path.inc


Index: lib/Support/Unix/Path.inc
===================================================================
--- lib/Support/Unix/Path.inc
+++ lib/Support/Unix/Path.inc
@@ -577,7 +577,7 @@
                                 SmallVectorImpl<char> *RealPath) {
   SmallString<128> Storage;
   StringRef P = Name.toNullTerminatedStringRef(Storage);
-  while ((ResultFD = open(P.begin(), O_RDONLY)) < 0) {
+  while ((ResultFD = open(P.begin(), O_RDONLY | O_CLOEXEC)) < 0) {
     if (errno != EINTR)
       return std::error_code(errno, std::generic_category());
   }
@@ -614,7 +614,7 @@
   assert((!(Flags & sys::fs::F_Excl) || !(Flags & sys::fs::F_Append)) &&
          "Cannot specify both 'excl' and 'append' file creation flags!");
 
-  int OpenFlags = O_CREAT;
+  int OpenFlags = O_CREAT | O_CLOEXEC;
 
   if (Flags & F_RW)
     OpenFlags |= O_RDWR;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28854.84833.patch
Type: text/x-patch
Size: 841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170118/1f68a53a/attachment.bin>


More information about the llvm-commits mailing list