You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jp...@apache.org on 2018/08/19 17:40:15 UTC

[mesos] 02/04: Made the containerizer launch be explicit about O_CLOEXEC.

This is an automated email from the ASF dual-hosted git repository.

jpeach pushed a commit to branch 1.7.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 5f547effcc0b320f5dd381a0ffb328bf08722d7e
Author: James Peach <jp...@apache.org>
AuthorDate: Fri Aug 17 11:45:56 2018 -0700

    Made the containerizer launch be explicit about O_CLOEXEC.
    
    Since the containerizer launch depends on the inherited pipe to signal
    the forked child, be explicit about manipulating O_CLOEXEC on the pipe
    file descriptors. Make sure to close the pipe on the error paths.
    
    Review: https://reviews.apache.org/r/63280/
    (cherry picked from commit 7569ffd05903be9b5284100f67eeffb35fcc7703)
---
 src/slave/containerizer/mesos/containerizer.cpp  |  9 +++++++++
 src/slave/containerizer/mesos/launcher.cpp       | 11 ++++++++++-
 src/slave/containerizer/mesos/linux_launcher.cpp | 11 ++++++++++-
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp
index 98129d0..ba24180 100644
--- a/src/slave/containerizer/mesos/containerizer.cpp
+++ b/src/slave/containerizer/mesos/containerizer.cpp
@@ -1991,6 +1991,9 @@ Future<Containerizer::LaunchResult> MesosContainerizerProcess::_launch(
       whitelistFds);
 
   if (forked.isError()) {
+    os::close(pipes[0]);
+    os::close(pipes[1]);
+
     return Failure("Failed to fork: " + forked.error());
   }
 
@@ -2010,6 +2013,9 @@ Future<Containerizer::LaunchResult> MesosContainerizerProcess::_launch(
       LOG(ERROR) << "Failed to checkpoint container's forked pid to '"
                  << pidCheckpointPath.get() << "': " << checkpointed.error();
 
+      os::close(pipes[0]);
+      os::close(pipes[1]);
+
       return Failure("Could not checkpoint container's pid");
     }
   }
@@ -2033,6 +2039,9 @@ Future<Containerizer::LaunchResult> MesosContainerizerProcess::_launch(
   checkpointed = slave::state::checkpoint(pidPath, stringify(pid));
 
   if (checkpointed.isError()) {
+    os::close(pipes[0]);
+    os::close(pipes[1]);
+
     return Failure("Failed to checkpoint the container pid to"
                    " '" + pidPath + "': " + checkpointed.error());
   }
diff --git a/src/slave/containerizer/mesos/launcher.cpp b/src/slave/containerizer/mesos/launcher.cpp
index ed41a14..2935bda 100644
--- a/src/slave/containerizer/mesos/launcher.cpp
+++ b/src/slave/containerizer/mesos/launcher.cpp
@@ -119,6 +119,15 @@ Try<pid_t> SubprocessLauncher::fork(
   parentHooks.emplace_back(Subprocess::ParentHook::CREATE_JOB());
 #endif // __linux__
 
+  vector<Subprocess::ChildHook> childHooks;
+
+  childHooks.push_back(Subprocess::ChildHook::SETSID());
+
+  // TODO(jpeach) libprocess should take care of this, see MESOS-9164.
+  foreach (int_fd fd, whitelistFds) {
+    childHooks.push_back(Subprocess::ChildHook::UNSET_CLOEXEC(fd));
+  }
+
   Try<Subprocess> child = subprocess(
       path,
       argv,
@@ -129,7 +138,7 @@ Try<pid_t> SubprocessLauncher::fork(
       environment,
       None(),
       parentHooks,
-      {Subprocess::ChildHook::SETSID()},
+      childHooks,
       whitelistFds);
 
   if (child.isError()) {
diff --git a/src/slave/containerizer/mesos/linux_launcher.cpp b/src/slave/containerizer/mesos/linux_launcher.cpp
index d1f8d3f..e51352a 100644
--- a/src/slave/containerizer/mesos/linux_launcher.cpp
+++ b/src/slave/containerizer/mesos/linux_launcher.cpp
@@ -535,6 +535,15 @@ Try<pid_t> LinuxLauncherProcess::fork(
     }));
   }
 
+  vector<Subprocess::ChildHook> childHooks;
+
+  childHooks.push_back(Subprocess::ChildHook::SETSID());
+
+  // TODO(jpeach) libprocess should take care of this, see MESOS-9164.
+  foreach (int_fd fd, whitelistFds) {
+    childHooks.push_back(Subprocess::ChildHook::UNSET_CLOEXEC(fd));
+  }
+
   Try<Subprocess> child = subprocess(
       path,
       argv,
@@ -561,7 +570,7 @@ Try<pid_t> LinuxLauncherProcess::fork(
         }
       },
       parentHooks,
-      {Subprocess::ChildHook::SETSID()});
+      childHooks);
 
   if (child.isError()) {
     return Error("Failed to clone child process: " + child.error());