Merge "adb: handle some edge cases with process environments."
This commit is contained in:
commit
80f3b0438d
1 changed files with 11 additions and 6 deletions
|
|
@ -250,13 +250,18 @@ bool Subprocess::ForkAndExec() {
|
||||||
// Construct the environment for the child before we fork.
|
// Construct the environment for the child before we fork.
|
||||||
passwd* pw = getpwuid(getuid());
|
passwd* pw = getpwuid(getuid());
|
||||||
std::unordered_map<std::string, std::string> env;
|
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;
|
// Drop any values that don't contain '='.
|
||||||
while (char* env_cstr = *current++) {
|
if (delimiter) {
|
||||||
std::string env_string = env_cstr;
|
*delimiter++ = '\0';
|
||||||
char* delimiter = strchr(env_string.c_str(), '=');
|
env[env_string.c_str()] = delimiter;
|
||||||
*delimiter++ = '\0';
|
}
|
||||||
env[env_string.c_str()] = delimiter;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pw != nullptr) {
|
if (pw != nullptr) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue