You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/03/28 18:19:11 UTC

[5/7] mesos git commit: Subprocess: [5/7] Introduced parentHooks to fork calls.

Subprocess: [5/7] Introduced parentHooks to fork calls.

So far subprocess supports parentHooks. This review adds this option
also to fork().

Review: https://reviews.apache.org/r/45235/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/85f6145e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/85f6145e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/85f6145e

Branch: refs/heads/master
Commit: 85f6145e5ea34c2574e07ec97413a7010e76befe
Parents: dbddb6b
Author: Joerg Schad <jo...@mesosphere.io>
Authored: Mon Mar 28 17:02:18 2016 +0200
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Mar 28 18:17:15 2016 +0200

----------------------------------------------------------------------
 src/slave/containerizer/mesos/launcher.cpp       |  4 ++--
 src/slave/containerizer/mesos/launcher.hpp       | 13 +++++++++----
 src/slave/containerizer/mesos/linux_launcher.cpp |  7 ++-----
 src/slave/containerizer/mesos/linux_launcher.hpp |  3 ++-
 src/tests/containerizer/launcher.cpp             |  6 +++---
 src/tests/containerizer/launcher.hpp             |  5 +++--
 6 files changed, 21 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/85f6145e/src/slave/containerizer/mesos/launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launcher.cpp b/src/slave/containerizer/mesos/launcher.cpp
