Bug 1386404 - Get content tmp dir early, avoid replacement on macOS. r?haik
MozReview-Commit-ID: IgedykIpPPJ
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -270,16 +270,26 @@ GeckoChildProcessHost::PrepareLaunch()
#if defined(MOZ_SANDBOX)
// For other process types we can't rely on them being launched on main
// thread and they may not have access to prefs in the child process, so allow
// them to turn on logging via an environment variable.
mEnableSandboxLogging = mEnableSandboxLogging
|| !!PR_GetEnv("MOZ_SANDBOX_LOGGING");
#endif
+#elif defined(XP_LINUX)
+ // Get and remember the path to the per-content-process tmpdir
+ if (ShouldHaveDirectoryService()) {
+ nsCOMPtr<nsIFile> mContentTempDir;
+ nsresult rv = NS_GetSpecialDirectory(NS_APP_CONTENT_PROCESS_TEMP_DIR,
+ getter_AddRefs(mContentTempDir));
+ if (NS_SUCCEEDED(rv)) {
+ mContentTempDir->GetNativePath(mTmpDirName);
+ }
+ }
#endif
}
#ifdef XP_WIN
void GeckoChildProcessHost::InitWindowsGroupID()
{
// On Win7+, pass the application user model to the child, so it can
// register with it. This insures windows created by the container
@@ -542,37 +552,30 @@ GeckoChildProcessHost::PerformAsyncLaunc
}
// `RUST_LOG_CHILD` is meant for logging child processes only.
const char* childRustLog = PR_GetEnv("RUST_LOG_CHILD");
if (childRustLog) {
rustLogDir.emplace("RUST_LOG", childRustLog, mRestoreOrigRustLog);
}
-#if defined(MOZ_CONTENT_SANDBOX)
+#if defined(XP_LINUX) && defined(MOZ_CONTENT_SANDBOX)
Maybe<AutoSetAndRestoreEnvVarForChildProcess> tmpDir;
Maybe<AutoSetAndRestoreEnvVarForChildProcess> xdgCacheHome;
Maybe<AutoSetAndRestoreEnvVarForChildProcess> xdgCacheDir;
Maybe<AutoSetAndRestoreEnvVarForChildProcess> mesaCacheDir;
- nsAutoCString tmpDirName;
- nsCOMPtr<nsIFile> mContentTempDir;
- nsresult rv = NS_GetSpecialDirectory(NS_APP_CONTENT_PROCESS_TEMP_DIR,
- getter_AddRefs(mContentTempDir));
- if (NS_SUCCEEDED(rv)) {
- rv = mContentTempDir->GetNativePath(tmpDirName);
- if (NS_SUCCEEDED(rv)) {
- // Point a bunch of things that might want to write from content to our
- // shiny new content-process specific tmpdir
- tmpDir.emplace("TMPDIR", tmpDirName, mRestoreTmpDir);
- xdgCacheHome.emplace("XDG_CACHE_HOME", tmpDirName, mRestoreXdgCacheHome);
- xdgCacheDir.emplace("XDG_CACHE_DIR", tmpDirName, mRestoreXdgCacheDir);
- // Partial fix for bug 1380051 (not persistent - should be)
- mesaCacheDir.emplace("MESA_GLSL_CACHE_DIR", tmpDirName, mRestoreMesaCacheDir);
- }
+ if (!mTmpDirName.IsEmpty()) {
+ // Point a bunch of things that might want to write from content to our
+ // shiny new content-process specific tmpdir
+ tmpDir.emplace("TMPDIR", mTmpDirName, mRestoreTmpDir);
+ xdgCacheHome.emplace("XDG_CACHE_HOME", mTmpDirName, mRestoreXdgCacheHome);
+ xdgCacheDir.emplace("XDG_CACHE_DIR", mTmpDirName, mRestoreXdgCacheDir);
+ // Partial fix for bug 1380051 (not persistent - should be)
+ mesaCacheDir.emplace("MESA_GLSL_CACHE_DIR", mTmpDirName, mRestoreMesaCacheDir);
}
#endif
return PerformAsyncLaunchInternal(aExtraOpts);
}
bool
GeckoChildProcessHost::RunPerformAsyncLaunch(std::vector<std::string> aExtraOpts)
--- a/ipc/glue/GeckoChildProcessHost.h
+++ b/ipc/glue/GeckoChildProcessHost.h
@@ -186,16 +186,18 @@ private:
// channel, there's a small window of time in which *we* might still
// be the channel listener, and receive messages. That's bad
// because we have no idea what to do with those messages. So queue
// them here until we hand off the eventual listener.
//
// FIXME/cjones: this strongly indicates bad design. Shame on us.
std::queue<IPC::Message> mQueue;
+ // Set this up before we're called from a different thread.
+ nsCString mTmpDirName;
// Remember original env values so we can restore it (there is no other
// simple way how to change environment of a child process than to modify
// the current environment).
nsCString mRestoreOrigNSPRLogName;
nsCString mRestoreOrigMozLogName;
nsCString mRestoreOrigRustLog;
nsCString mRestoreTmpDir;
nsCString mRestoreXdgCacheHome;