Commit 69a4e82c authored by Matt Howell's avatar Matt Howell Committed by Georg Koppen
Browse files

Bug 1335916 - Make sure the update driver only calls SetupMacCommandLine from...

Bug 1335916 - Make sure the update driver only calls SetupMacCommandLine from the main thread. r=rstrong

MozReview-Commit-ID: 9nOgB6z8ooE

--HG--
extra : rebase_source : 6a6a18f64297a0bd44e7d6f49b1812e035636e4c
parent 24697b9c
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include "nsCommandLineServiceMac.h"
#include "MacLaunchHelper.h"
#include "updaterfileutils_osx.h"
#include "mozilla/Monitor.h"
#endif

#if defined(XP_WIN)
@@ -91,6 +92,33 @@ static const int kAppUpdaterIOPrioClassDefault = IOPRIO_CLASS_IDLE;
static const int  kAppUpdaterIOPrioLevelDefault = 0;      // Doesn't matter for CLASS IDLE
#endif

#ifdef XP_MACOSX
static void
UpdateDriverSetupMacCommandLine(int& argc, char**& argv, bool restart)
{
  if (NS_IsMainThread()) {
    CommandLineServiceMac::SetupMacCommandLine(argc, argv, restart);
    return;
  }
  // Bug 1335916: SetupMacCommandLine calls a CoreFoundation function that
  // asserts that it was called from the main thread, so if we are not the main
  // thread, we have to dispatch that call to there. But we also have to get the
  // result from it, so we can't just dispatch and return, we have to wait
  // until the dispatched operation actually completes. So we also set up a
  // monitor to signal us when that happens, and block until then.
  Monitor monitor("nsUpdateDriver SetupMacCommandLine");

  NS_DispatchToMainThread(
    NS_NewRunnableFunction([&argc, &argv, restart, &monitor]() -> void
    {
      CommandLineServiceMac::SetupMacCommandLine(argc, argv, restart);
      MonitorAutoLock(monitor).Notify();
    }));

  MonitorAutoLock(monitor).Wait();
}
#endif

static nsresult
GetCurrentWorkingDir(char *buf, size_t size)
{
@@ -735,7 +763,7 @@ SwitchToUpdatedApp(nsIFile *greDir, nsIFile *updateDir,
  }
  _exit(0);
#elif defined(XP_MACOSX)
  CommandLineServiceMac::SetupMacCommandLine(argc, argv, true);
  UpdateDriverSetupMacCommandLine(argc, argv, true);
  LaunchChildMac(argc, argv);
  exit(0);
#else
@@ -1072,7 +1100,7 @@ ApplyUpdate(nsIFile *greDir, nsIFile *updateDir, nsIFile *statusFile,
    _exit(0);
  }
#elif defined(XP_MACOSX)
  CommandLineServiceMac::SetupMacCommandLine(argc, argv, restart);
  UpdateDriverSetupMacCommandLine(argc, argv, restart);
#ifdef DEBUG
  dump_argv("ApplyUpdate after SetupMacCommandLine", argv, argc);
#endif