From: Christopher Dykes Date: Wed, 5 Apr 2017 19:50:28 +0000 (-0700) Subject: Disable EnvUtil::setAsCurrentEnvironment() on platforms without clearenv() X-Git-Tag: v2017.04.10.00~15 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=2d2d3d3f923a6efb92ad2d17b10098b33ea68d02 Disable EnvUtil::setAsCurrentEnvironment() on platforms without clearenv() Summary: Implementing `clearenv()` correctly on multiple OS's without relying on underlying implementation details is significantly more complicated, and this is preventing being able to build on OSX. This function isn't actually used anywhere currently. Reviewed By: yfeldblum Differential Revision: D4832473 fbshipit-source-id: a80aabb5a223264746ab45e3138d065bce5fe99c --- diff --git a/folly/experimental/EnvUtil.cpp b/folly/experimental/EnvUtil.cpp index 5c16ee74..1035575d 100644 --- a/folly/experimental/EnvUtil.cpp +++ b/folly/experimental/EnvUtil.cpp @@ -44,12 +44,14 @@ EnvironmentState EnvironmentState::fromCurrentEnvironment() { return EnvironmentState{std::move(data)}; } +#if __linux__ && !FOLLY_MOBILE void EnvironmentState::setAsCurrentEnvironment() { PCHECK(0 == clearenv()); for (const auto& kvp : env_) { PCHECK(0 == setenv(kvp.first.c_str(), kvp.second.c_str(), (int)true)); } } +#endif std::vector EnvironmentState::toVector() const { std::vector result; diff --git a/folly/experimental/EnvUtil.h b/folly/experimental/EnvUtil.h index 3ab3b16a..3ab06164 100644 --- a/folly/experimental/EnvUtil.h +++ b/folly/experimental/EnvUtil.h @@ -64,12 +64,14 @@ struct EnvironmentState { return &env_; } +#if __linux__ && !FOLLY_MOBILE // Update the process environment with the one in the stored model. // Subsequent changes to the model do not alter the process environment. The // state of the process environment during execution of this method is not // defined. If the process environment is altered by another thread during the // execution of this method the results are not defined. void setAsCurrentEnvironment(); +#endif // Get a copy of the model environment in the form used by `folly::Subprocess` std::vector toVector() const; diff --git a/folly/experimental/test/EnvUtilTest.cpp b/folly/experimental/test/EnvUtilTest.cpp index bcac455d..1e1e3d2d 100644 --- a/folly/experimental/test/EnvUtilTest.cpp +++ b/folly/experimental/test/EnvUtilTest.cpp @@ -132,6 +132,7 @@ TEST(EnvironmentStateTest, Separation) { EXPECT_STREQ("foon", getenv("spork")); } +#if __linux__ && !FOLLY_MOBILE TEST(EnvironmentStateTest, Update) { EnvVarSaver saver{}; auto env = EnvironmentState::fromCurrentEnvironment(); @@ -141,6 +142,7 @@ TEST(EnvironmentStateTest, Update) { env.setAsCurrentEnvironment(); EXPECT_STREQ("foon", getenv("spork")); } +#endif TEST(EnvironmentStateTest, forSubprocess) { auto env = EnvironmentState::empty();