index c37eee0..a5c8c31 100644
--- a/src/slave/containerizer/mesos/launcher.cpp
+++ b/src/slave/containerizer/mesos/launcher.cpp
@@ -88,7 +88,8 @@ Try<pid_t> PosixLauncher::fork(
     const Subprocess::IO& err,
     const Option<flags::FlagsBase>& flags,
     const Option<map<string, string>>& environment,
-    const Option<int>& namespaces)
+    const Option<int>& namespaces,
+    vector<process::Subprocess::Hook> parentHooks)
 {
   if (pids.contains(containerId)) {
     return Error("Process has already been forked for container " +
@@ -97,7 +98,6 @@ Try<pid_t> PosixLauncher::fork(
 
   // If we are on systemd, then extend the life of the child. Any
   // grandchildren's lives will also be extended.
-  std::vector<Subprocess::Hook> parentHooks;
 #ifdef __linux__
   if (systemd::enabled()) {
     parentHooks.emplace_back(Subprocess::Hook(&systemd::mesos::extendLifetime));

http://git-wip-us.apache.org/repos/asf/mesos/blob/85f6145e/src/slave/containerizer/mesos/launcher.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launcher.hpp b/src/slave/containerizer/mesos/launcher.hpp
index 63d642c..5977c30 100644
--- a/src/slave/containerizer/mesos/launcher.hpp
+++ b/src/slave/containerizer/mesos/launcher.hpp
@@ -57,8 +57,9 @@ public:
   // Fork a new process in the containerized context. The child will
   // exec the binary at the given path with the given argv, flags and
   // environment. The I/O of the child will be redirected according to
-  // the specified I/O descriptors. The parent will return the child's
-  // pid if the fork is successful.
+  // the specified I/O descriptors. The parentHooks will be executed
+  // in the parent process before the child execs. The parent will return
+  // the child's pid if the fork is successful.
   virtual Try<pid_t> fork(
       const ContainerID& containerId,
       const std::string& path,
@@ -68,7 +69,9 @@ public:
       const process::Subprocess::IO& err,
       const Option<flags::FlagsBase>& flags,
       const Option<std::map<std::string, std::string>>& environment,
-      const Option<int>& namespaces) = 0;
+      const Option<int>& namespaces,
+      std::vector<process::Subprocess::Hook> parentHooks =
+        process::Subprocess::Hook::None()) = 0;
 
   // Kill all processes in the containerized context.
   virtual process::Future<Nothing> destroy(const ContainerID& containerId) = 0;
@@ -98,7 +101,9 @@ public:
       const process::Subprocess::IO& err,
       const Option<flags::FlagsBase>& flags,
       const Option<std::map<std::string, std::string>>& environment,
-      const Option<int>& namespaces);
+      const Option<int>& namespaces,
+      std::vector<process::Subprocess::Hook> parentHooks =
+        process::Subprocess::Hook::None());
 
   virtual process::Future<Nothing> destroy(const ContainerID& containerId);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/85f6145e/src/slave/containerizer/mesos/linux_launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/linux_launcher.cpp b/src/slave/containerizer/mesos/linux_launcher.cpp
index 7e82b0b..5028854 100644
--- a/src/slave/containerizer/mesos/linux_launcher.cpp
+++ b/src/slave/containerizer/mesos/linux_launcher.cpp
@@ -272,7 +272,8 @@ Try<pid_t> LinuxLauncher::fork(
     const process::Subprocess::IO& err,
     const Option<flags::FlagsBase>& flags,
     const Option<map<string, string>>& environment,
-    const Option<int>& namespaces)
+    const Option<int>& namespaces,
+    vector<Subprocess::Hook> parentHooks)
 {
   int cloneFlags = namespaces.isSome() ? namespaces.get() : 0;
   cloneFlags |= SIGCHLD; // Specify SIGCHLD as child termination signal.
@@ -280,10 +281,6 @@ Try<pid_t> LinuxLauncher::fork(
   LOG(INFO) << "Cloning child process with flags = "
             << ns::stringify(cloneFlags);
 
-  // NOTE: The child process will be blocked until all hooks have been
-  // executed.
-  vector<Subprocess::Hook> parentHooks;
-
   // NOTE: Currently we don't care about the order of the hooks, as
   // both hooks are independent.
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/85f6145e/src/slave/containerizer/mesos/linux_launcher.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/linux_launcher.hpp b/src/slave/containerizer/mesos/linux_launcher.hpp
index 3a0f378..89bb295 100644
--- a/src/slave/containerizer/mesos/linux_launcher.hpp
+++ b/src/slave/containerizer/mesos/linux_launcher.hpp
@@ -47,7 +47,8 @@ public:
       const process::Subprocess::IO& err,
       const Option<flags::FlagsBase>& flags,
       const Option<std::map<std::string, std::string>>& environment,
-      const Option<int>& namespaces);
+      const Option<int>& namespaces,
+      std::vector<process::Subprocess::Hook> parentHooks);
 
   virtual process::Future<Nothing> destroy(const ContainerID& containerId);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/85f6145e/src/tests/containerizer/launcher.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/launcher.cpp b/src/tests/containerizer/launcher.cpp
index 51ae4f9..a92d989 100644
--- a/src/tests/containerizer/launcher.cpp
+++ b/src/tests/containerizer/launcher.cpp
@@ -30,7 +30,7 @@ ACTION_P(InvokeRecover, launcher)
 ACTION_P(InvokeFork, launcher)
 {
   return launcher->real->fork(
-      arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
+      arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
 }
 
 
@@ -51,9 +51,9 @@ TestLauncher::TestLauncher(const process::Owned<slave::Launcher>& _real)
   EXPECT_CALL(*this, recover(_))
     .WillRepeatedly(DoDefault());
 
-  ON_CALL(*this, fork(_, _, _, _, _, _, _, _, _))
+  ON_CALL(*this, fork(_, _, _, _, _, _, _, _, _, _))
     .WillByDefault(InvokeFork(this));
-  EXPECT_CALL(*this, fork(_, _, _, _, _, _, _, _, _))
+  EXPECT_CALL(*this, fork(_, _, _, _, _, _, _, _, _, _))
     .WillRepeatedly(DoDefault());
 
   ON_CALL(*this, destroy(_))

http://git-wip-us.apache.org/repos/asf/mesos/blob/85f6145e/src/tests/containerizer/launcher.hpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/launcher.hpp b/src/tests/containerizer/launcher.hpp
index f7c4801..c352634 100644
--- a/src/tests/containerizer/launcher.hpp
+++ b/src/tests/containerizer/launcher.hpp
@@ -56,7 +56,7 @@ public:
       process::Future<hashset<ContainerID>>(
           const std::list<mesos::slave::ContainerState>& states));
 
-  MOCK_METHOD9(
+  MOCK_METHOD10(
       fork,
       Try<pid_t>(
           const ContainerID& containerId,
@@ -67,7 +67,8 @@ public:
           const process::Subprocess::IO& err,
           const Option<flags::FlagsBase>& flags,
           const Option<std::map<std::string, std::string> >& env,
-          const Option<int>& namespaces));
+          const Option<int>& namespaces,
+          std::vector<process::Subprocess::Hook> parentHooks));
 
   MOCK_METHOD1(
       destroy,