Merge "adb: handle some edge cases with process environments."

am: 80f3b0438d

* commit '80f3b0438d84fba3c36cc73cfef992032cd33eb0':
  adb: handle some edge cases with process environments.
This commit is contained in:
Josh Gao 2015-12-11 16:49:30 -08:00 committed by android-build-merger
commit 412f6aaead

View file

@ -250,13 +250,18 @@ bool Subprocess::ForkAndExec() {
// Construct the environment for the child before we fork.
passwd* pw = getpwuid(getuid());
std::unordered_map<std::string, std::string> env;
if (environ) {
char** current = environ;
while (char* env_cstr = *current++) {
std::string env_string = env_cstr;
char* delimiter = strchr(env_string.c_str(), '=');
char** current = environ;
while (char* env_cstr = *current++) {
std::string env_string = env_cstr;
char* delimiter = strchr(env_string.c_str(), '=');
*delimiter++ = '\0';
env[env_string.c_str()] = delimiter;
// Drop any values that don't contain '='.
if (delimiter) {
*delimiter++ = '\0';
env[env_string.c_str()] = delimiter;
}
}
}
if (pw != nullptr) {