From 639e93ee9cb443b307acd9de9137857fea45c1e3 Mon Sep 17 00:00:00 2001 From: Keith Mok Date: Mon, 15 Nov 2021 04:26:08 +0000 Subject: [PATCH] Improper EINTR handling logic When EINTR received, we should just continue the loop without update the byte counte and pointer Use TEMP_FAILURE_RETRY for that Test: CtsPrintTestCases Bug: 206810144 Change-Id: Ia8b580ed0e3af00e9a2afefe554b81cbe014054b --- ...printspooler_util_BitmapSerializeUtils.cpp | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/PrintSpooler/jni/com_android_printspooler_util_BitmapSerializeUtils.cpp b/packages/PrintSpooler/jni/com_android_printspooler_util_BitmapSerializeUtils.cpp index 7ff9cedab5f70..b2c82c6fb846e 100644 --- a/packages/PrintSpooler/jni/com_android_printspooler_util_BitmapSerializeUtils.cpp +++ b/packages/PrintSpooler/jni/com_android_printspooler_util_BitmapSerializeUtils.cpp @@ -30,11 +30,8 @@ static bool writeAllBytes(const int fd, void* buffer, const size_t byteCount) { char* writeBuffer = static_cast(buffer); size_t remainingBytes = byteCount; while (remainingBytes > 0) { - ssize_t writtenByteCount = write(fd, writeBuffer, remainingBytes); + ssize_t writtenByteCount = TEMP_FAILURE_RETRY(write(fd, writeBuffer, remainingBytes)); if (writtenByteCount == -1) { - if (errno == EINTR) { - continue; - } __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Error writing to buffer: %d", errno); return false; @@ -49,19 +46,17 @@ static bool readAllBytes(const int fd, void* buffer, const size_t byteCount) { char* readBuffer = static_cast(buffer); size_t remainingBytes = byteCount; while (remainingBytes > 0) { - ssize_t readByteCount = read(fd, readBuffer, remainingBytes); + ssize_t readByteCount = TEMP_FAILURE_RETRY(read(fd, readBuffer, remainingBytes)); + if (readByteCount == -1) { + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, + "Error reading from buffer: %d", errno); + return false; + } remainingBytes -= readByteCount; readBuffer += readByteCount; - if (readByteCount == -1) { - if (errno == EINTR) { - continue; - } - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, - "Error reading from buffer: %d", errno); - return false; - } else if (readByteCount == 0 && remainingBytes > 0) { + if (readByteCount == 0 && remainingBytes > 0) { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "File closed before all bytes were read. %zu/%zu remaining", remainingBytes, byteCount);