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

Commit e4cd3790 authored by Hans Boehm's avatar Hans Boehm Committed by Automerger Merge Worker
Browse files

Merge "More consistently retry system calls on EINTR" am: e9554cb7 am:...

Merge "More consistently retry system calls on EINTR" am: e9554cb7 am: c9984045 am: 06376fc9 am: ebe38545

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

Change-Id: I154d87fdfd93dcb72d89477e3f52daddcefae7e1
parents 45c0aae0 ebe38545
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -887,7 +887,7 @@ static void DetachDescriptors(JNIEnv* env,


    for (int fd : fds_to_close) {
    for (int fd : fds_to_close) {
      ALOGV("Switching descriptor %d to /dev/null", fd);
      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)));
        fail_fn(StringPrintf("Failed dup3() on descriptor %d: %s", fd, strerror(errno)));
      }
      }
    }
    }
+4 −4
Original line number Original line Diff line number Diff line
@@ -426,7 +426,7 @@ jboolean com_android_internal_os_ZygoteCommandBuffer_nativeForkRepeatedly(
      tmp_pid >>= 8;
      tmp_pid >>= 8;
    }
    }
    pid_buf[4] = 0;  // Process is not wrapped.
    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 != 5) {
      if (res == -1) {
      if (res == -1) {
        (first_time ? fail_fn_1 : fail_fn_n)
        (first_time ? fail_fn_1 : fail_fn_n)
@@ -451,18 +451,18 @@ jboolean com_android_internal_os_ZygoteCommandBuffer_nativeForkRepeatedly(
      }
      }
      // We've now seen either a disconnect or connect request.
      // We've now seen either a disconnect or connect request.
      close(session_socket);
      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) {
      if (new_fd == -1) {
        fail_fn_z(CREATE_ERROR("Accept(%d) failed: %s", zygote_socket_fd, strerror(errno)));
        fail_fn_z(CREATE_ERROR("Accept(%d) failed: %s", zygote_socket_fd, strerror(errno)));
      }
      }
      if (new_fd != session_socket) {
      if (new_fd != session_socket) {
          // Move new_fd back to the old value, so that we don't have to change Java-level data
          // 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.
          // 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",
            fail_fn_z(CREATE_ERROR("Failed to move fd %d to %d: %s",
                                   new_fd, session_socket, strerror(errno)));
                                   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.
      // If we ever return, we effectively reuse the old Java ZygoteConnection.
      // None of its state needs to change.
      // None of its state needs to change.