Index: runtime/bin/file_linux.cc |
diff --git a/runtime/bin/file_linux.cc b/runtime/bin/file_linux.cc |
index bc6f6109a5d708cb4dd0938b2fd70b7bf16bd3e2..b75ee5715f4d2801d887d73f22a236fd3f0c4241 100644 |
--- a/runtime/bin/file_linux.cc |
+++ b/runtime/bin/file_linux.cc |
@@ -38,21 +38,26 @@ class FileHandle { |
File::~File() { |
- // Close the file (unless it's a standard stream). |
- if (handle_->fd() > STDERR_FILENO) { |
- Close(); |
- } |
+ Close(); |
delete handle_; |
} |
void File::Close() { |
ASSERT(handle_->fd() >= 0); |
- int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(handle_->fd())); |
- if (err != 0) { |
- const int kBufferSize = 1024; |
- char error_buf[kBufferSize]; |
- Log::PrintErr("%s\n", strerror_r(errno, error_buf, kBufferSize)); |
+ if (handle_->fd() == STDOUT_FILENO) { |
Søren Gjesse
2014/02/07 11:05:11
Why is stderr not handled here as well?
Anders Johnsen
2014/02/14 08:43:28
It's only to work around print printing to file/so
|
+ // If stdout, redirect fd to /dev/null. |
+ int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); |
+ ASSERT(null_fd >= 0); |
Søren Gjesse
2014/02/07 11:05:11
So this will still affect "printf debugging".
Anders Johnsen
2014/02/14 08:43:28
Yes, intentionally. :)
|
+ VOID_TEMP_FAILURE_RETRY(dup2(null_fd, STDOUT_FILENO)); |
Søren Gjesse
2014/02/07 11:05:11
Use handle_->fd() instead of STDOUT_FILENO here.
Ivan Posva
2014/02/11 04:08:37
I am wondering whether we should have duped the st
Anders Johnsen
2014/02/14 08:43:28
Done.
Anders Johnsen
2014/02/14 08:43:28
That would still have given us this scenario where
|
+ VOID_TEMP_FAILURE_RETRY(close(null_fd)); |
+ } else { |
+ int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(handle_->fd())); |
+ if (err != 0) { |
+ const int kBufferSize = 1024; |
+ char error_buf[kBufferSize]; |
+ Log::PrintErr("%s\n", strerror_r(errno, error_buf, kBufferSize)); |
+ } |
} |
handle_->set_fd(kClosedFd); |
} |