diff options
Diffstat (limited to 'cmds/incidentd/src/FdBuffer.cpp')
-rw-r--r-- | cmds/incidentd/src/FdBuffer.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/cmds/incidentd/src/FdBuffer.cpp b/cmds/incidentd/src/FdBuffer.cpp index b7633a435653..30dd339a629b 100644 --- a/cmds/incidentd/src/FdBuffer.cpp +++ b/cmds/incidentd/src/FdBuffer.cpp @@ -26,6 +26,7 @@ #include <unistd.h> #include <wait.h> +const bool DEBUG = false; const ssize_t BUFFER_SIZE = 16 * 1024; // 16 KB const ssize_t MAX_BUFFER_COUNT = 256; // 4 MB max @@ -71,9 +72,11 @@ FdBuffer::read(int fd, int64_t timeout) mTimedOut = true; break; } else if (count < 0) { + if (DEBUG) ALOGD("poll failed: %s", strerror(errno)); return -errno; } else { if ((pfds.revents & POLLERR) != 0) { + if (DEBUG) ALOGD("return event has error %s", strerror(errno)); return errno != 0 ? -errno : UNKNOWN_ERROR; } else { ssize_t amt = ::read(fd, mBuffer.writeBuffer(), mBuffer.currentToWrite()); @@ -81,6 +84,7 @@ FdBuffer::read(int fd, int64_t timeout) if (errno == EAGAIN || errno == EWOULDBLOCK) { continue; } else { + if (DEBUG) ALOGD("Fail to read %d: %s", fd, strerror(errno)); return -errno; } } else if (amt == 0) { @@ -95,7 +99,7 @@ FdBuffer::read(int fd, int64_t timeout) } status_t -FdBuffer::readProcessedDataInStream(int fd, int toFd, int fromFd, int64_t timeoutMs) +FdBuffer::readProcessedDataInStream(int fd, int toFd, int fromFd, int64_t timeoutMs, const bool isSysfs) { struct pollfd pfds[] = { { .fd = fd, .events = POLLIN }, @@ -135,12 +139,18 @@ FdBuffer::readProcessedDataInStream(int fd, int toFd, int fromFd, int64_t timeou mTimedOut = true; break; } else if (count < 0) { + if (DEBUG) ALOGD("Fail to poll: %s", strerror(errno)); return -errno; } // make sure no errors occur on any fds for (int i = 0; i < 3; ++i) { if ((pfds[i].revents & POLLERR) != 0) { + if (i == 0 && isSysfs) { + if (DEBUG) ALOGD("fd %d is sysfs, ignore its POLLERR return value", fd); + continue; + } + if (DEBUG) ALOGD("fd[%d]=%d returns error events: %s", i, fd, strerror(errno)); return errno != 0 ? -errno : UNKNOWN_ERROR; } } @@ -155,6 +165,7 @@ FdBuffer::readProcessedDataInStream(int fd, int toFd, int fromFd, int64_t timeou } if (amt < 0) { if (!(errno == EAGAIN || errno == EWOULDBLOCK)) { + if (DEBUG) ALOGD("Fail to read fd %d: %s", fd, strerror(errno)); return -errno; } // otherwise just continue } else if (amt == 0) { // reach EOF so don't have to poll pfds[0]. @@ -176,6 +187,7 @@ FdBuffer::readProcessedDataInStream(int fd, int toFd, int fromFd, int64_t timeou } if (amt < 0) { if (!(errno == EAGAIN || errno == EWOULDBLOCK)) { + if (DEBUG) ALOGD("Fail to write toFd %d: %s", toFd, strerror(errno)); return -errno; } // otherwise just continue } else { @@ -202,6 +214,7 @@ FdBuffer::readProcessedDataInStream(int fd, int toFd, int fromFd, int64_t timeou ssize_t amt = ::read(fromFd, mBuffer.writeBuffer(), mBuffer.currentToWrite()); if (amt < 0) { if (!(errno == EAGAIN || errno == EWOULDBLOCK)) { + if (DEBUG) ALOGD("Fail to read fromFd %d: %s", fromFd, strerror(errno)); return -errno; } // otherwise just continue } else if (amt == 0) { |