diff options
author | Dan Gohman <gohman@apple.com> | 2010-05-06 02:06:20 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-05-06 02:06:20 +0000 |
commit | e1e230141220d7fbde40eee228cba7a767e1b76b (patch) | |
tree | 9c07601d8b7be35d420fefb99a942d54518889bd /lib/Support | |
parent | af2b353d72cbc2e88ba890526a3c442b2f65efb5 (diff) | |
download | external_llvm-e1e230141220d7fbde40eee228cba7a767e1b76b.zip external_llvm-e1e230141220d7fbde40eee228cba7a767e1b76b.tar.gz external_llvm-e1e230141220d7fbde40eee228cba7a767e1b76b.tar.bz2 |
Handle the case where open(2) or close(2) is interrupted by a signal when
automatic syscall restarting is disabled.
Also, fix the build on systems which don't define EWOULDBLOCK.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103158 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/raw_ostream.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index ad47cb6..14c6a10 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -400,21 +400,27 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo, if (Flags & F_Excl) OpenFlags |= O_EXCL; - FD = open(Filename, OpenFlags, 0664); - if (FD < 0) { - ErrorInfo = "Error opening output file '" + std::string(Filename) + "'"; - ShouldClose = false; - } else { - ShouldClose = true; + while ((FD = open(Filename, OpenFlags, 0664)) < 0) { + if (errno != EINTR) { + ErrorInfo = "Error opening output file '" + std::string(Filename) + "'"; + ShouldClose = false; + return; + } } + + // Ok, we successfully opened the file, so it'll need to be closed. + ShouldClose = true; } raw_fd_ostream::~raw_fd_ostream() { if (FD < 0) return; flush(); if (ShouldClose) - if (::close(FD) != 0) - error_detected(); + while (::close(FD) != 0) + if (errno != EINTR) { + error_detected(); + break; + } } @@ -432,7 +438,11 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { // some programs, such as bjam, assume that their child processes // will treat them as if they are. If you don't want this code to // spin, don't use O_NONBLOCK file descriptors with raw_ostream. - if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) + if (errno == EINTR || errno == EAGAIN +#ifdef EWOULDBLOCK + || errno == EWOULDBLOCK +#endif + ) continue; // Otherwise it's a non-recoverable error. Note it and quit. @@ -452,8 +462,11 @@ void raw_fd_ostream::close() { assert(ShouldClose); ShouldClose = false; flush(); - if (::close(FD) != 0) - error_detected(); + while (::close(FD) != 0) + if (errno != EINTR) { + error_detected(); + break; + } FD = -1; } |