raw_fd_ostream: Make file handles non-inheritable by default

Summary:
This makes the file descriptors on unix platform non-inheritable (O_CLOEXEC).

There is no change in behavior on windows, as the handles were already
non-inheritable there.

Reviewers: rnk, rafael

Subscribers: llvm-commits, mgorny

Differential Revision: https://reviews.llvm.org/D28854

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292401 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pavel Labath 2017-01-18 15:46:50 +00:00
parent 73dc33b204
commit 7990fabccf

View File

@ -577,7 +577,7 @@ std::error_code openFileForRead(const Twine &Name, int &ResultFD,
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 @@ std::error_code openFileForWrite(const Twine &Name, int &ResultFD,
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;