[llvm-commits] [llvm] r111321 - /llvm/trunk/lib/Support/raw_ostream.cpp
Chris Lattner
sabre at nondot.org
Tue Aug 17 16:11:56 PDT 2010
Author: lattner
Date: Tue Aug 17 18:11:56 2010
New Revision: 111321
URL: http://llvm.org/viewvc/llvm-project?rev=111321&view=rev
Log:
Fix the rest of rdar://8318441 which happens when a raw_fd_ostream
(e.g. errs()) fails in close() due to (e.g.) a broken pipe. As
previously written, the had_error() flag would get set and then
the raw_ostream dtor would report a fatal error. There is nothing
the client can do about this and we have no way to report the error,
so just eat it.
Modified:
llvm/trunk/lib/Support/raw_ostream.cpp
Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=111321&r1=111320&r2=111321&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Tue Aug 17 18:11:56 2010
@@ -415,15 +415,31 @@
raw_fd_ostream::~raw_fd_ostream() {
if (FD < 0) return;
- flush();
- if (ShouldClose)
- while (::close(FD) != 0)
- if (errno != EINTR) {
- error_detected();
- break;
- }
+ if (!ShouldClose) {
+ flush();
+ return;
+ }
+
+ bool HadError = has_error();
+ close();
+
+ // If we had a failure closing the stream, there is no way for the client to
+ // handle it, just eat the failure.
+ if (!HadError && has_error())
+ clear_error();
}
+void raw_fd_ostream::close() {
+ assert(ShouldClose);
+ ShouldClose = false;
+ flush();
+ while (::close(FD) != 0)
+ if (errno != EINTR) {
+ error_detected();
+ break;
+ }
+ FD = -1;
+}
void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
assert(FD >= 0 && "File already closed.");
@@ -461,18 +477,6 @@
} while (Size > 0);
}
-void raw_fd_ostream::close() {
- assert(ShouldClose);
- ShouldClose = false;
- flush();
- while (::close(FD) != 0)
- if (errno != EINTR) {
- error_detected();
- break;
- }
- FD = -1;
-}
-
uint64_t raw_fd_ostream::seek(uint64_t off) {
flush();
pos = ::lseek(FD, off, SEEK_SET);
More information about the llvm-commits
mailing list