logcat: replace write() calls with WriteFully()
There is a possibility of data loss if an interrupt occurs in the
middle of these write() calls.
Test: logcat -g/-S/-B work correctly
Change-Id: I2dd4ec10771714fc49b61538d3028983516e106c
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index b5d2aa4..6b7e016 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -64,6 +64,7 @@
using android::base::ParseUint;
using android::base::Split;
using android::base::StringPrintf;
+using android::base::WriteFully;
class Logcat {
public:
@@ -864,8 +865,7 @@
if (consolePipe) {
// need the trailing '\0'
- if (!android::base::WriteFully(fd, pipePurpose.c_str(),
- pipePurpose.size() + 1)) {
+ if (!WriteFully(fd, pipePurpose.c_str(), pipePurpose.size() + 1)) {
close(fd);
return EXIT_FAILURE;
}
@@ -1078,7 +1078,9 @@
buffer_name, size_format.first, size_format.second, consumed_format.first,
consumed_format.second, readable_format.first, readable_format.second,
(int)LOGGER_ENTRY_MAX_LEN, (int)LOGGER_ENTRY_MAX_PAYLOAD);
- TEMP_FAILURE_RETRY(write(output_fd_.get(), str.data(), str.length()));
+ if (!WriteFully(output_fd_, str.data(), str.length())) {
+ error(EXIT_FAILURE, errno, "Failed to write to output fd");
+ }
}
}
}
@@ -1148,7 +1150,9 @@
if (*cp == '\n') ++cp;
size_t len = strlen(cp);
- TEMP_FAILURE_RETRY(write(output_fd_.get(), cp, len));
+ if (!WriteFully(output_fd_, cp, len)) {
+ error(EXIT_FAILURE, errno, "Failed to write to output fd");
+ }
return EXIT_SUCCESS;
}
@@ -1192,7 +1196,9 @@
PrintDividers(log_msg.id(), printDividers);
if (print_binary_) {
- TEMP_FAILURE_RETRY(write(output_fd_.get(), &log_msg, log_msg.len()));
+ if (!WriteFully(output_fd_, &log_msg, log_msg.len())) {
+ error(EXIT_FAILURE, errno, "Failed to write to output fd");
+ }
} else {
ProcessBuffer(&log_msg);
}