mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From idow...@apache.org
Subject [3/5] git commit: Update Subprocess to use ExecEnv from stout.
Date Tue, 20 May 2014 23:02:38 GMT
Update Subprocess to use ExecEnv from stout.

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


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

Branch: refs/heads/master
Commit: b8cbeac60f6eaf46c471c606f07466e9b0d0d572
Parents: 2482788
Author: Ian Downes <idownes@twitter.com>
Authored: Wed Apr 30 15:23:25 2014 -0700
Committer: Ian Downes <idownes@twitter.com>
Committed: Tue May 20 15:25:32 2014 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/src/subprocess.cpp | 61 ++---------------------------
 1 file changed, 3 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b8cbeac6/3rdparty/libprocess/src/subprocess.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/subprocess.cpp b/3rdparty/libprocess/src/subprocess.cpp
index 27a4355..9f8f37f 100644
--- a/3rdparty/libprocess/src/subprocess.cpp
+++ b/3rdparty/libprocess/src/subprocess.cpp
@@ -18,6 +18,8 @@
 #include <stout/os.hpp>
 #include <stout/try.hpp>
 
+#include <stout/os/execenv.hpp>
+
 using std::map;
 using std::string;
 
@@ -42,63 +44,6 @@ void cleanup(
   delete promise;
 }
 
-// Used to build the environment passed to the subproces.
-class Envp
-{
-public:
-  explicit Envp(const map<string, string>& environment);
-  ~Envp();
-
-  char** operator () () const { return envp; }
-
-private:
-  // Not default constructable, not copyable, not assignable.
-  Envp();
-  Envp(const Envp&);
-  Envp& operator = (const Envp&);
-
-  char** envp;
-  size_t size;
-};
-
-
-Envp::Envp(const map<string, string>& _environment)
-  : envp(NULL),
-    size(0)
-{
-  // Merge passed environment with OS environment, overriding where necessary.
-  hashmap<string, string> environment = os::environment();
-
-  foreachpair (const string& key, const string& value, _environment) {
-    environment[key] = value;
-  }
-
-  size = environment.size();
-
-  // Convert environment to internal representation.
-  // Add 1 to the size for a NULL terminator.
-  envp = new char*[size + 1];
-  int index = 0;
-  foreachpair (const string& key, const string& value, environment) {
-    string entry = key + "=" + value;
-    envp[index] = new char[entry.size() + 1];
-    strncpy(envp[index], entry.c_str(), entry.size() + 1);
-    ++index;
-  }
-
-  envp[index] = NULL;
-}
-
-
-Envp::~Envp()
-{
-  for (size_t i = 0; i < size; ++i) {
-    delete[] envp[i];
-  }
-  delete[] envp;
-  envp = NULL;
-}
-
 }  // namespace internal {
 
 
@@ -133,7 +78,7 @@ Try<Subprocess> subprocess(
   // TODO(tillt): Consider optimizing this to not pass an empty map
   // into the constructor or even further to use execl instead of
   // execle once we have no user supplied environment.
-  internal::Envp envp(environment.get(map<string, string>()));
+  os::ExecEnv envp(environment.get(map<string, string>()));
 
   pid_t pid;
   if ((pid = fork()) == -1) {


Mime
View raw message