[PATCH] D28854: raw_fd_ostream: Make file handles non-inheritable by default
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 18 07:47:24 PST 2017
LGTM :-)
Pavel Labath via Phabricator <reviews at reviews.llvm.org> writes:
> 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;
>
>
> 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;
More information about the llvm-commits
mailing list