diff options
author | Zachary Turner <zturner@google.com> | 2018-06-08 15:15:56 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2018-06-08 15:15:56 +0000 |
commit | 6edfecb88380862166c72e0ac5dbcaba6538ec58 (patch) | |
tree | e0b8dbc3698ca4821c2cdbfa25bb57d234a1fda4 /llvm/lib/Support/Unix/Path.inc | |
parent | aafcf9e4a1e7a58196467dd65cb984f563ae6a71 (diff) | |
download | bcm5719-llvm-6edfecb88380862166c72e0ac5dbcaba6538ec58.tar.gz bcm5719-llvm-6edfecb88380862166c72e0ac5dbcaba6538ec58.zip |
Add a file open flag that disables O_CLOEXEC.
O_CLOEXEC is the right default, but occasionally you don't
want this. This is especially true for tools like debuggers
where you might need to spawn the child process with specific
files already open, but it's occasionally useful in other
scenarios as well, like when you want to do some IPC between
parent and child.
llvm-svn: 334293
Diffstat (limited to 'llvm/lib/Support/Unix/Path.inc')
-rw-r--r-- | llvm/lib/Support/Unix/Path.inc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index c4c4cfc3afe..f3f529e54d7 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -753,7 +753,8 @@ static int nativeOpenFlags(CreationDisposition Disp, OpenFlags Flags, Result |= O_APPEND; #ifdef O_CLOEXEC - Result |= O_CLOEXEC; + if (!(Flags & OF_ChildInherit)) + Result |= O_CLOEXEC; #endif return Result; @@ -770,9 +771,11 @@ std::error_code openFile(const Twine &Name, int &ResultFD, 0) 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"); + if (!(Flags & OF_ChildInherit)) { + int r = fcntl(ResultFD, F_SETFD, FD_CLOEXEC); + (void)r; + assert(r == 0 && "fcntl(F_SETFD, FD_CLOEXEC) failed"); + } #endif return std::error_code(); } |