From 6edfecb88380862166c72e0ac5dbcaba6538ec58 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 8 Jun 2018 15:15:56 +0000 Subject: 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 --- llvm/lib/Support/Unix/Path.inc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Support/Unix/Path.inc') 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(); } -- cgit v1.2.3