From 532f9f53d8ee1273981107e03ef96dee9abb482e Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Tue, 2 Jul 2013 03:53:02 -0700 Subject: [PATCH] Mac installer: fix crash bug, improve translations. --- mac_installer/Installer.cpp | 99 +++++++++++------------------------ mac_installer/PostInstall.cpp | 5 ++ mac_installer/uninstall.cpp | 5 ++ 3 files changed, 40 insertions(+), 69 deletions(-) diff --git a/mac_installer/Installer.cpp b/mac_installer/Installer.cpp index 1511e76ba8..5ab7d68794 100644 --- a/mac_installer/Installer.cpp +++ b/mac_installer/Installer.cpp @@ -45,7 +45,6 @@ Boolean IsRestartNeeded(); static void GetPreferredLanguages(char * pkgPath); static void LoadPreferredLanguages(); static void ShowMessage(const char *format, ...); -OSErr FindProcess (OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN); static OSErr QuitAppleEventHandler(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon); void print_to_log_file(const char *format, ...); void strip_cr(char *buf); @@ -72,10 +71,9 @@ int main(int argc, char *argv[]) char MetaPkgPath[MAXPATHLEN], MetaPkgRestartPath[MAXPATHLEN]; char brand[64], s[256]; char *p; - ProcessSerialNumber ourPSN, installerPSN; + ProcessSerialNumber ourPSN; FSRef ourFSRef; long response; - pid_t installerPID = 0; OSStatus err = noErr; struct stat stat_buf; Boolean restartNeeded = true; @@ -133,42 +131,38 @@ int main(int argc, char *argv[]) *p = '\0'; ShowMessage((char *)_("Sorry, this version of %s requires system 10.4 or higher."), brand); - err = FindProcess ('APPL', 'xins', &installerPSN); - err = GetProcessPID(&installerPSN , &installerPID); + } else { - if (err == noErr) - err = kill(installerPID, SIGKILL); + // Remove previous installer package receipt so we can run installer again + // (affects only older versions of OS X and fixes a bug in those versions) + // "rm -rf /Library/Receipts/GridRepublic.pkg" + sprintf(s, "rm -rf \"/Library/Receipts/%s.pkg\"", brand); + system (s); - ExitToShell(); - } - - // Remove previous installer package receipt so we can run installer again - // (affects only older versions of OS X and fixes a bug in those versions) - // "rm -rf /Library/Receipts/GridRepublic.pkg" - sprintf(s, "rm -rf \"/Library/Receipts/%s.pkg\"", brand); - system (s); - - restartNeeded = IsRestartNeeded(); - - // Write a temp file to tell our PostInstall.app whether restart is needed - restartNeededFile = fopen("/tmp/BOINC_restart_flag", "w"); - if (restartNeededFile) { - fputs(restartNeeded ? "1\n" : "0\n", restartNeededFile); - fclose(restartNeededFile); - } - - err = Gestalt(gestaltSystemVersion, &response); - if (err != noErr) - return err; - - if (err == noErr) { - if ((response < 0x1050) || stat(MetaPkgPath, &stat_buf)) { // stat() returns zero on success - sprintf(infoPlistPath, "open \"%s\" &", restartNeeded ? pkgRestartPath : pkgPath); - } else { - sprintf(infoPlistPath, "open \"%s\" &", restartNeeded ? MetaPkgRestartPath : MetaPkgPath); + restartNeeded = IsRestartNeeded(); + + // Write a temp file to tell our PostInstall.app whether restart is needed + restartNeededFile = fopen("/tmp/BOINC_restart_flag", "w"); + if (restartNeededFile) { + fputs(restartNeeded ? "1\n" : "0\n", restartNeededFile); + fclose(restartNeededFile); + } + + err = Gestalt(gestaltSystemVersion, &response); + if (err != noErr) + return err; + + if (err == noErr) { + if ((response < 0x1050) || stat(MetaPkgPath, &stat_buf)) { // stat() returns zero on success + sprintf(infoPlistPath, "open \"%s\" &", restartNeeded ? pkgRestartPath : pkgPath); + } else { + sprintf(infoPlistPath, "open \"%s\" &", restartNeeded ? MetaPkgRestartPath : MetaPkgPath); + } + system(infoPlistPath); } - system(infoPlistPath); } + + system("rm -dfR /tmp/BOINC_PAX"); return err; } @@ -393,8 +387,6 @@ cleanup: CFArrayRemoveAllValues(supportedLanguages); CFRelease(supportedLanguages); supportedLanguages = NULL; - - system("rm -dfR /tmp/BOINC_PAX"); } @@ -406,7 +398,7 @@ static void LoadPreferredLanguages(){ BOINCTranslationInit(); - // Install.app wrote a list of our preferred languages to a temp file + // GetPreferredLanguages() wrote a list of our preferred languages to a temp file f = fopen("/tmp/BOINC_preferred_languages", "r"); if (!f) return; @@ -460,37 +452,6 @@ static void ShowMessage(const char *format, ...) { } -// --------------------------------------------------------------------------- -/* This runs through the process list looking for the indicated application */ -/* Searches for process by file type and signature (creator code) */ -// --------------------------------------------------------------------------- -OSErr FindProcess (OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN) -{ - ProcessInfoRec tempInfo; - FSSpec procSpec; - Str31 processName; - OSErr myErr = noErr; - /* null out the PSN so we're starting at the beginning of the list */ - processSN->lowLongOfPSN = kNoProcess; - processSN->highLongOfPSN = kNoProcess; - /* initialize the process information record */ - tempInfo.processInfoLength = sizeof(ProcessInfoRec); - tempInfo.processName = processName; - tempInfo.processAppSpec = &procSpec; - /* loop through all the processes until we */ - /* 1) find the process we want */ - /* 2) error out because of some reason (usually, no more processes) */ - do { - myErr = GetNextProcess(processSN); - if (myErr == noErr) - GetProcessInformation(processSN, &tempInfo); - } - while ((tempInfo.processSignature != creatorToFind || tempInfo.processType != typeToFind) && - myErr == noErr); - return(myErr); -} - - static OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon ) { gQuitFlag = true; diff --git a/mac_installer/PostInstall.cpp b/mac_installer/PostInstall.cpp index 1883568fdc..d465afc813 100644 --- a/mac_installer/PostInstall.cpp +++ b/mac_installer/PostInstall.cpp @@ -1132,6 +1132,11 @@ static char * PersistentFGets(char *buf, size_t buflen, FILE *f) { // user, before the Apple Installer switches us to root. // So we get the preferred languages in our Installer.app which // writes them to a temporary file which we retrieve here. +// We must do it this way because, for unknown reasons, the +// CFBundleCopyLocalizationsForPreferences() API does not work +// correctly if we seteuid and setuid to the logged in user by +// calling SetEUIDBackToUser() after running as root. +// static void LoadPreferredLanguages(){ FILE *f; int i; diff --git a/mac_installer/uninstall.cpp b/mac_installer/uninstall.cpp index 951eede8a3..001b3ca922 100644 --- a/mac_installer/uninstall.cpp +++ b/mac_installer/uninstall.cpp @@ -1375,6 +1375,11 @@ static void SleepTicks(UInt32 ticksToSleep) { // user, before we switch to root in our second pass. // So we get the preferred languages here and write them to a // temporary file to be retrieved by our second pass. +// We must do it this way because, for unknown reasons, the +// CFBundleCopyLocalizationsForPreferences() API does not work +// correctly if we seteuid and setuid to the logged in user +// after running as root. + static void GetPreferredLanguages() { DIR *dirp; struct dirent *dp;