You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by tn...@apache.org on 2015/06/04 20:11:43 UTC

[3/3] mesos git commit: Refactored os::getenv() to return an option and removed os::hasenv().

Refactored os::getenv() to return an option and removed os::hasenv().

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


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

Branch: refs/heads/master
Commit: 2a74bcb5267d4dcded403d85df20b310950823a8
Parents: c394e14
Author: Greg Mann <Gr...@gmail.com>
Authored: Thu Jun 4 10:51:27 2015 -0700
Committer: Timothy Chen <tn...@apache.org>
Committed: Thu Jun 4 11:11:30 2015 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/os.hpp         | 28 ++++++--------------
 1 file changed, 8 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2a74bcb5/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 8ee02ef..68626b0 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -153,31 +153,18 @@ inline hashmap<std::string, std::string> environment()
 }
 
 
-// Checks if the specified key is in the environment variables.
-inline bool hasenv(const std::string& key)
-{
-  char* value = ::getenv(key.c_str());
-
-  return value != NULL;
-}
-
 // Looks in the environment variables for the specified key and
-// returns a string representation of it's value. If 'expected' is
-// true (default) and no environment variable matching key is found,
-// this function will exit the process.
-inline std::string getenv(const std::string& key, bool expected = true)
+// returns a string representation of its value. If no environment
+// variable matching key is found, None() is returned.
+inline Option<std::string> getenv(const std::string& key)
 {
   char* value = ::getenv(key.c_str());
 
-  if (expected && value == NULL) {
-    LOG(FATAL) << "Expecting '" << key << "' in environment variables";
-  }
-
-  if (value != NULL) {
-    return std::string(value);
+  if (value == NULL) {
+    return None();
   }
 
-  return std::string();
+  return std::string(value);
 }
 
 
@@ -1257,7 +1244,8 @@ inline std::string paths()
 #else
     "DYLD_LIBRARY_PATH";
 #endif
-  return getenv(environmentVariable, false);
+  const Option<std::string> path = getenv(environmentVariable);
+  return path.isSome() ? path.get() : std::string();
 }