You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/10/12 00:00:04 UTC

[3/4] mesos git commit: Added 'environment' flag to mesos-containerizer launch helper.

Added 'environment' flag to mesos-containerizer launch helper.

The flag is optional. If set, the command to be launched will use the
specified environment variables. If not set, the command will inherit
the environment variables of the calling process.

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


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

Branch: refs/heads/master
Commit: 7d60be7c17387673045f9486cd2b3b23a1ebae6e
Parents: c43c54a
Author: Jie Yu <yu...@gmail.com>
Authored: Mon Oct 10 22:25:28 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Oct 11 16:59:31 2016 -0700

----------------------------------------------------------------------
 src/slave/containerizer/mesos/launch.cpp | 34 +++++++++++++++++----------
 src/slave/containerizer/mesos/launch.hpp |  3 +++
 2 files changed, 25 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/7d60be7c/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index c6b669a..8a30ff8 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -71,6 +71,10 @@ MesosContainerizerLaunch::Flags::Flags()
       "command",
       "The command to execute.");
 
+  add(&environment,
+      "environment",
+      "The environment variables for the command.");
+
   add(&working_directory,
       "working_directory",
       "The working directory for the command. It has to be an absolute path \n"
@@ -605,8 +609,21 @@ int MesosContainerizerLaunch::execute()
     }
   }
 
-  // Relay the environment variables.
-  // TODO(jieyu): Consider using a clean environment.
+  // Prepare the executable and the argument list for the child.
+  string executable(command->shell()
+    ? os::Shell::name
+    : command->value().c_str());
+
+  os::raw::Argv argv(command->shell()
+    ? vector<string>({os::Shell::arg0, os::Shell::arg1, command->value()})
+    : vector<string>(command->arguments().begin(), command->arguments().end()));
+
+  // Prepare the environment for the child. If 'environment' is not
+  // specified, inherit the environment of the current process.
+  Option<os::raw::Envp> envp;
+  if (flags.environment.isSome()) {
+    envp = os::raw::Envp(flags.environment.get());
+  }
 
 #ifndef __WINDOWS__
   // If we have `containerStatusFd` set, then we need to fork-exec the
@@ -682,17 +699,10 @@ int MesosContainerizerLaunch::execute()
   }
 #endif // __WINDOWS__
 
-  if (command->shell()) {
-    // Execute the command using shell.
-    os::execlp(os::Shell::name,
-               os::Shell::arg0,
-               os::Shell::arg1,
-               command->value().c_str(),
-               (char*) nullptr);
+  if (envp.isSome()) {
+    os::execvpe(executable.c_str(), argv, envp.get());
   } else {
-    // Use execvp to launch the command.
-    os::execvp(command->value().c_str(),
-               os::raw::Argv(command->arguments()));
+    os::execvp(executable.c_str(), argv);
   }
 
   // If we get here, the execle call failed.

http://git-wip-us.apache.org/repos/asf/mesos/blob/7d60be7c/src/slave/containerizer/mesos/launch.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.hpp b/src/slave/containerizer/mesos/launch.hpp
index 208ad2b..cfbf790 100644
--- a/src/slave/containerizer/mesos/launch.hpp
+++ b/src/slave/containerizer/mesos/launch.hpp
@@ -17,6 +17,8 @@
 #ifndef __MESOS_CONTAINERIZER_LAUNCH_HPP__
 #define __MESOS_CONTAINERIZER_LAUNCH_HPP__
 
+#include <string>
+
 #include <stout/json.hpp>
 #include <stout/option.hpp>
 #include <stout/subcommand.hpp>
@@ -37,6 +39,7 @@ public:
     Flags();
 
     Option<JSON::Object> command;
+    Option<JSON::Object> environment;
     Option<std::string> working_directory;
 #ifndef __WINDOWS__
     Option<std::string> runtime_directory;