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

Commit 5d5bf1f4 authored by Nick Kralevich's avatar Nick Kralevich
Browse files

even more O_CLOEXECs!

Bug: 120983106
Test: device boots and no obvious problems.
Change-Id: If13fc115187f36a4c577d74a7f138fa62a7316de
parent 38a641d2
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -659,7 +659,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,
@@ -667,15 +667,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)));
      }
    }
  }