commit 899435e1997583bd01ab31e363fe3153486dd134 Author: Matt Howell mhowell@mozilla.com Date: Thu Feb 2 15:29:32 2017 -0800
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 --- toolkit/xre/nsUpdateDriver.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/toolkit/xre/nsUpdateDriver.cpp b/toolkit/xre/nsUpdateDriver.cpp index a9dbeff..7af085a 100644 --- a/toolkit/xre/nsUpdateDriver.cpp +++ b/toolkit/xre/nsUpdateDriver.cpp @@ -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
tor-commits@lists.torproject.org