From e3ed9dec468079e3837ccc3f4c3165b038dc2f6d Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Wed, 3 Feb 2016 15:06:48 -0500 Subject: [PATCH] transfer environment to child process --- command.cpp | 9 ++++++++- environment.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/command.cpp b/command.cpp index fee3a85..1796abc 100644 --- a/command.cpp +++ b/command.cpp @@ -67,7 +67,14 @@ namespace { if (pid == 0) { - // also export environment... + // export environment... + + for (const auto &kv : env) { + if (kv.second) { // exported + std::string name = "mpw$" + kv.first; + setenv(name.c_str(), kv.second.c_str(), 1); + } + } // handle any indirection... fds.dup(); diff --git a/environment.h b/environment.h index 1621311..e40cae2 100644 --- a/environment.h +++ b/environment.h @@ -17,6 +17,8 @@ public: operator const std::string&() const { return value; } operator std::string&() { return value; } + const char *c_str() const { return value.c_str(); } + EnvironmentEntry() = default; EnvironmentEntry(const EnvironmentEntry &) = default; EnvironmentEntry(EnvironmentEntry &&) = default;