Index: runtime/bin/file_android.cc |
diff --git a/runtime/bin/file_android.cc b/runtime/bin/file_android.cc |
index b00e22de3bbc980d42319143dce10c7478bc9ecd..6c740c59fdf68b80b992f95ce39894e1021a4f2b 100644 |
--- a/runtime/bin/file_android.cc |
+++ b/runtime/bin/file_android.cc |
@@ -38,22 +38,27 @@ 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_message[kBufferSize]; |
- strerror_r(errno, error_message, kBufferSize); |
- Log::PrintErr("%s\n", error_message); |
+ if (handle_->fd() == STDOUT_FILENO) { |
+ // If stdout, redirect fd to /dev/null. |
+ int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); |
+ ASSERT(null_fd >= 0); |
+ VOID_TEMP_FAILURE_RETRY(dup2(null_fd, handle_->fd())); |
+ 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_message[kBufferSize]; |
+ strerror_r(errno, error_message, kBufferSize); |
+ Log::PrintErr("%s\n", error_message); |
+ } |
} |
handle_->set_fd(kClosedFd); |
} |