diff options
author | Hans Boehm <hboehm@google.com> | 2021-07-19 16:49:19 -0700 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2021-09-27 21:17:05 +0800 |
commit | 2d702b3730ea803d2e288375881cb247ee733b5e (patch) | |
tree | b4689fd0ffd01502c7b458c48eb0d2c96aaf4404 | |
parent | f8f5e42b253066cadfefea34f17b5aa4befd4e6c (diff) |
[master] More consistently retry system calls on EINTR
We were not retrying an accept() call om EINTR, resulting in occasional
zygote failures. This fixes that, and a few other calls documented
to potentially return EINTR. This is based on a quick seacrh of the
two files affected by this CL.
Bug: 193753947
Bug: 187992348
Test: Build and boot AOSP
Change-Id: Icbfb38be5110607c121545e5c200ce65d1eefbfe
-rw-r--r-- | core/jni/com_android_internal_os_Zygote.cpp | 2 | ||||
-rw-r--r-- | core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp | 8 |
2 files changed, 5 insertions, 5 deletions
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index c57e500128b3..0187bf870c91 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -895,7 +895,7 @@ static void DetachDescriptors(JNIEnv* env, for (int fd : fds_to_close) { ALOGV("Switching descriptor %d to /dev/null", fd); - if (dup3(devnull_fd, fd, O_CLOEXEC) == -1) { + if (TEMP_FAILURE_RETRY(dup3(devnull_fd, fd, O_CLOEXEC)) == -1) { fail_fn(StringPrintf("Failed dup3() on descriptor %d: %s", fd, strerror(errno))); } } diff --git a/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp b/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp index 011e8f8f1b8c..4ea2fef97f2f 100644 --- a/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp +++ b/core/jni/com_android_internal_os_ZygoteCommandBuffer.cpp @@ -427,7 +427,7 @@ jboolean com_android_internal_os_ZygoteCommandBuffer_nativeForkRepeatedly( tmp_pid >>= 8; } pid_buf[4] = 0; // Process is not wrapped. - int res = write(session_socket, pid_buf, 5); + int res = TEMP_FAILURE_RETRY(write(session_socket, pid_buf, 5)); if (res != 5) { if (res == -1) { (first_time ? fail_fn_1 : fail_fn_n) @@ -452,18 +452,18 @@ jboolean com_android_internal_os_ZygoteCommandBuffer_nativeForkRepeatedly( } // We've now seen either a disconnect or connect request. close(session_socket); - int new_fd = accept(zygote_socket_fd, nullptr, nullptr); + int new_fd = TEMP_FAILURE_RETRY(accept(zygote_socket_fd, nullptr, nullptr)); if (new_fd == -1) { fail_fn_z("Accept(%d) failed: %s", zygote_socket_fd, strerror(errno)); } if (new_fd != session_socket) { // Move new_fd back to the old value, so that we don't have to change Java-level data // structures to reflect a change. This implicitly closes the old one. - if (dup2(new_fd, session_socket) != session_socket) { + if (TEMP_FAILURE_RETRY(dup2(new_fd, session_socket)) != session_socket) { fail_fn_z(CREATE_ERROR("Failed to move fd %d to %d: %s", new_fd, session_socket, strerror(errno))); } - close(new_fd); + close(new_fd); // On Linux, fd is closed even if EINTR is returned. } // If we ever return, we effectively reuse the old Java ZygoteConnection. // None of its state needs to change. |