Restart failed system calls interrupted with errno of EINTR
In number of places we don't handle properly system calls failures
when the errno is EINTR (i.e., the system call was interrupted
by a signal). In all our use cases, the system calls should be
restarted. The handling of the following system calls (as used in the code)
has been updated/fixed:
poll, send, recv, sendmsg, nanosleep, epoll_wait
read - mostly (e.g., socket-like fds)
write - mostly (e.g., socket-like fds)
select, accept, connect
Bug: 28471477
Bug: 28658141
Change-Id: I03e6f0f67e33876780fb6d02c33eb84547ba8f95
diff --git a/system/osi/src/metrics.cc b/system/osi/src/metrics.cc
index a99200b..064f99e 100644
--- a/system/osi/src/metrics.cc
+++ b/system/osi/src/metrics.cc
@@ -196,7 +196,9 @@
std::string protoBase64;
base::Base64Encode(serialized, &protoBase64);
- if (write(fd, protoBase64.c_str(), protoBase64.size()) == -1) {
+ ssize_t ret;
+ OSI_NO_INTR(ret = write(fd, protoBase64.c_str(), protoBase64.size()));
+ if (ret == -1) {
LOG_ERROR(LOG_TAG, "%s: error writing to dumpsys fd: %s (%d)", __func__,
strerror(errno), errno);
}
@@ -215,9 +217,10 @@
}
log_lock.unlock();
- if (write(fd, pretty_output.c_str(), pretty_output.size()) == -1) {
+ ssize_t ret;
+ OSI_NO_INTR(ret = write(fd, pretty_output.c_str(), pretty_output.size()));
+ if (ret == -1) {
LOG_ERROR(LOG_TAG, "%s: error writing to dumpsys fd: %s (%d)", __func__,
strerror(errno), errno);
}
-
}