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

Commit bb5b6454 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "even more O_CLOEXECs!"

parents 9343b88b 5d5bf1f4
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)));
      }
    }
  }