Index: runtime/bin/file_linux.cc |
diff --git a/runtime/bin/file_linux.cc b/runtime/bin/file_linux.cc |
index 2e79248cbd1a2381812119e35348fc95cd2fc710..92c5637c6158ae1958b97bf8d22de00fad38511a 100644 |
--- a/runtime/bin/file_linux.cc |
+++ b/runtime/bin/file_linux.cc |
@@ -15,9 +15,9 @@ |
#include <unistd.h> // NOLINT |
#include <libgen.h> // NOLINT |
+#include "platform/signal_blocker.h" |
#include "bin/builtin.h" |
#include "bin/log.h" |
-#include "bin/signal_blocker.h" |
namespace dart { |
@@ -52,7 +52,7 @@ void File::Close() { |
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())); |
+ int err = TEMP_FAILURE_RETRY(close(handle_->fd())); |
if (err != 0) { |
const int kBufferSize = 1024; |
char error_buf[kBufferSize]; |
@@ -70,47 +70,44 @@ bool File::IsClosed() { |
int64_t File::Read(void* buffer, int64_t num_bytes) { |
ASSERT(handle_->fd() >= 0); |
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(read(handle_->fd(), buffer, |
- num_bytes)); |
+ return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
} |
int64_t File::Write(const void* buffer, int64_t num_bytes) { |
ASSERT(handle_->fd() >= 0); |
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(write(handle_->fd(), buffer, |
- num_bytes)); |
+ return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); |
} |
int64_t File::Position() { |
ASSERT(handle_->fd() >= 0); |
- return lseek64(handle_->fd(), 0, SEEK_CUR); |
+ return NO_RETRY_EXPECTED(lseek64(handle_->fd(), 0, SEEK_CUR)); |
} |
bool File::SetPosition(int64_t position) { |
ASSERT(handle_->fd() >= 0); |
- return lseek64(handle_->fd(), position, SEEK_SET) >= 0; |
+ return NO_RETRY_EXPECTED(lseek64(handle_->fd(), position, SEEK_SET)) >= 0; |
} |
bool File::Truncate(int64_t length) { |
ASSERT(handle_->fd() >= 0); |
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS( |
- ftruncate64(handle_->fd(), length) != -1); |
+ return TEMP_FAILURE_RETRY(ftruncate64(handle_->fd(), length) != -1); |
} |
bool File::Flush() { |
ASSERT(handle_->fd() >= 0); |
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fsync(handle_->fd()) != -1); |
+ return NO_RETRY_EXPECTED(fsync(handle_->fd())) != -1; |
} |
int64_t File::Length() { |
ASSERT(handle_->fd() >= 0); |
struct stat64 st; |
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fstat64(handle_->fd(), &st)) == 0) { |
+ if (NO_RETRY_EXPECTED(fstat64(handle_->fd(), &st)) == 0) { |
return st.st_size; |
} |
return -1; |
@@ -120,7 +117,7 @@ int64_t File::Length() { |
File* File::Open(const char* name, FileOpenMode mode) { |
// Report errors for non-regular files. |
struct stat64 st; |
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { |
+ if (NO_RETRY_EXPECTED(stat64(name, &st)) == 0) { |
// Only accept regular files and character devices. |
if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) { |
errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
@@ -135,12 +132,12 @@ File* File::Open(const char* name, FileOpenMode mode) { |
flags = flags | O_TRUNC; |
} |
flags |= O_CLOEXEC; |
- int fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(open64(name, flags, 0666)); |
+ int fd = TEMP_FAILURE_RETRY(open64(name, flags, 0666)); |
if (fd < 0) { |
return NULL; |
} |
if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { |
- int64_t position = lseek64(fd, 0, SEEK_END); |
+ int64_t position = NO_RETRY_EXPECTED(lseek64(fd, 0, SEEK_END)); |
if (position < 0) { |
return NULL; |
} |
@@ -157,7 +154,7 @@ File* File::OpenStdio(int fd) { |
bool File::Exists(const char* name) { |
struct stat64 st; |
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { |
+ if (NO_RETRY_EXPECTED(stat64(name, &st)) == 0) { |
return S_ISREG(st.st_mode); |
} else { |
return false; |
@@ -166,25 +163,24 @@ bool File::Exists(const char* name) { |
bool File::Create(const char* name) { |
- int fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( |
+ int fd = TEMP_FAILURE_RETRY( |
open64(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666)); |
if (fd < 0) { |
return false; |
} |
- return (close(fd) == 0); |
+ return (TEMP_FAILURE_RETRY(close(fd)) == 0); |
} |
bool File::CreateLink(const char* name, const char* target) { |
- int status = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(symlink(target, name)); |
- return (status == 0); |
+ return NO_RETRY_EXPECTED(symlink(target, name)) == 0; |
} |
bool File::Delete(const char* name) { |
File::Type type = File::GetType(name, true); |
if (type == kIsFile) { |
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(unlink(name)) == 0; |
+ return NO_RETRY_EXPECTED(unlink(name)) == 0; |
} else if (type == kIsDirectory) { |
errno = EISDIR; |
} else { |
@@ -197,7 +193,7 @@ bool File::Delete(const char* name) { |
bool File::DeleteLink(const char* name) { |
File::Type type = File::GetType(name, false); |
if (type == kIsLink) { |
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(unlink(name)) == 0; |
+ return NO_RETRY_EXPECTED(unlink(name)) == 0; |
} |
errno = EINVAL; |
return false; |
@@ -207,7 +203,7 @@ bool File::DeleteLink(const char* name) { |
bool File::Rename(const char* old_path, const char* new_path) { |
File::Type type = File::GetType(old_path, true); |
if (type == kIsFile) { |
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(rename(old_path, new_path)) == 0; |
+ return NO_RETRY_EXPECTED(rename(old_path, new_path)) == 0; |
} else if (type == kIsDirectory) { |
errno = EISDIR; |
} else { |
@@ -220,7 +216,7 @@ bool File::Rename(const char* old_path, const char* new_path) { |
bool File::RenameLink(const char* old_path, const char* new_path) { |
File::Type type = File::GetType(old_path, false); |
if (type == kIsLink) { |
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(rename(old_path, new_path)) == 0; |
+ return NO_RETRY_EXPECTED(rename(old_path, new_path)) == 0; |
} else if (type == kIsDirectory) { |
errno = EISDIR; |
} else { |
@@ -234,25 +230,24 @@ bool File::Copy(const char* old_path, const char* new_path) { |
File::Type type = File::GetType(old_path, true); |
if (type == kIsFile) { |
struct stat64 st; |
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(old_path, &st)) != 0) { |
+ if (NO_RETRY_EXPECTED(stat64(old_path, &st)) != 0) { |
return false; |
} |
- int old_fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(open64(old_path, |
- O_RDONLY | O_CLOEXEC)); |
+ int old_fd = TEMP_FAILURE_RETRY(open64(old_path, O_RDONLY | O_CLOEXEC)); |
if (old_fd < 0) { |
return false; |
} |
- int new_fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( |
+ int new_fd = TEMP_FAILURE_RETRY( |
open64(new_path, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, st.st_mode)); |
if (new_fd < 0) { |
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(old_fd)); |
+ VOID_TEMP_FAILURE_RETRY(close(old_fd)); |
return false; |
} |
int64_t offset = 0; |
intptr_t result = 1; |
while (result > 0) { |
// Loop to ensure we copy everything, and not only up to 2GB. |
- result = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( |
+ result = NO_RETRY_EXPECTED( |
sendfile64(new_fd, old_fd, &offset, kMaxUint32)); |
} |
// From sendfile man pages: |
@@ -261,10 +256,9 @@ bool File::Copy(const char* old_path, const char* new_path) { |
if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { |
const intptr_t kBufferSize = 8 * KB; |
uint8_t buffer[kBufferSize]; |
- while ((result = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( |
+ while ((result = TEMP_FAILURE_RETRY( |
read(old_fd, buffer, kBufferSize))) > 0) { |
- int wrote = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(write(new_fd, buffer, |
- result)); |
+ int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); |
if (wrote != result) { |
result = -1; |
break; |
@@ -273,9 +267,9 @@ bool File::Copy(const char* old_path, const char* new_path) { |
} |
if (result < 0) { |
int e = errno; |
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(old_fd)); |
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(new_fd)); |
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(unlink(new_path)); |
+ VOID_TEMP_FAILURE_RETRY(close(old_fd)); |
+ VOID_TEMP_FAILURE_RETRY(close(new_fd)); |
+ VOID_NO_RETRY_EXPECTED(unlink(new_path)); |
errno = e; |
return false; |
} |
@@ -291,7 +285,7 @@ bool File::Copy(const char* old_path, const char* new_path) { |
int64_t File::LengthFromPath(const char* name) { |
struct stat64 st; |
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { |
+ if (NO_RETRY_EXPECTED(stat64(name, &st)) == 0) { |
return st.st_size; |
} |
return -1; |
@@ -300,7 +294,7 @@ int64_t File::LengthFromPath(const char* name) { |
void File::Stat(const char* name, int64_t* data) { |
struct stat64 st; |
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { |
+ if (NO_RETRY_EXPECTED(stat64(name, &st)) == 0) { |
if (S_ISREG(st.st_mode)) { |
data[kType] = kIsFile; |
} else if (S_ISDIR(st.st_mode)) { |
@@ -323,7 +317,7 @@ void File::Stat(const char* name, int64_t* data) { |
time_t File::LastModified(const char* name) { |
struct stat64 st; |
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { |
+ if (NO_RETRY_EXPECTED(stat64(name, &st)) == 0) { |
return st.st_mtime; |
} |
return -1; |
@@ -332,14 +326,15 @@ time_t File::LastModified(const char* name) { |
char* File::LinkTarget(const char* pathname) { |
struct stat64 link_stats; |
- if (lstat64(pathname, &link_stats) != 0) return NULL; |
+ if (NO_RETRY_EXPECTED(lstat64(pathname, &link_stats)) != 0) return NULL; |
if (!S_ISLNK(link_stats.st_mode)) { |
errno = ENOENT; |
return NULL; |
} |
size_t target_size = link_stats.st_size; |
char* target_name = reinterpret_cast<char*>(malloc(target_size + 1)); |
- size_t read_size = readlink(pathname, target_name, target_size + 1); |
+ size_t read_size = NO_RETRY_EXPECTED( |
+ readlink(pathname, target_name, target_size + 1)); |
if (read_size != target_size) { |
free(target_name); |
return NULL; |
@@ -379,7 +374,7 @@ const char* File::StringEscapedPathSeparator() { |
File::StdioHandleType File::GetStdioHandleType(int fd) { |
ASSERT(0 <= fd && fd <= 2); |
struct stat64 buf; |
- int result = fstat64(fd, &buf); |
+ int result = NO_RETRY_EXPECTED(fstat64(fd, &buf)); |
if (result == -1) { |
const int kBufferSize = 1024; |
char error_buf[kBufferSize]; |
@@ -398,11 +393,9 @@ File::Type File::GetType(const char* pathname, bool follow_links) { |
struct stat64 entry_info; |
int stat_success; |
if (follow_links) { |
- stat_success = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(pathname, |
- &entry_info)); |
+ stat_success = NO_RETRY_EXPECTED(stat64(pathname, &entry_info)); |
} else { |
- stat_success = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(lstat64(pathname, |
- &entry_info)); |
+ stat_success = NO_RETRY_EXPECTED(lstat64(pathname, &entry_info)); |
} |
if (stat_success == -1) return File::kDoesNotExist; |
if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; |
@@ -415,8 +408,8 @@ File::Type File::GetType(const char* pathname, bool follow_links) { |
File::Identical File::AreIdentical(const char* file_1, const char* file_2) { |
struct stat64 file_1_info; |
struct stat64 file_2_info; |
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(lstat64(file_1, &file_1_info)) == -1 || |
- TEMP_FAILURE_RETRY_BLOCK_SIGNALS(lstat64(file_2, &file_2_info)) == -1) { |
+ if (NO_RETRY_EXPECTED(lstat64(file_1, &file_1_info)) == -1 || |
+ NO_RETRY_EXPECTED(lstat64(file_2, &file_2_info)) == -1) { |
return File::kError; |
} |
return (file_1_info.st_ino == file_2_info.st_ino && |