bug 1376574 - Do not use fork() for launching the crashreporter on Mac since that might crash too; r?Ted draft
authorGabriele Svelto <gsvelto@mozilla.com>
Tue, 27 Jun 2017 23:39:30 +0200
changeset 645079 12ec0c0eb08cc18e584924e900a92a597e7c47dd
parent 643173 4c5fbf49376351679dcc49f4cff26c3c2e055ccc
child 725811 91db250a97377fd2d3ad842f0b4a7e5a476e2730
push id73654
push userbmo:gsvelto@mozilla.com
push dateFri, 11 Aug 2017 21:18:18 +0000
reviewersTed
bugs1376574
milestone57.0a1
bug 1376574 - Do not use fork() for launching the crashreporter on Mac since that might crash too; r?Ted MozReview-Commit-ID: BX1ig3rtoIr
toolkit/crashreporter/nsExceptionHandler.cpp
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -841,35 +841,52 @@ LaunchProgram(const XP_CHAR* aProgramPat
 
   // If CreateProcess() fails don't do anything
   if (CreateProcess(nullptr, (LPWSTR)cmdLine, nullptr, nullptr, FALSE,
                     NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
                     nullptr, nullptr, &si, &pi)) {
     CloseHandle(pi.hProcess);
     CloseHandle(pi.hThread);
   }
-#elif defined(XP_UNIX)
+#elif defined(XP_MACOSX)
+  // Needed to locate NSS and its dependencies
+  setenv("DYLD_LIBRARY_PATH", libraryPath, /* overwrite */ 1);
+
+  pid_t pid = 0;
+  char* const my_argv[] = {
+    const_cast<char*>(aProgramPath),
+    const_cast<char*>(aMinidumpPath),
+    nullptr
+  };
+
+  char **env = nullptr;
+  char ***nsEnv = _NSGetEnviron();
+  if (nsEnv) {
+    env = *nsEnv;
+  }
+
+  int rv = posix_spawnp(&pid, my_argv[0], nullptr, nullptr, my_argv, env);
+
+  if (rv != 0) {
+    return false;
+  }
+#else // !XP_MACOSX
   pid_t pid = sys_fork();
 
   if (pid == -1) {
     return false;
   } else if (pid == 0) {
-#ifdef XP_LINUX
     // need to clobber this, as libcurl might load NSS,
     // and we want it to load the system NSS.
     unsetenv("LD_LIBRARY_PATH");
-#else // XP_MACOSX
-    // Needed to locate NSS and its dependencies
-    setenv("DYLD_LIBRARY_PATH", libraryPath, /* overwrite */ 1);
-#endif
     Unused << execl(aProgramPath,
                     aProgramPath, aMinidumpPath, (char*)0);
     _exit(1);
   }
-#endif // XP_UNIX
+#endif // XP_MACOSX
 
   return true;
 }
 
 #else
 
 /**
  * Launch the crash reporter activity on Android