diff --git a/mac_installer/Installer.cpp b/mac_installer/Installer.cpp index b41d38901f..595bae253c 100644 --- a/mac_installer/Installer.cpp +++ b/mac_installer/Installer.cpp @@ -17,8 +17,8 @@ /* Installer.cpp */ -#define CREATE_LOG 0 /* for debugging */ -#define VERBOSE_TEST 0 +#define CREATE_LOG 0 /* for general debugging */ +#define VERBOSE_TEST 0 /* for debugging callPosixSpawn */ #include #include @@ -48,7 +48,6 @@ Boolean IsRestartNeeded(); static void GetPreferredLanguages(); static void LoadPreferredLanguages(); static void ShowMessage(const char *format, ...); -static void ShowError(int lineNum); static OSErr QuitAppleEventHandler(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon); int callPosixSpawn(const char *cmd); void print_to_log_file(const char *format, ...); @@ -58,7 +57,7 @@ void strip_cr(char *buf); // have not yet been installed when this application is run. #define MAX_LANGUAGES_TO_TRY 5 -#define REPORT_ERROR(isError) if (isError) ShowError(__LINE__) +#define REPORT_ERROR(isError) if (isError) print_to_log_file("BOINC Installer error at line %d", __LINE__); static char * Catalog_Name = (char *)"BOINC-Setup"; static char Catalogs_Dir[MAXPATHLEN]; @@ -88,7 +87,17 @@ int main(int argc, char *argv[]) } strncpy(loginName, getenv("USER"), sizeof(loginName)-1); - REPORT_ERROR(loginName[0] == '\0'); + if (loginName[0] == '\0') { + ShowMessage((char *)_("Could not get user login name")); + return 0; + } + + snprintf(temp, sizeof(temp), "/tmp/%s", loginName); + mkdir(temp, 0777); + chmod(temp, 0777); // Needed because mkdir sets permissions restricted by umask (022) + + snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/BOINC_Installer_Errors", loginName); + err = callPosixSpawn(temp); snprintf(Catalogs_Dir, sizeof(Catalogs_Dir), "/tmp/%s/BOINC_payload/Library/Application Support/BOINC Data/locale/", @@ -140,10 +149,6 @@ int main(int argc, char *argv[]) err = callPosixSpawn(temp); REPORT_ERROR(err); - snprintf(temp, sizeof(temp), "/tmp/%s", loginName); - mkdir(temp, 0777); - chmod(temp, 0777); // Needed because mkdir sets permissions restricted by umask (022) - sprintf(temp, "cp -fpR \"%s\" /tmp/%s/PostInstall.app", postInstallAppPath, loginName); err = callPosixSpawn(temp); REPORT_ERROR(err); @@ -433,7 +438,9 @@ static void GetPreferredLanguages() { } if (f && language) { fprintf(f, "%s\n", language); +#if CREATE_LOG print_to_log_file("Adding language: %s\n", language); +#endif } // Remove all copies of this language from our list of supported languages // so we can get the next preferred language in order of priority @@ -469,7 +476,9 @@ cleanup: CFArrayRemoveAllValues(supportedLanguages); CFRelease(supportedLanguages); supportedLanguages = NULL; +#if CREATE_LOG print_to_log_file("Exiting GetPreferredLanguages"); +#endif } @@ -547,11 +556,6 @@ static void ShowMessage(const char *format, ...) { } -static void ShowError(int lineNum) { - ShowMessage((char *)_("BOINC Installer error at line %d"), lineNum); -} - - static OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon ) { gQuitFlag = true; @@ -690,13 +694,14 @@ int callPosixSpawn(const char *cmdline) { // For debugging void print_to_log_file(const char *format, ...) { -#if CREATE_LOG FILE *f; va_list args; - char buf[256]; + char buf[MAXPATHLEN]; time_t t; - strlcpy(buf, getenv("HOME"), sizeof(buf)); - strlcat(buf, "/Documents/test_log.txt", sizeof(buf)); +// strlcpy(buf, getenv("HOME"), sizeof(buf)); +// strlcat(buf, "/Documents/test_log.txt", sizeof(buf)); + + snprintf(buf, sizeof(buf), "/tmp/%s/BOINC_Installer_Errors", loginName); f = fopen(buf, "a"); if (!f) return; @@ -717,10 +722,8 @@ void print_to_log_file(const char *format, ...) { fputs("\n", f); fflush(f); fclose(f); -#endif } -#if CREATE_LOG void strip_cr(char *buf) { char *theCR; @@ -732,4 +735,3 @@ void strip_cr(char *buf) if (theCR) *theCR = '\0'; } -#endif // CREATE_LOG diff --git a/mac_installer/PostInstall.cpp b/mac_installer/PostInstall.cpp index 5fa722c9a2..a418aad4b8 100644 --- a/mac_installer/PostInstall.cpp +++ b/mac_installer/PostInstall.cpp @@ -112,8 +112,7 @@ Boolean CheckDeleteFile(char *name); void SetEUIDBackToUser (void); static char * PersistentFGets(char *buf, size_t buflen, FILE *f); static void LoadPreferredLanguages(); -static Boolean ShowMessage(Boolean allowCancel, const char *format, ...); -static void ShowError(int lineNum); +static Boolean ShowMessage(Boolean askYesNo, const char *format, ...); Boolean IsUserMemberOfGroup(const char *userName, const char *groupName); int CountGroupMembershipEntries(const char *userName, const char *groupName); OSErr UpdateAllVisibleUsers(long brandID); @@ -124,8 +123,9 @@ static double dtime(void); static void SleepSeconds(double seconds); static OSErr QuitAppleEventHandler(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon); int callPosixSpawn(const char *cmd); -void print_to_log_file(const char *format, ...); +void print_to_log(const char *format, ...); void strip_cr(char *buf); +void CopyPreviousErrorsToLog(void); extern int check_security( char *bundlePath, char *dataPath, @@ -148,7 +148,7 @@ void notused() { static char * Catalog_Name = (char *)"BOINC-Setup"; static char * Catalogs_Dir = (char *)"/Library/Application Support/BOINC Data/locale/"; -#define REPORT_ERROR(isError) if (isError) ShowError(__LINE__) +#define REPORT_ERROR(isError) if (isError) print_to_log("BOINC PostInstall error at line %d", __LINE__); /* globals */ static Boolean gCommandLineInstall = false; @@ -221,13 +221,20 @@ int main(int argc, char *argv[]) receiptName[3] = "/Library/Receipts/Charity Engine Installer.pkg"; skinName[3] = "Charity Engine"; - puts("Starting PostInstall app\n"); + printf("\nStarting PostInstall app %s\n\n", argv[1]); fflush(stdout); // getlogin() gives unreliable results under OS 10.6.2, so use environment strncpy(loginName, getenv("USER"), sizeof(loginName)-1); + if (loginName[0] == '\0') { + ShowMessage(false, (char *)_("Could not get user login name")); + return 0; + } + printf("login name = %s\n", loginName); fflush(stdout); + CopyPreviousErrorsToLog(); + if (getenv("COMMAND_LINE_INSTALL") != NULL) { gCommandLineInstall = true; puts("command-line install\n"); @@ -348,7 +355,7 @@ int main(int argc, char *argv[]) REPORT_ERROR(i >= RETRY_LIMIT); continue; } - + // err = SetBOINCAppOwnersGroupsAndPermissions("/Applications/GridRepublic Desktop.app"); err = SetBOINCAppOwnersGroupsAndPermissions(appPath[brandID]); @@ -881,9 +888,9 @@ Boolean SetLoginItemOSAScript(long brandID, Boolean deleteLogInItem, char *userN #if CREATE_LOG if (err == noErr) { - print_to_log_file("SystemEvents is at %s\n", systemEventsPath); + print_to_log("SystemEvents is at %s\n", systemEventsPath); } else { - print_to_log_file("GetPathToAppFromID(kSystemEventsCreator, kSystemEventsBundleID) returned error %d ", (int) err); + print_to_log("GetPathToAppFromID(kSystemEventsCreator, kSystemEventsBundleID) returned error %d ", (int) err); } #endif @@ -1160,7 +1167,7 @@ static void LoadPreferredLanguages(){ } -static Boolean ShowMessage(Boolean allowCancel, const char *format, ...) { +static Boolean ShowMessage(Boolean askYesNo, const char *format, ...) { // CAUTION: vsprintf will produce undesirable results if the string // contains a % character that is not a format specification! // But CFString is OK! @@ -1203,7 +1210,7 @@ static Boolean ShowMessage(Boolean allowCancel, const char *format, ...) { BringAppToFront(); SInt32 retval = CFUserNotificationDisplayAlert(0.0, kCFUserNotificationPlainAlertLevel, myIconURLRef, NULL, NULL, CFSTR(" "), myString, - yes, allowCancel ? no : NULL, NULL, + askYesNo ? yes : NULL, askYesNo ? no : NULL, NULL, &responseFlags); @@ -1217,31 +1224,6 @@ static Boolean ShowMessage(Boolean allowCancel, const char *format, ...) { } -static void ShowError(int lineNum) { - char s[1024]; - CFOptionFlags responseFlags; - CFURLRef myIconURLRef = NULL; - CFBundleRef myBundleRef; - - myBundleRef = CFBundleGetMainBundle(); - if (myBundleRef) { - myIconURLRef = CFBundleCopyResourceURL(myBundleRef, CFSTR("MacInstaller.icns"), NULL, NULL); - } - - sprintf(s, (char *)_("BOINC PostInstall error at line %d"), lineNum); - CFStringRef myString = CFStringCreateWithCString(NULL, s, kCFStringEncodingUTF8); - - BringAppToFront(); - CFUserNotificationDisplayAlert(0.0, kCFUserNotificationPlainAlertLevel, - myIconURLRef, NULL, NULL, CFSTR(" "), myString, - NULL, NULL, NULL, - &responseFlags); - - if (myIconURLRef) CFRelease(myIconURLRef); - if (myString) CFRelease(myString); -} - - Boolean IsUserMemberOfGroup(const char *userName, const char *groupName) { group *grp; short i = 0; @@ -2009,19 +1991,19 @@ int callPosixSpawn(const char *cmdline) { } #if VERBOSE_TEST - print_to_log_file("***********"); + print_to_log("***********"); for (int i=0; i> /tmp/BOINCInstallLog.txt +"$pipath" -part1 > /tmp/BOINCInstallLog.txt 2>&1 sleep 2 -"$pipath" -part2 >> /tmp/BOINCInstallLog.txt & +"$pipath" -part2 >> /tmp/BOINCInstallLog.txt 2>&1 & else -"$pipath" -part1 +"$pipath" -part1 2>&1 | tee /tmp/BOINCInstallLog.txt sleep 2 # part2 continues to run after Installer finishes, # and fails unless we redirect stdout to a file -"$pipath" -part2 >> /tmp/BOINCInstallLog.txt & +"$pipath" -part2 >> /tmp/BOINCInstallLog.txt 2>&1 & fi exit 0 diff --git a/mac_installer/postupgrade b/mac_installer/postupgrade index 0d0480da42..1d1b0988d3 100755 --- a/mac_installer/postupgrade +++ b/mac_installer/postupgrade @@ -22,15 +22,15 @@ echo "PostInstall.app path = $pipath" # Run the Postinstall Application if [ "${COMMAND_LINE_INSTALL}" = "1" ]; then -"$pipath" -part1 >> /tmp/BOINCInstallLog.txt +"$pipath" -part1 > /tmp/BOINCInstallLog.txt 2>&1 sleep 2 -"$pipath" -part2 >> /tmp/BOINCInstallLog.txt & +"$pipath" -part2 >> /tmp/BOINCInstallLog.txt 2>&1 & else -"$pipath" -part1 +"$pipath" -part1 2>&1 | tee /tmp/BOINCInstallLog.txt sleep 2 # part2 continues to run after Installer finishes, # and fails unless we redirect stdout to a file -"$pipath" -part2 >> /tmp/BOINCInstallLog.txt & +"$pipath" -part2 >> /tmp/BOINCInstallLog.txt 2>&1 & fi exit 0