Backed out changeset 4a42968b790d (bug 1250901) for Mochitest M(oth) failures on OS X

This commit is contained in:
Iris Hsiao 2016-08-30 16:54:29 +08:00
parent 5a1fd6c4d4
commit 114e53ff4e
6 changed files with 91 additions and 25 deletions

View File

@ -98,6 +98,8 @@ static NS_DEFINE_CID(kXPCOMShutdownCID,
using namespace mozilla;
uint32_t gRestartMode = 0;
class nsAppExitEvent : public mozilla::Runnable {
private:
RefPtr<nsAppStartup> mService;
@ -386,10 +388,12 @@ nsAppStartup::Quit(uint32_t aMode)
mShuttingDown = true;
if (!mRestart) {
mRestart = (aMode & eRestart) != 0;
gRestartMode = (aMode & 0xF0);
}
if (!mRestartNotSameProfile) {
mRestartNotSameProfile = (aMode & eRestartNotSameProfile) != 0;
gRestartMode = (aMode & 0xF0);
}
if (mRestart || mRestartNotSameProfile) {

View File

@ -34,14 +34,14 @@ void LaunchChild(int argc, const char** argv)
@try {
NSString* launchPath = [NSString stringWithUTF8String:argv[0]];
NSMutableArray* arguments = [NSMutableArray arrayWithCapacity:argc - 1];
NSMutableArray* arguments = [NSMutableArray arrayWithCapacity:argc];
for (int i = 1; i < argc; i++) {
[arguments addObject:[NSString stringWithUTF8String:argv[i]]];
}
[NSTask launchedTaskWithLaunchPath:launchPath
arguments:arguments];
} @catch (NSException* e) {
NSLog(@"%@: %@", e.name, e.reason);
// Ignore any exception.
}
}

View File

@ -11,8 +11,10 @@
#include <unistd.h>
extern "C" {
void LaunchChildMac(int aArgc, char** aArgv, pid_t* aPid = 0);
bool LaunchElevatedUpdate(int aArgc, char** aArgv, pid_t* aPid = 0);
void LaunchChildMac(int aArgc, char** aArgv, uint32_t aRestartType = 0,
pid_t *pid = 0);
bool LaunchElevatedUpdate(int argc, char** argv, uint32_t aRestartType = 0,
pid_t* pid = 0);
}
#endif

View File

@ -19,23 +19,77 @@
using namespace mozilla;
void LaunchChildMac(int aArgc, char** aArgv, pid_t* aPid)
{
MacAutoreleasePool pool;
namespace {
cpu_type_t pref_cpu_types[2] = {
#if defined(__i386__)
CPU_TYPE_X86,
#elif defined(__x86_64__)
CPU_TYPE_X86_64,
#elif defined(__ppc__)
CPU_TYPE_POWERPC,
#endif
CPU_TYPE_ANY };
@try {
NSString* launchPath = [NSString stringWithUTF8String:aArgv[0]];
NSMutableArray* arguments = [NSMutableArray arrayWithCapacity:aArgc - 1];
for (int i = 1; i < aArgc; i++) {
[arguments addObject:[NSString stringWithUTF8String:aArgv[i]]];
}
NSTask* child = [NSTask launchedTaskWithLaunchPath:launchPath
arguments:arguments];
if (aPid) {
*aPid = [child processIdentifier];
}
} @catch (NSException* e) {
NSLog(@"%@: %@", e.name, e.reason);
cpu_type_t cpu_i386_types[2] = {
CPU_TYPE_X86,
CPU_TYPE_ANY };
cpu_type_t cpu_x64_86_types[2] = {
CPU_TYPE_X86_64,
CPU_TYPE_ANY };
} // namespace
void LaunchChildMac(int aArgc, char** aArgv,
uint32_t aRestartType, pid_t *pid)
{
// "posix_spawnp" uses null termination for arguments rather than a count.
// Note that we are not duplicating the argument strings themselves.
auto argv_copy = MakeUnique<char*[]>(aArgc + 1);
for (int i = 0; i < aArgc; i++) {
argv_copy[i] = aArgv[i];
}
argv_copy[aArgc] = NULL;
// Initialize spawn attributes.
posix_spawnattr_t spawnattr;
if (posix_spawnattr_init(&spawnattr) != 0) {
printf("Failed to init posix spawn attribute.");
return;
}
cpu_type_t *wanted_type = pref_cpu_types;
size_t attr_count = ArrayLength(pref_cpu_types);
if (aRestartType & nsIAppStartup::eRestarti386) {
wanted_type = cpu_i386_types;
attr_count = ArrayLength(cpu_i386_types);
} else if (aRestartType & nsIAppStartup::eRestartx86_64) {
wanted_type = cpu_x64_86_types;
attr_count = ArrayLength(cpu_x64_86_types);
}
// Set spawn attributes.
size_t attr_ocount = 0;
if (posix_spawnattr_setbinpref_np(&spawnattr, attr_count, wanted_type, &attr_ocount) != 0 ||
attr_ocount != attr_count) {
printf("Failed to set binary preference on posix spawn attribute.");
posix_spawnattr_destroy(&spawnattr);
return;
}
// Pass along our environment.
char** envp = NULL;
char*** cocoaEnvironment = _NSGetEnviron();
if (cocoaEnvironment) {
envp = *cocoaEnvironment;
}
int result = posix_spawnp(pid, argv_copy[0], NULL, &spawnattr, argv_copy.get(), envp);
posix_spawnattr_destroy(&spawnattr);
if (result != 0) {
printf("Process spawn failed with code %d!", result);
}
}
@ -122,9 +176,10 @@ void AbortElevatedUpdate()
NSLog(@"Unable to clean up updater.");
}
bool LaunchElevatedUpdate(int aArgc, char** aArgv, pid_t* aPid)
bool LaunchElevatedUpdate(int argc, char** argv, uint32_t aRestartType,
pid_t* pid)
{
LaunchChildMac(aArgc, aArgv, aPid);
LaunchChildMac(argc, argv, aRestartType, pid);
bool didSucceed = InstallPrivilegedHelper();
if (!didSucceed) {
AbortElevatedUpdate();

View File

@ -1749,7 +1749,9 @@ static nsresult LaunchChild(nsINativeAppSupport* aNative,
#else
#if defined(XP_MACOSX)
CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, true);
LaunchChildMac(gRestartArgc, gRestartArgv);
uint32_t restartMode = 0;
restartMode = gRestartMode;
LaunchChildMac(gRestartArgc, gRestartArgv, restartMode);
#else
nsCOMPtr<nsIFile> lf;
nsresult rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));

View File

@ -639,6 +639,9 @@ SwitchToUpdatedApp(nsIFile *greDir, nsIFile *updateDir,
_exit(0);
#elif defined(XP_MACOSX)
CommandLineServiceMac::SetupMacCommandLine(argc, argv, true);
// LaunchChildMac uses posix_spawnp and prefers the current
// architecture when launching. It doesn't require a
// null-terminated string but it doesn't matter if we pass one.
LaunchChildMac(argc, argv);
exit(0);
#else
@ -961,13 +964,13 @@ ApplyUpdate(nsIFile *greDir, nsIFile *updateDir, nsIFile *statusFile,
// occur when an admin user installs the application, but another admin
// user attempts to update (see bug 394984).
if (restart && !IsRecursivelyWritable(installDirPath.get())) {
if (!LaunchElevatedUpdate(argc, argv, outpid)) {
if (!LaunchElevatedUpdate(argc, argv, 0, outpid)) {
LOG(("Failed to launch elevated update!"));
exit(1);
}
exit(0);
} else {
LaunchChildMac(argc, argv, outpid);
LaunchChildMac(argc, argv, 0, outpid);
if (restart) {
exit(0);
}