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

Commit 35167389 authored by Nick Kralevich's avatar Nick Kralevich Committed by android-build-merger
Browse files

Merge "even more O_CLOEXECs!" am: bb5b6454 am: 6130adad

am: 8da21b7b

Change-Id: Ia4e37933ee5742f74e7d58e4eaca71f89954aa00
parents 4e78dec0 8da21b7b
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -821,7 +821,7 @@ static bool NeedsNoRandomizeWorkaround() {

// Utility to close down the Zygote socket file descriptors while
// the child is still running as root with Zygote's privileges.  Each
// descriptor (if any) is closed via dup2(), replacing it with a valid
// descriptor (if any) is closed via dup3(), replacing it with a valid
// (open) descriptor to /dev/null.

static void DetachDescriptors(JNIEnv* env,
@@ -829,15 +829,15 @@ static void DetachDescriptors(JNIEnv* env,
                              fail_fn_t fail_fn) {

  if (fds_to_close.size() > 0) {
    android::base::unique_fd devnull_fd(open("/dev/null", O_RDWR));
    android::base::unique_fd devnull_fd(open("/dev/null", O_RDWR | O_CLOEXEC));
    if (devnull_fd == -1) {
      fail_fn(std::string("Failed to open /dev/null: ").append(strerror(errno)));
    }

    for (int fd : fds_to_close) {
      ALOGV("Switching descriptor %d to /dev/null", fd);
      if (dup2(devnull_fd, fd) == -1) {
        fail_fn(StringPrintf("Failed dup2() on descriptor %d: %s", fd, strerror(errno)));
      if (dup3(devnull_fd, fd, O_CLOEXEC) == -1) {
        fail_fn(StringPrintf("Failed dup3() on descriptor %d: %s", fd, strerror(errno)));
      }
    }
  }