[PATCH] D28894: [Support] Use O_CLOEXEC only when declared
Pavel Labath via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 24 03:08:10 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL292912: [Support] Use O_CLOEXEC only when declared (authored by labath).
Changed prior to commit:
https://reviews.llvm.org/D28894?vs=85338&id=85555#toc
Repository:
rL LLVM
https://reviews.llvm.org/D28894
Files:
llvm/trunk/lib/Support/Unix/Path.inc
Index: llvm/trunk/lib/Support/Unix/Path.inc
===================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc
+++ llvm/trunk/lib/Support/Unix/Path.inc
@@ -587,10 +587,19 @@
SmallVectorImpl<char> *RealPath) {
SmallString<128> Storage;
StringRef P = Name.toNullTerminatedStringRef(Storage);
- while ((ResultFD = open(P.begin(), O_RDONLY | O_CLOEXEC)) < 0) {
+ int OpenFlags = O_RDONLY;
+#ifdef O_CLOEXEC
+ OpenFlags |= O_CLOEXEC;
+#endif
+ while ((ResultFD = open(P.begin(), OpenFlags)) < 0) {
if (errno != EINTR)
return std::error_code(errno, std::generic_category());
}
+#ifndef O_CLOEXEC
+ int r = fcntl(ResultFD, F_SETFD, FD_CLOEXEC);
+ (void)r;
+ assert(r == 0 && "fcntl(F_SETFD, FD_CLOEXEC) failed");
+#endif
// Attempt to get the real name of the file, if the user asked
if(!RealPath)
return std::error_code();
@@ -624,7 +633,11 @@
assert((!(Flags & sys::fs::F_Excl) || !(Flags & sys::fs::F_Append)) &&
"Cannot specify both 'excl' and 'append' file creation flags!");
- int OpenFlags = O_CREAT | O_CLOEXEC;
+ int OpenFlags = O_CREAT;
+
+#ifdef O_CLOEXEC
+ OpenFlags |= O_CLOEXEC;
+#endif
if (Flags & F_RW)
OpenFlags |= O_RDWR;
@@ -645,6 +658,11 @@
if (errno != EINTR)
return std::error_code(errno, std::generic_category());
}
+#ifndef O_CLOEXEC
+ int r = fcntl(ResultFD, F_SETFD, FD_CLOEXEC);
+ (void)r;
+ assert(r == 0 && "fcntl(F_SETFD, FD_CLOEXEC) failed");
+#endif
return std::error_code();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28894.85555.patch
Type: text/x-patch
Size: 1569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170124/6fa37272/attachment.bin>
More information about the llvm-commits
mailing list