diff options
author | 2021-11-18 18:03:38 +0000 | |
---|---|---|
committer | 2021-11-18 18:03:38 +0000 | |
commit | 86ef373a37df7d3cc923eecba6b40a7b7548f3d9 (patch) | |
tree | 94d4207095eb439747f38762fed88cbb5b9e0c07 | |
parent | fdbd7e4106bb9058997618f326dafdba6f669a0b (diff) | |
parent | 854f1bc5a484638b1b4e0172d2ac1a5a1694fb7a (diff) |
Merge "Improper EINTR handling logic" am: bd0a86f9d7 am: 1b9106268f am: b7ec41f5a0 am: 854f1bc5a4
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1891585
Change-Id: I245ec2da2ef2ac16adde23c986ef5c8a3b1436eb
-rw-r--r-- | packages/PrintSpooler/jni/com_android_printspooler_util_BitmapSerializeUtils.cpp | 21 |
1 files 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 7ff9cedab5f7..b2c82c6fb846 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<char*>(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<char*>(buffer); size_t remainingBytes = byteCount; while (remainingBytes > 0) { - ssize_t readByteCount = read(fd, readBuffer, remainingBytes); - - remainingBytes -= readByteCount; - readBuffer += readByteCount; - + ssize_t readByteCount = TEMP_FAILURE_RETRY(read(fd, readBuffer, remainingBytes)); 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) { + } + + remainingBytes -= readByteCount; + readBuffer += readByteCount; + + 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); |