diff --git a/ipc/chromium/src/base/process_util.h b/ipc/chromium/src/base/process_util.h index fe1b4d2b420..054cb647818 100644 --- a/ipc/chromium/src/base/process_util.h +++ b/ipc/chromium/src/base/process_util.h @@ -19,6 +19,7 @@ #include #endif +#include #include #include @@ -132,6 +133,14 @@ typedef std::vector > file_handle_mapping_vector; bool LaunchApp(const std::vector& argv, const file_handle_mapping_vector& fds_to_remap, bool wait, ProcessHandle* process_handle); + +#if defined(CHROMIUM_MOZILLA_BUILD) && defined(OS_LINUX) +typedef std::map environment_map; +bool LaunchApp(const std::vector& argv, + const file_handle_mapping_vector& fds_to_remap, + const environment_map& env_vars_to_set, + bool wait, ProcessHandle* process_handle); +#endif #endif // Executes the application specified by cl. This function delegates to one diff --git a/ipc/chromium/src/base/process_util_linux.cc b/ipc/chromium/src/base/process_util_linux.cc index 3a567af1279..574ac6574f1 100644 --- a/ipc/chromium/src/base/process_util_linux.cc +++ b/ipc/chromium/src/base/process_util_linux.cc @@ -32,9 +32,21 @@ static mozilla::EnvironmentLog gProcessLog("MOZ_PROCESS_LOG"); namespace base { +#if defined(CHROMIUM_MOZILLA_BUILD) bool LaunchApp(const std::vector& argv, const file_handle_mapping_vector& fds_to_remap, bool wait, ProcessHandle* process_handle) { + return LaunchApp(argv, fds_to_remap, environment_map(), + wait, process_handle); +} +#endif + +bool LaunchApp(const std::vector& argv, + const file_handle_mapping_vector& fds_to_remap, +#if defined(CHROMIUM_MOZILLA_BUILD) + const environment_map& env_vars_to_set, +#endif + bool wait, ProcessHandle* process_handle) { pid_t pid = fork(); if (pid < 0) return false; @@ -51,6 +63,14 @@ bool LaunchApp(const std::vector& argv, CloseSuperfluousFds(fd_shuffle); +#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); + } +#endif + scoped_array argv_cstr(new char*[argv.size() + 1]); for (size_t i = 0; i < argv.size(); i++) argv_cstr[i] = const_cast(argv[i].c_str()); diff --git a/ipc/glue/GeckoChildProcessHost.cpp b/ipc/glue/GeckoChildProcessHost.cpp index 58beb1d1e82..b35498b54b5 100644 --- a/ipc/glue/GeckoChildProcessHost.cpp +++ b/ipc/glue/GeckoChildProcessHost.cpp @@ -51,8 +51,13 @@ #endif #include "nsExceptionHandler.h" +#include "nsDirectoryServiceDefs.h" +#include "nsIFile.h" + #include "mozilla/ipc/BrowserProcessSubThread.h" +using base::environment_map; + using mozilla::MonitorAutoEnter; using mozilla::ipc::GeckoChildProcessHost; @@ -180,18 +185,20 @@ GeckoChildProcessHost::PerformAsyncLaunch(std::vector aExtraOpts) // we split the logic here. FilePath exePath; + environment_map newEnvVars; nsCOMPtr directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID)); nsCOMPtr greDir; nsresult rv = directoryService->Get(NS_GRE_DIR, NS_GET_IID(nsIFile), getter_AddRefs(greDir)); - if (NS_SUCCEEDED(rv)) - { + if (NS_SUCCEEDED(rv)) { nsCString path; greDir->GetNativePath(path); exePath = FilePath(path.get()); +#ifdef OS_LINUX + newEnvVars["LD_LIBRARY_PATH"] = path.get(); +#endif } - else - { + else { exePath = FilePath(CommandLine::ForCurrentProcess()->argv()[0]); exePath = exePath.DirName(); } @@ -231,7 +238,11 @@ GeckoChildProcessHost::PerformAsyncLaunch(std::vector aExtraOpts) } #endif - base::LaunchApp(childArgv, mFileMap, false, &process); + base::LaunchApp(childArgv, mFileMap, +#ifdef OS_LINUX + newEnvVars, +#endif + false, &process); //-------------------------------------------------- #elif defined(OS_WIN) diff --git a/ipc/glue/GeckoChildProcessHost.h b/ipc/glue/GeckoChildProcessHost.h index 6c67cd61ebb..5e71d0f1617 100644 --- a/ipc/glue/GeckoChildProcessHost.h +++ b/ipc/glue/GeckoChildProcessHost.h @@ -47,9 +47,6 @@ #include "nsXULAppAPI.h" // for GeckoProcessType -#include "nsDirectoryServiceDefs.h" -#include "nsIFile.h" - namespace mozilla { namespace ipc {