Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b910626 authored by Keith Mok's avatar Keith Mok Committed by Automerger Merge Worker
Browse files

Merge "Improper EINTR handling logic" am: bd0a86f9

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1891585

Change-Id: I3037743d6b8e09252d37f92b1de1907fa19898a1
parents d353c81c bd0a86f9
Loading
Loading
Loading
Loading
+8 −13
Original line number Original line Diff line number Diff line
@@ -30,11 +30,8 @@ static bool writeAllBytes(const int fd, void* buffer, const size_t byteCount) {
    char* writeBuffer = static_cast<char*>(buffer);
    char* writeBuffer = static_cast<char*>(buffer);
    size_t remainingBytes = byteCount;
    size_t remainingBytes = byteCount;
    while (remainingBytes > 0) {
    while (remainingBytes > 0) {
        ssize_t writtenByteCount = write(fd, writeBuffer, remainingBytes);
        ssize_t writtenByteCount = TEMP_FAILURE_RETRY(write(fd, writeBuffer, remainingBytes));
        if (writtenByteCount == -1) {
        if (writtenByteCount == -1) {
            if (errno == EINTR) {
                continue;
            }
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
                    "Error writing to buffer: %d", errno);
                    "Error writing to buffer: %d", errno);
            return false;
            return false;
@@ -49,19 +46,17 @@ static bool readAllBytes(const int fd, void* buffer, const size_t byteCount) {
    char* readBuffer = static_cast<char*>(buffer);
    char* readBuffer = static_cast<char*>(buffer);
    size_t remainingBytes = byteCount;
    size_t remainingBytes = byteCount;
    while (remainingBytes > 0) {
    while (remainingBytes > 0) {
        ssize_t readByteCount = read(fd, readBuffer, remainingBytes);
        ssize_t readByteCount = TEMP_FAILURE_RETRY(read(fd, readBuffer, remainingBytes));

        remainingBytes -= readByteCount;
        readBuffer += readByteCount;

        if (readByteCount == -1) {
        if (readByteCount == -1) {
            if (errno == EINTR) {
                continue;
            }
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
                    "Error reading from buffer: %d", errno);
                    "Error reading from buffer: %d", errno);
            return false;
            return false;
        } else if (readByteCount == 0 && remainingBytes > 0) {
        }

        remainingBytes -= readByteCount;
        readBuffer += readByteCount;

        if (readByteCount == 0 && remainingBytes > 0) {
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
                    "File closed before all bytes were read. %zu/%zu remaining", remainingBytes,
                    "File closed before all bytes were read. %zu/%zu remaining", remainingBytes,
                    byteCount);
                    byteCount);