Bug 1386404 - Get content tmp dir early, avoid replacement on macOS. r?haik draft
authorGian-Carlo Pascutto <gcp@mozilla.com>
Mon, 06 Nov 2017 17:04:20 +0100
changeset 693644 c7f5787684a29243f8290bcb2608e2db6ada4fe7
parent 693643 09242b2902ff7af3d6f01d7121e851f089c50f4c
child 739105 0fc0e8a674067029bd5f0bb5ab25de073c5e860d
push id87881
push usergpascutto@mozilla.com
push dateMon, 06 Nov 2017 18:00:57 +0000
reviewershaik
bugs1386404
milestone58.0a1
Bug 1386404 - Get content tmp dir early, avoid replacement on macOS. r?haik MozReview-Commit-ID: IgedykIpPPJ
ipc/glue/GeckoChildProcessHost.cpp
ipc/glue/GeckoChildProcessHost.h
--- 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;