From 33301ca730a85298b210b0c53e434762e6a1a6d2 Mon Sep 17 00:00:00 2001 From: Benoit Girard Date: Tue, 20 Jul 2010 00:17:45 -0400 Subject: [PATCH] Bug 557225 - Fix TryServer failures. r=cjones r=josh --- ipc/chromium/src/base/process_util_mac.mm | 54 +++++++++++++++++++++-- testing/xpcshell/runxpcshelltests.py | 2 +- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/ipc/chromium/src/base/process_util_mac.mm b/ipc/chromium/src/base/process_util_mac.mm index c11b7291fc28..d9cf95a63c8d 100644 --- a/ipc/chromium/src/base/process_util_mac.mm +++ b/ipc/chromium/src/base/process_util_mac.mm @@ -49,15 +49,43 @@ bool LaunchApp(const std::vector& argv, SetAllFDsToCloseOnExec(); #if defined(CHROMIUM_MOZILLA_BUILD) - for (environment_map::const_iterator it = env_vars_to_set.begin(); - it != env_vars_to_set.end(); ++it) { - if (setenv(it->first.c_str(), it->second.c_str(), 1/*overwrite*/)) - exit(127); + // Copy _NSGetEnviron() to a new char array and add the variables + // in env_vars_to_set. + // Existing variables are overwritten by env_vars_to_set. + int pos = 0; + environment_map combined_env_vars = env_vars_to_set; + while((*_NSGetEnviron())[pos] != NULL) { + std::string varString = (*_NSGetEnviron())[pos]; + std::string varName = varString.substr(0, varString.find_first_of('=')); + std::string varValue = varString.substr(varString.find_first_of('=') + 1); + if (combined_env_vars.find(varName) == combined_env_vars.end()) { + combined_env_vars[varName] = varValue; } + pos++; + } + int varsLen = combined_env_vars.size() + 1; + + char** vars = new char*[varsLen]; + int i = 0; + for (environment_map::const_iterator it = combined_env_vars.begin(); + it != combined_env_vars.end(); ++it) { + std::string entry(it->first); + entry += "="; + entry += it->second; + vars[i] = strdup(entry.c_str()); + i++; + } + vars[i] = NULL; #endif posix_spawn_file_actions_t file_actions; if (posix_spawn_file_actions_init(&file_actions) != 0) { +#if defined(CHROMIUM_MOZILLA_BUILD) + for(int j = 0; j < varsLen; j++) { + free(vars[j]); + } + delete[] vars; +#endif return false; } @@ -77,18 +105,36 @@ bool LaunchApp(const std::vector& argv, if (posix_spawn_file_actions_adddup2(&file_actions, src_fd, dest_fd) != 0) { posix_spawn_file_actions_destroy(&file_actions); +#if defined(CHROMIUM_MOZILLA_BUILD) + for(int j = 0; j < varsLen; j++) { + free(vars[j]); + } + delete[] vars; +#endif return false; } } } + int pid = 0; int spawn_succeeded = (posix_spawnp(&pid, argv_copy[0], &file_actions, NULL, argv_copy, +#if defined(CHROMIUM_MOZILLA_BUILD) + vars) == 0); +#else *_NSGetEnviron()) == 0); +#endif + +#if defined(CHROMIUM_MOZILLA_BUILD) + for(int j = 0; j < varsLen; j++) { + free(vars[j]); + } + delete[] vars; +#endif posix_spawn_file_actions_destroy(&file_actions); diff --git a/testing/xpcshell/runxpcshelltests.py b/testing/xpcshell/runxpcshelltests.py index 3d20e395f3b3..94646a9cb7f8 100644 --- a/testing/xpcshell/runxpcshelltests.py +++ b/testing/xpcshell/runxpcshelltests.py @@ -160,7 +160,7 @@ class XPCShellTests(object): elif sys.platform in ('os2emx', 'os2knix'): os.environ["BEGINLIBPATH"] = self.xrePath + ";" + self.env["BEGINLIBPATH"] os.environ["LIBPATHSTRICT"] = "T" - elif sys.platform == 'osx': + elif sys.platform == 'osx' or sys.platform == "darwin": self.env["DYLD_LIBRARY_PATH"] = self.xrePath else: # unix or linux? self.env["LD_LIBRARY_PATH"] = self.xrePath