diff options
| author | Mateusz Guzik <mjg@FreeBSD.org> | 2023-12-29 18:51:56 +0000 |
|---|---|---|
| committer | Mateusz Guzik <mjg@FreeBSD.org> | 2023-12-29 18:52:12 +0000 |
| commit | 3358108a38f0efc7e7a143aeda80c941946fef77 (patch) | |
| tree | 5f55883b4fe0fe36dba3c53f85aed34c0cf2c4b2 /contrib/llvm-project/llvm/lib/Support | |
| parent | 683ea4d22bbcc892ac7c5bb996d1b134831dfdc3 (diff) | |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support')
| -rw-r--r-- | contrib/llvm-project/llvm/lib/Support/Unix/Process.inc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/Unix/Process.inc b/contrib/llvm-project/llvm/lib/Support/Unix/Process.inc index 2babf07944bf..c8b15cb759df 100644 --- a/contrib/llvm-project/llvm/lib/Support/Unix/Process.inc +++ b/contrib/llvm-project/llvm/lib/Support/Unix/Process.inc @@ -235,6 +235,25 @@ std::error_code Process::FixupStandardFileDescriptors() { return std::error_code(); } +// Close a file descriptor while being mindful of EINTR. +// +// On Unix systems closing a file descriptor usually starts with removing it +// from the fd table (or an equivalent structure). This means any error +// generated past that point will still result in the entry being cleared. +// +// Make sure to not bubble up EINTR as there is nothing to do in that case. +// XXX what about other errors? +#if defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__) || \ + defined(__NetBSD__) || defined(__OpenBSD__) +std::error_code Process::SafelyCloseFileDescriptor(int FD) { + int EC = 0; + if (::close(FD) < 0) { + if (errno != EINTR) + EC = errno; + } + return std::error_code(EC, std::generic_category()); +} +#else std::error_code Process::SafelyCloseFileDescriptor(int FD) { // Create a signal set filled with *all* signals. sigset_t FullSet, SavedSet; @@ -269,6 +288,7 @@ std::error_code Process::SafelyCloseFileDescriptor(int FD) { return std::error_code(ErrnoFromClose, std::generic_category()); return std::error_code(EC, std::generic_category()); } +#endif bool Process::StandardInIsUserInput() { return FileDescriptorIsDisplayed(STDIN_FILENO); |
