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/02/05 19:27:38 UTC

[2/2] mesos git commit: Added working dir flag to command executor.

Added working dir flag to command executor.

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


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

Branch: refs/heads/master
Commit: d27776d427007ac61a9107ed8d04cd429fc636db
Parents: e4e1e28
Author: Gilbert Song <so...@gmail.com>
Authored: Fri Feb 5 09:40:18 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Feb 5 10:25:38 2016 -0800

----------------------------------------------------------------------
 src/launcher/executor.cpp | 43 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 35 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d27776d4/src/launcher/executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index b214a3f..41ce439 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -82,6 +82,7 @@ public:
       const Option<char**>& override,
       const string& _healthCheckDir,
       const Option<string>& _sandboxDirectory,
+      const Option<string>& _workingDirectory,
       const Option<string>& _user,
       const Option<string>& _taskCommand)
     : state(REGISTERING),
@@ -95,6 +96,7 @@ public:
       healthCheckDir(_healthCheckDir),
       override(override),
       sandboxDirectory(_sandboxDirectory),
+      workingDirectory(_workingDirectory),
       user(_user),
       taskCommand(_taskCommand) {}
 
@@ -213,9 +215,12 @@ public:
       // If 'sandbox_diretory' is specified, that means the user
       // task specifies a root filesystem, and that root filesystem has
       // already been prepared at COMMAND_EXECUTOR_ROOTFS_CONTAINER_PATH.
-      // The command executor is reponsible for mounting the sandbox
+      // The command executor is responsible for mounting the sandbox
       // into the root filesystem, chrooting into it and changing the
       // user before exec-ing the user process.
+      //
+      // TODO(gilbert): Consider a better way to detect if a root
+      // filesystem is specified for the command task.
 #ifdef __linux__
       Result<string> user = os::user();
       if (user.isError()) {
@@ -345,10 +350,19 @@ public:
           abort();
         }
 
-        Try<Nothing> chdir = os::chdir(sandboxDirectory.get());
+        // Determine the current working directory for the executor.
+        string cwd;
+        if (workingDirectory.isSome()) {
+          cwd = workingDirectory.get();
+        } else {
+          CHECK_SOME(sandboxDirectory);
+          cwd = sandboxDirectory.get();
+        }
+
+        Try<Nothing> chdir = os::chdir(cwd);
         if (chdir.isError()) {
-          cerr << "Failed to change directory to sandbox dir '"
-               << sandboxDirectory.get() << "': " << chdir.error();
+          cerr << "Failed to chdir into current working directory '"
+               << cwd << "': " << chdir.error() << endl;
           abort();
         }
 
@@ -646,6 +660,7 @@ private:
   string healthCheckDir;
   Option<char**> override;
   Option<string> sandboxDirectory;
+  Option<string> workingDirectory;
   Option<string> user;
   Option<string> taskCommand;
 };
@@ -658,11 +673,17 @@ public:
       const Option<char**>& override,
       const string& healthCheckDir,
       const Option<string>& sandboxDirectory,
+      const Option<string>& workingDirectory,
       const Option<string>& user,
       const Option<string>& taskCommand)
   {
-    process = new CommandExecutorProcess(
-        override, healthCheckDir, sandboxDirectory, user, taskCommand);
+    process = new CommandExecutorProcess(override,
+                                         healthCheckDir,
+                                         sandboxDirectory,
+                                         workingDirectory,
+                                         user,
+                                         taskCommand);
+
     spawn(process);
   }
 
@@ -750,13 +771,17 @@ public:
         "subsequent 'argv' to be used with 'execvp'",
         false);
 
-    // The following flags are only applicable when a rootfs is provisioned
-    // for this command.
+    // The following flags are only applicable when a rootfs is
+    // provisioned for this command.
     add(&sandbox_directory,
         "sandbox_directory",
         "The absolute path for the directory in the container where the\n"
         "sandbox is mapped to");
 
+    add(&working_directory,
+        "working_directory",
+        "The working directory for the task in the container.");
+
     add(&user,
         "user",
         "The user that the task should be running as.");
@@ -772,6 +797,7 @@ public:
 
   bool override;
   Option<string> sandbox_directory;
+  Option<string> working_directory;
   Option<string> user;
   Option<string> task_command;
 };
@@ -816,6 +842,7 @@ int main(int argc, char** argv)
       override,
       path,
       flags.sandbox_directory,
+      flags.working_directory,
       flags.user,
       flags.task_command);