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/12/16 02:27:26 UTC

[2/4] mesos git commit: Used `os::var()` for the default value in agent `--runtime_dir`.

Used `os::var()` for the default value in agent `--runtime_dir`.

This commit improves the logic of `Flags::runtime_dir` to use
`os::var()` for encapsulation of `/var` vs `C:\\ProgramData`.

The flags still contain some platform specific `#ifdef`-ing as the
desired runtime path is structured differently.  On POSIX, the
default is `/var/run/mesos`.  On Windows, the default is
`C:\\ProgramData\mesos\runtime`.  Notice that the relative position of
"run(time)" is flipped.

The permission check for the default path is fixed to check actual
access permissions to the directory, instead of assuming permissions
based on comparison of usernames.

Stylistically we chose a bit of duplication as a trade-off for enhanced
readability and for auto-formatting to work properly.

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


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

Branch: refs/heads/master
Commit: a0f5caa2f1562a0d7f0247fd1940ed76e5b0f878
Parents: 3b61aae
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Thu Dec 15 15:54:40 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Thu Dec 15 16:50:01 2016 -0800

----------------------------------------------------------------------
 src/slave/flags.cpp | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a0f5caa2/src/slave/flags.cpp
----------------------------------------------------------------------
diff --git a/src/slave/flags.cpp b/src/slave/flags.cpp
index a1dfbf9..5fb91fb 100644
--- a/src/slave/flags.cpp
+++ b/src/slave/flags.cpp
@@ -217,22 +217,29 @@ mesos::internal::slave::Flags::Flags()
       "not across reboots). This directory will be cleared on reboot.\n"
       "(Example: `/var/run/mesos`)",
       []() -> string {
+        Try<std::string> var = os::var();
+        if (var.isSome()) {
 #ifdef __WINDOWS__
-        // TODO(josephw): After adding a platform-dependent helper
-        // for determining the "var" directory, consider removing
-        // this `#ifdef`.
-        return path::join(os::temp(), "mesos", "runtime");
+          const std::string prefix(var.get());
 #else
-        Result<string> user = os::user();
-        CHECK_SOME(user);
-
-        // TODO(andschwa): Check for permissions instead of user.
-        if (user.get() == "root") {
-          return path::join("/var", "run", "mesos");
-        } else {
-          return path::join(os::temp(), "mesos", "runtime");
-        }
+          const std::string prefix(path::join(var.get(), "run"));
+#endif // __WINDOWS__
+
+          // We check for access on the prefix because the remainder
+          // of the directory structure is created by the agent later.
+          Try<bool> access = os::access(prefix, R_OK | W_OK);
+          if (access.isSome() && access.get()) {
+#ifdef __WINDOWS__
+            return path::join(prefix, "mesos", "runtime");
+#else
+            return path::join(prefix, "mesos");
 #endif // __WINDOWS__
+          }
+        }
+
+        // We provide a fallback path for ease of use in case `os::var()`
+        // errors or if the directory is not accessible.
+        return path::join(os::temp(), "mesos", "runtime");
       }());
 
   add(&Flags::launcher_dir, // TODO(benh): This needs a better name.