OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
(...skipping 20 matching lines...) Expand all Loading... | |
31 void set_fd(int fd) { fd_ = fd; } | 31 void set_fd(int fd) { fd_ = fd; } |
32 | 32 |
33 private: | 33 private: |
34 int fd_; | 34 int fd_; |
35 | 35 |
36 DISALLOW_COPY_AND_ASSIGN(FileHandle); | 36 DISALLOW_COPY_AND_ASSIGN(FileHandle); |
37 }; | 37 }; |
38 | 38 |
39 | 39 |
40 File::~File() { | 40 File::~File() { |
41 // Close the file (unless it's a standard stream). | 41 Close(); |
42 if (handle_->fd() > STDERR_FILENO) { | |
43 Close(); | |
44 } | |
45 delete handle_; | 42 delete handle_; |
46 } | 43 } |
47 | 44 |
48 | 45 |
49 void File::Close() { | 46 void File::Close() { |
50 ASSERT(handle_->fd() >= 0); | 47 ASSERT(handle_->fd() >= 0); |
51 int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(handle_->fd())); | 48 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
| |
52 if (err != 0) { | 49 // If stdout, redirect fd to /dev/null. |
53 const int kBufferSize = 1024; | 50 int null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY)); |
54 char error_buf[kBufferSize]; | 51 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. :)
| |
55 Log::PrintErr("%s\n", strerror_r(errno, error_buf, kBufferSize)); | 52 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
| |
53 VOID_TEMP_FAILURE_RETRY(close(null_fd)); | |
54 } else { | |
55 int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(handle_->fd())); | |
56 if (err != 0) { | |
57 const int kBufferSize = 1024; | |
58 char error_buf[kBufferSize]; | |
59 Log::PrintErr("%s\n", strerror_r(errno, error_buf, kBufferSize)); | |
60 } | |
56 } | 61 } |
57 handle_->set_fd(kClosedFd); | 62 handle_->set_fd(kClosedFd); |
58 } | 63 } |
59 | 64 |
60 | 65 |
61 bool File::IsClosed() { | 66 bool File::IsClosed() { |
62 return handle_->fd() == kClosedFd; | 67 return handle_->fd() == kClosedFd; |
63 } | 68 } |
64 | 69 |
65 | 70 |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 return (file_1_info.st_ino == file_2_info.st_ino && | 422 return (file_1_info.st_ino == file_2_info.st_ino && |
418 file_1_info.st_dev == file_2_info.st_dev) ? | 423 file_1_info.st_dev == file_2_info.st_dev) ? |
419 File::kIdentical : | 424 File::kIdentical : |
420 File::kDifferent; | 425 File::kDifferent; |
421 } | 426 } |
422 | 427 |
423 } // namespace bin | 428 } // namespace bin |
424 } // namespace dart | 429 } // namespace dart |
425 | 430 |
426 #endif // defined(TARGET_OS_LINUX) | 431 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |