This is an archive of the discontinued LLVM Phabricator instance.

raw_fd_ostream: Make file handles non-inheritable by default
ClosedPublic

Authored by labath on Jan 18 2017, 4:12 AM.

Details

Summary

This makes the file descriptors on unix platform non-inheritable by default
(O_CLOEXEC). I have also added a file open flag F_Inheritable to override this
behavior if necessary. If the platform supports O_CLOEXEC flag, we will use it
to set the descriptor flag during open(2). If the flag is not available, we will
revert to the (racy) fcntl(2) call.

There is no change in behavior on windows, as the handles were already
non-inheritable by default (but one can still use the new flag to make them
inheritable).

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Jan 18 2017, 4:12 AM
aaron.ballman added inline comments.
lib/Support/Unix/Path.inc
648 ↗(On Diff #84819)

In general, please add && "something useful" so that people who trigger this assert have a chance to know what went wrong.

lib/Support/Windows/Path.inc
778 ↗(On Diff #84819)

Please add parens around the argument.

Btw, I should note that the Windows code LGTM.

emaste added a subscriber: emaste.Jan 18 2017, 7:28 AM
labath updated this revision to Diff 84833.Jan 18 2017, 7:42 AM

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.

This revision was automatically updated to reflect the committed changes.