Return-Path: X-Original-To: apmail-mesos-commits-archive@www.apache.org Delivered-To: apmail-mesos-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 956581194F for ; Tue, 20 May 2014 23:02:36 +0000 (UTC) Received: (qmail 55324 invoked by uid 500); 20 May 2014 23:02:36 -0000 Delivered-To: apmail-mesos-commits-archive@mesos.apache.org Received: (qmail 55288 invoked by uid 500); 20 May 2014 23:02:36 -0000 Mailing-List: contact commits-help@mesos.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mesos.apache.org Delivered-To: mailing list commits@mesos.apache.org Received: (qmail 55277 invoked by uid 99); 20 May 2014 23:02:36 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 May 2014 23:02:36 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 438A398442D; Tue, 20 May 2014 23:02:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: idownes@apache.org To: commits@mesos.apache.org Date: Tue, 20 May 2014 23:02:38 -0000 Message-Id: <5e75df72920f4531b7ce614291a98ff4@git.apache.org> In-Reply-To: <3ab1dcb8ff2e43d7883a5b0480b3a26b@git.apache.org> References: <3ab1dcb8ff2e43d7883a5b0480b3a26b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/5] git commit: Update Subprocess to use ExecEnv from stout. 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 Authored: Wed Apr 30 15:23:25 2014 -0700 Committer: Ian Downes 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 #include +#include + 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& 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& _environment) - : envp(NULL), - size(0) -{ - // Merge passed environment with OS environment, overriding where necessary. - hashmap 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( // 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())); + os::ExecEnv envp(environment.get(map())); pid_t pid; if ((pid = fork()) == -1) {