2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2006-06-27 12:56:11 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2022-04-06 08:26:49 +00:00
|
|
|
// Copyright (C) 2022 University of California
|
2006-06-27 12:56:11 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2006-06-27 12:56:11 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2006-06-27 12:56:11 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
/* Installer.cpp */
|
|
|
|
|
2017-07-12 12:06:12 +00:00
|
|
|
#define CREATE_LOG 0 /* for general debugging */
|
|
|
|
#define VERBOSE_TEST 0 /* for debugging callPosixSpawn */
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#include <grp.h>
|
|
|
|
|
|
|
|
#include <sys/types.h> // getpwname, getpwuid, getuid
|
|
|
|
#include <pwd.h> // getpwname, getpwuid, getuid
|
|
|
|
#include <sys/wait.h> // waitpid
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/param.h> // for MAXPATHLEN
|
2012-01-06 10:44:53 +00:00
|
|
|
#include <sys/stat.h>
|
2006-06-27 12:56:11 +00:00
|
|
|
|
2013-06-04 07:55:57 +00:00
|
|
|
#include "str_util.h"
|
2013-06-07 04:27:05 +00:00
|
|
|
#include "str_replace.h"
|
2017-01-06 09:53:47 +00:00
|
|
|
#include "mac_util.h"
|
2013-07-02 09:08:21 +00:00
|
|
|
#include "translate.h"
|
2017-11-11 11:35:48 +00:00
|
|
|
#include "file_names.h"
|
2018-07-11 10:59:34 +00:00
|
|
|
#include "mac_branding.h"
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
#define boinc_master_user_name "boinc_master"
|
|
|
|
#define boinc_master_group_name "boinc_master"
|
|
|
|
#define boinc_project_user_name "boinc_project"
|
|
|
|
#define boinc_project_group_name "boinc_project"
|
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
|
|
|
|
OSErr Initialize(void); /* function prototypes */
|
2011-12-02 13:11:21 +00:00
|
|
|
Boolean IsUserMemberOfGroup(const char *userName, const char *groupName);
|
2013-06-11 12:22:12 +00:00
|
|
|
Boolean IsRestartNeeded();
|
2013-10-30 12:19:29 +00:00
|
|
|
static void GetPreferredLanguages();
|
2013-07-02 09:08:21 +00:00
|
|
|
static void LoadPreferredLanguages();
|
2018-06-24 11:01:49 +00:00
|
|
|
static long GetOldBrandID(void);
|
2021-06-25 00:46:51 +00:00
|
|
|
static void ShowMessage(const char *format, ...);
|
2006-06-27 12:56:11 +00:00
|
|
|
static OSErr QuitAppleEventHandler(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon);
|
2017-01-06 09:53:47 +00:00
|
|
|
int callPosixSpawn(const char *cmd);
|
2006-06-27 12:56:11 +00:00
|
|
|
void print_to_log_file(const char *format, ...);
|
|
|
|
void strip_cr(char *buf);
|
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
// We can't use translation because the translation catalogs
|
|
|
|
// have not yet been installed when this application is run.
|
|
|
|
#define MAX_LANGUAGES_TO_TRY 5
|
|
|
|
|
2017-07-12 12:06:12 +00:00
|
|
|
#define REPORT_ERROR(isError) if (isError) print_to_log_file("BOINC Installer error at line %d", __LINE__);
|
2017-06-05 08:58:46 +00:00
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
static char * Catalog_Name = (char *)"BOINC-Setup";
|
2017-07-11 14:29:56 +00:00
|
|
|
static char Catalogs_Dir[MAXPATHLEN];
|
|
|
|
static char loginName[256];
|
2017-07-15 12:11:32 +00:00
|
|
|
static char tempDirName[MAXPATHLEN];
|
2013-06-04 00:57:09 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
Boolean gQuitFlag = false; /* global */
|
|
|
|
|
2013-06-11 12:22:12 +00:00
|
|
|
#if 0
|
2011-12-02 13:11:21 +00:00
|
|
|
CFStringRef valueRestartRequired = CFSTR("RequiredRestart");
|
|
|
|
CFStringRef valueLogoutRequired = CFSTR("RequiredLogout");
|
|
|
|
CFStringRef valueNoRestart = CFSTR("NoRestart");
|
2013-06-11 12:22:12 +00:00
|
|
|
#endif
|
2011-12-02 13:11:21 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2013-11-01 09:47:34 +00:00
|
|
|
char pkgPath[MAXPATHLEN];
|
2015-08-13 11:21:19 +00:00
|
|
|
char postInstallAppPath[MAXPATHLEN];
|
2017-11-12 11:37:52 +00:00
|
|
|
char temp[MAXPATHLEN], temp2[MAXPATHLEN];
|
2007-10-26 10:01:28 +00:00
|
|
|
char brand[64], s[256];
|
2006-06-27 12:56:11 +00:00
|
|
|
char *p;
|
|
|
|
OSStatus err = noErr;
|
2013-06-11 12:22:12 +00:00
|
|
|
Boolean restartNeeded = true;
|
|
|
|
FILE *restartNeededFile;
|
2018-06-24 11:01:49 +00:00
|
|
|
FILE *f;
|
|
|
|
long oldBrandID;
|
2020-12-01 10:53:07 +00:00
|
|
|
int major = 0;
|
|
|
|
int minor = 0;
|
2017-06-05 08:58:46 +00:00
|
|
|
|
2018-07-11 10:59:34 +00:00
|
|
|
if (!check_branding_arrays(temp, sizeof(temp))) {
|
2021-06-25 00:46:51 +00:00
|
|
|
ShowMessage((char *)_("Branding array has too few entries: %s"), temp);
|
2018-07-11 10:59:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
if (Initialize() != noErr) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-11 14:29:56 +00:00
|
|
|
|
|
|
|
strncpy(loginName, getenv("USER"), sizeof(loginName)-1);
|
2017-07-12 12:06:12 +00:00
|
|
|
if (loginName[0] == '\0') {
|
2021-06-25 00:46:51 +00:00
|
|
|
ShowMessage((char *)_("Could not get user login name"));
|
2017-07-12 12:06:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-15 12:11:32 +00:00
|
|
|
|
|
|
|
snprintf(tempDirName, sizeof(tempDirName), "InstallBOINC-%s", loginName);
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "/tmp/%s", tempDirName);
|
2017-07-12 12:06:12 +00:00
|
|
|
mkdir(temp, 0777);
|
|
|
|
chmod(temp, 0777); // Needed because mkdir sets permissions restricted by umask (022)
|
|
|
|
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/BOINC_Installer_Errors", tempDirName);
|
2017-07-12 12:06:12 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2017-07-11 14:29:56 +00:00
|
|
|
snprintf(Catalogs_Dir, sizeof(Catalogs_Dir),
|
|
|
|
"/tmp/%s/BOINC_payload/Library/Application Support/BOINC Data/locale/",
|
2017-07-15 12:11:32 +00:00
|
|
|
tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
// Get the full path to Installer package inside this application's bundle
|
2017-01-06 09:53:47 +00:00
|
|
|
getPathToThisApp(pkgPath, sizeof(pkgPath));
|
2013-10-30 12:19:29 +00:00
|
|
|
strlcpy(temp, pkgPath, sizeof(temp));
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
strlcat(pkgPath, "/Contents/Resources/", sizeof(pkgPath));
|
|
|
|
|
2015-08-13 11:21:19 +00:00
|
|
|
strlcpy(postInstallAppPath, pkgPath, sizeof(postInstallAppPath));
|
|
|
|
strlcat(postInstallAppPath, "PostInstall.app", sizeof(postInstallAppPath));
|
|
|
|
|
2013-10-30 12:19:29 +00:00
|
|
|
p = strrchr(temp, '/'); // Point to name of this application (e.g., "BOINC Installer.app")
|
2017-11-12 11:37:52 +00:00
|
|
|
if (p == NULL) {
|
2013-10-30 12:19:29 +00:00
|
|
|
p = temp - 1;
|
2017-11-12 11:37:52 +00:00
|
|
|
} else {
|
|
|
|
*p = '\0';
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2017-11-12 11:37:52 +00:00
|
|
|
// Delete any old project auto-attach key file from our temp directory
|
2017-11-15 02:33:20 +00:00
|
|
|
snprintf(temp2, sizeof(temp2), "rm -dfR \"/tmp/%s/%s\"", tempDirName, ACCOUNT_DATA_FILENAME);
|
2017-11-12 11:37:52 +00:00
|
|
|
err = callPosixSpawn(temp2);
|
|
|
|
REPORT_ERROR(err);
|
|
|
|
|
|
|
|
// Write a file containing the project auto-attach key into our temp
|
|
|
|
// directory because the BOINC Data directory may not yet exist.
|
2021-06-23 06:56:57 +00:00
|
|
|
// PostInstall.app will copy it into the BOINC Data directory later
|
2017-11-15 03:16:33 +00:00
|
|
|
snprintf(temp2, sizeof(temp2), "%s/%s", temp, ACCOUNT_DATA_FILENAME);
|
2017-11-12 11:37:52 +00:00
|
|
|
if (boinc_file_exists(temp2)) {
|
2017-11-15 02:44:35 +00:00
|
|
|
// If the project server put account_data.txt file in the same
|
2017-11-12 11:37:52 +00:00
|
|
|
// parent directory as this installer, copy it into our temp directory
|
2017-11-15 02:33:20 +00:00
|
|
|
snprintf(temp2, sizeof(temp2), "cp \"%s/%s\" \"/tmp/%s/%s\"", temp, ACCOUNT_DATA_FILENAME, tempDirName, ACCOUNT_DATA_FILENAME);
|
2017-11-12 11:37:52 +00:00
|
|
|
err = callPosixSpawn(temp2);
|
|
|
|
REPORT_ERROR(err);
|
|
|
|
} else {
|
2023-05-05 18:05:20 +00:00
|
|
|
// Create an account_data.txt file containing our
|
2017-11-12 11:37:52 +00:00
|
|
|
// installer's filename and put it in our temp directory
|
2017-11-15 02:33:20 +00:00
|
|
|
snprintf(temp2, sizeof(temp2), "/tmp/%s/%s", tempDirName, ACCOUNT_DATA_FILENAME);
|
2018-06-24 11:01:49 +00:00
|
|
|
f = fopen(temp2, "w");
|
2017-11-12 11:37:52 +00:00
|
|
|
fputs(p+1, f);
|
|
|
|
fclose(f);
|
|
|
|
}
|
2018-06-24 11:01:49 +00:00
|
|
|
|
|
|
|
// Write a temp file to tell our PostInstall.app the previous branding, if any
|
|
|
|
oldBrandID = GetOldBrandID();
|
|
|
|
snprintf(temp, sizeof(temp), "/tmp/%s/OldBranding", tempDirName);
|
|
|
|
f = fopen(temp, "w");
|
|
|
|
if (!f) {
|
|
|
|
REPORT_ERROR(true);
|
|
|
|
} else {
|
|
|
|
fprintf(f, "BrandId=%ld\n", oldBrandID);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
2017-11-11 11:35:48 +00:00
|
|
|
// To allow for branding, assume name of installer package inside bundle corresponds to name of this application
|
2007-10-26 10:01:28 +00:00
|
|
|
strlcpy(brand, p+1, sizeof(brand));
|
2006-06-27 12:56:11 +00:00
|
|
|
strlcat(pkgPath, p+1, sizeof(pkgPath));
|
2007-10-26 10:01:28 +00:00
|
|
|
p = strrchr(pkgPath, ' '); // Strip off last space character and everything following
|
2006-06-27 12:56:11 +00:00
|
|
|
if (p)
|
2023-05-05 18:05:20 +00:00
|
|
|
*p = '\0';
|
2006-06-27 12:56:11 +00:00
|
|
|
|
2017-11-16 14:06:26 +00:00
|
|
|
p = strrchr(brand, ' '); // Strip off last space character and everything following
|
2011-12-02 16:59:37 +00:00
|
|
|
if (p)
|
2023-05-05 18:05:20 +00:00
|
|
|
*p = '\0';
|
|
|
|
|
2012-01-06 10:44:53 +00:00
|
|
|
strlcat(pkgPath, ".pkg", sizeof(pkgPath));
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2017-07-11 14:29:56 +00:00
|
|
|
// In the unlikely situation that /tmp has files from an earlier attempt to install
|
|
|
|
// BOINC by a different user, we won't have permission to delete or overwrite them,
|
|
|
|
// so include the current user's name as part of the paths to our temporary files.
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-10-30 12:19:29 +00:00
|
|
|
// Expand the installer package
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/BOINC.pkg", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/expanded_BOINC.pkg", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/PostInstall.app", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -f /tmp/%s/BOINC_preferred_languages", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -f /tmp/%s/BOINC_restart_flag", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2017-07-15 12:11:32 +00:00
|
|
|
sprintf(temp, "cp -fpR \"%s\" /tmp/%s/PostInstall.app", postInstallAppPath, tempDirName);
|
2017-03-01 12:45:38 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2017-07-15 12:11:32 +00:00
|
|
|
sprintf(temp, "pkgutil --expand \"%s\" /tmp/%s/expanded_BOINC.pkg", pkgPath, tempDirName);
|
2017-03-01 12:45:38 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2013-10-30 12:19:29 +00:00
|
|
|
if (err == noErr) {
|
|
|
|
GetPreferredLanguages();
|
|
|
|
}
|
2020-12-01 10:53:07 +00:00
|
|
|
|
|
|
|
sscanf(Deployment_target, "%i.%i", &major, &minor);
|
|
|
|
if (compareOSVersionTo(major, minor) < 0) {
|
2013-07-02 09:08:21 +00:00
|
|
|
LoadPreferredLanguages();
|
2017-01-06 09:53:47 +00:00
|
|
|
BringAppToFront();
|
2007-10-26 10:01:28 +00:00
|
|
|
p = strrchr(brand, ' '); // Strip off last space character and everything following
|
|
|
|
if (p)
|
2023-05-05 18:05:20 +00:00
|
|
|
*p = '\0';
|
2021-06-25 00:46:51 +00:00
|
|
|
ShowMessage((char *)_("Sorry, this version of %s requires system %s or higher."), brand, Deployment_target);
|
2007-10-26 10:01:28 +00:00
|
|
|
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/BOINC_payload", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2013-10-30 12:19:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-10-26 10:01:28 +00:00
|
|
|
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/BOINC_payload", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2007-10-26 10:01:28 +00:00
|
|
|
|
2013-10-30 12:19:29 +00:00
|
|
|
// 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);
|
2017-06-05 08:58:46 +00:00
|
|
|
err = callPosixSpawn (s);
|
|
|
|
REPORT_ERROR(err);
|
2013-10-30 12:19:29 +00:00
|
|
|
|
|
|
|
restartNeeded = IsRestartNeeded();
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-10-30 12:19:29 +00:00
|
|
|
// Write a temp file to tell our PostInstall.app whether restart is needed
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "/tmp/%s/BOINC_restart_flag", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
restartNeededFile = fopen(temp, "w");
|
2013-10-30 12:19:29 +00:00
|
|
|
if (restartNeededFile) {
|
|
|
|
fputs(restartNeeded ? "1\n" : "0\n", restartNeededFile);
|
|
|
|
fclose(restartNeededFile);
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-10-30 12:19:29 +00:00
|
|
|
if (restartNeeded) {
|
|
|
|
if (err == noErr) {
|
|
|
|
// Change onConclusion="none" to onConclusion="RequireRestart"
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "sed -i \".bak\" s/onConclusion=\"none\"/onConclusion=\"RequireRestart\"/g /tmp/%s/expanded_BOINC.pkg/Distribution", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2013-07-02 10:53:02 +00:00
|
|
|
}
|
|
|
|
if (err == noErr) {
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/expanded_BOINC.pkg/Distribution.bak", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2013-10-30 12:19:29 +00:00
|
|
|
// Flatten the installer package
|
2017-07-15 12:11:32 +00:00
|
|
|
sprintf(temp, "pkgutil --flatten /tmp/%s/expanded_BOINC.pkg /tmp/%s/%s.pkg", tempDirName, tempDirName, brand);
|
2017-03-01 12:45:38 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2013-10-30 12:19:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (err == noErr) {
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/expanded_BOINC.pkg", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2017-07-15 12:11:32 +00:00
|
|
|
sprintf(temp, "open \"/tmp/%s/%s.pkg\"", tempDirName, brand);
|
2017-06-05 08:58:46 +00:00
|
|
|
err = callPosixSpawn(temp);
|
|
|
|
REPORT_ERROR(err);
|
|
|
|
return err;
|
2012-01-06 10:44:53 +00:00
|
|
|
}
|
2006-06-27 12:56:11 +00:00
|
|
|
}
|
2013-07-02 10:53:02 +00:00
|
|
|
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/expanded_BOINC.pkg", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
err = callPosixSpawn(temp);
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(err);
|
2014-09-29 12:14:15 +00:00
|
|
|
|
2017-06-04 13:05:58 +00:00
|
|
|
sprintf(temp, "open \"%s\"", pkgPath);
|
2017-06-05 08:58:46 +00:00
|
|
|
err = callPosixSpawn(temp);
|
|
|
|
REPORT_ERROR(err);
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-02 13:11:21 +00:00
|
|
|
Boolean IsUserMemberOfGroup(const char *userName, const char *groupName) {
|
|
|
|
group *grp;
|
|
|
|
short i = 0;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
grp = getgrnam(groupName);
|
|
|
|
if (!grp) {
|
|
|
|
printf("getgrnam(%s) failed\n", groupName);
|
|
|
|
fflush(stdout);
|
|
|
|
return false; // Group not found
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((p = grp->gr_mem[i]) != NULL) { // Step through all users in group admin
|
|
|
|
if (strcmp(p, userName) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-11 12:22:12 +00:00
|
|
|
Boolean IsRestartNeeded()
|
2006-06-27 12:56:11 +00:00
|
|
|
{
|
|
|
|
passwd *pw = NULL;
|
|
|
|
group *grp = NULL;
|
|
|
|
gid_t boinc_master_gid = 0, boinc_project_gid = 0;
|
|
|
|
uid_t boinc_master_uid = 0, boinc_project_uid = 0;
|
2017-06-04 13:05:58 +00:00
|
|
|
|
2014-08-21 12:48:17 +00:00
|
|
|
if (compareOSVersionTo(10, 9) >= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
grp = getgrnam(boinc_master_group_name);
|
|
|
|
if (grp == NULL)
|
2013-06-11 12:22:12 +00:00
|
|
|
return true; // Group boinc_master does not exist
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
boinc_master_gid = grp->gr_gid;
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
grp = getgrnam(boinc_project_group_name);
|
|
|
|
if (grp == NULL)
|
2013-06-11 12:22:12 +00:00
|
|
|
return true; // Group boinc_project does not exist
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
boinc_project_gid = grp->gr_gid;
|
|
|
|
|
|
|
|
pw = getpwnam(boinc_master_user_name);
|
|
|
|
if (pw == NULL)
|
2013-06-11 12:22:12 +00:00
|
|
|
return true; // User boinc_master does not exist
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
boinc_master_uid = pw->pw_uid;
|
2011-12-02 13:11:21 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
if (pw->pw_gid != boinc_master_gid)
|
2013-06-11 12:22:12 +00:00
|
|
|
return true; // User boinc_master does not have group boinc_master as its primary group
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
pw = getpwnam(boinc_project_user_name);
|
|
|
|
if (pw == NULL)
|
2013-06-11 12:22:12 +00:00
|
|
|
return true; // User boinc_project does not exist
|
2011-12-02 15:54:46 +00:00
|
|
|
|
|
|
|
boinc_project_uid = pw->pw_uid;
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
if (pw->pw_gid != boinc_project_gid)
|
2013-06-11 12:22:12 +00:00
|
|
|
return true; // User boinc_project does not have group boinc_project as its primary group
|
2011-12-02 13:26:17 +00:00
|
|
|
|
2013-11-15 13:02:04 +00:00
|
|
|
if (compareOSVersionTo(10, 5) >= 0) {
|
2011-12-02 13:26:17 +00:00
|
|
|
if (boinc_master_gid < 501)
|
2013-06-11 12:22:12 +00:00
|
|
|
return true; // We will change boinc_master_gid to a value > 501
|
2011-12-02 13:26:17 +00:00
|
|
|
if (boinc_project_gid < 501)
|
2013-06-11 12:22:12 +00:00
|
|
|
return true; // We will change boinc_project_gid to a value > 501
|
2011-12-02 13:26:17 +00:00
|
|
|
if (boinc_master_uid < 501)
|
2013-06-11 12:22:12 +00:00
|
|
|
return true; // We will change boinc_master_uid to a value > 501
|
2011-12-02 13:26:17 +00:00
|
|
|
if (boinc_project_uid < 501)
|
2013-06-11 12:22:12 +00:00
|
|
|
return true; // We will change boinc_project_uid to a value > 501
|
2011-12-02 13:26:17 +00:00
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2011-12-02 13:11:21 +00:00
|
|
|
#ifdef SANDBOX
|
|
|
|
if (loginName[0]) {
|
|
|
|
if (IsUserMemberOfGroup(loginName, boinc_master_group_name)) {
|
2013-06-11 12:22:12 +00:00
|
|
|
return false; // Logged in user is already a member of group boinc_master
|
2011-12-02 13:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // SANDBOX
|
2006-06-27 12:56:11 +00:00
|
|
|
|
2013-06-11 12:22:12 +00:00
|
|
|
return true;
|
2006-06-27 12:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
OSErr Initialize() /* Initialize some managers */
|
2006-06-27 12:56:11 +00:00
|
|
|
{
|
2011-10-18 12:42:53 +00:00
|
|
|
// InitCursor();
|
2006-06-27 12:56:11 +00:00
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
return AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr)QuitAppleEventHandler), 0, false );
|
2006-06-27 12:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
// Because language preferences are set on a per-user basis, we
|
2023-05-05 18:05:20 +00:00
|
|
|
// must get the preferred languages while set to the current
|
2013-06-14 11:50:06 +00:00
|
|
|
// user, before the Apple Installer switches us to root.
|
|
|
|
// So we get the preferred languages here and write them to a
|
|
|
|
// temporary file to be retrieved by our PostInstall app.
|
2013-10-30 12:19:29 +00:00
|
|
|
static void GetPreferredLanguages() {
|
2013-06-14 11:50:06 +00:00
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
2017-07-11 14:29:56 +00:00
|
|
|
char temp[MAXPATHLEN];
|
2013-06-14 11:50:06 +00:00
|
|
|
char searchPath[MAXPATHLEN];
|
2021-06-25 00:46:51 +00:00
|
|
|
char savedWD[MAXPATHLEN];
|
2013-06-14 11:50:06 +00:00
|
|
|
struct stat sbuf;
|
|
|
|
CFMutableArrayRef supportedLanguages;
|
|
|
|
CFStringRef aLanguage;
|
2013-08-15 11:24:20 +00:00
|
|
|
char shortLanguage[32];
|
2013-06-14 11:50:06 +00:00
|
|
|
CFArrayRef preferredLanguages;
|
|
|
|
int i, j, k;
|
|
|
|
char * language;
|
2013-08-15 11:24:20 +00:00
|
|
|
char *uscore;
|
2013-06-14 11:50:06 +00:00
|
|
|
FILE *f;
|
2013-10-30 12:19:29 +00:00
|
|
|
|
2021-06-25 00:46:51 +00:00
|
|
|
getcwd(savedWD, sizeof(savedWD));
|
|
|
|
snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/BOINC_payload", tempDirName);
|
|
|
|
callPosixSpawn(temp);
|
|
|
|
snprintf(temp, sizeof(temp), "/tmp/%s/BOINC_payload", tempDirName);
|
|
|
|
mkdir(temp, 0777);
|
|
|
|
chmod(temp, 0777); // Needed because mkdir sets permissions restricted by umask (022)
|
|
|
|
chdir(temp);
|
|
|
|
// Extract the installer package payload to a temporary location
|
|
|
|
snprintf(temp, sizeof(temp), "cpio -i -I /tmp/%s/expanded_BOINC.pkg/BOINC.pkg/Payload", tempDirName);
|
|
|
|
callPosixSpawn(temp);
|
|
|
|
chdir(savedWD);
|
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
// Create an array of all our supported languages
|
2013-10-17 11:22:05 +00:00
|
|
|
supportedLanguages = CFArrayCreateMutable(kCFAllocatorDefault, 100, &kCFTypeArrayCallBacks);
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
aLanguage = CFStringCreateWithCString(NULL, "en", kCFStringEncodingMacRoman);
|
|
|
|
CFArrayAppendValue(supportedLanguages, aLanguage);
|
2013-06-18 12:45:16 +00:00
|
|
|
CFRelease(aLanguage);
|
2013-06-14 11:50:06 +00:00
|
|
|
aLanguage = NULL;
|
|
|
|
|
|
|
|
dirp = opendir(Catalogs_Dir);
|
2017-06-05 08:58:46 +00:00
|
|
|
if (!dirp) {
|
|
|
|
REPORT_ERROR(true);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-06-14 11:50:06 +00:00
|
|
|
while (true) {
|
|
|
|
dp = readdir(dirp);
|
|
|
|
if (dp == NULL)
|
|
|
|
break; // End of list
|
|
|
|
|
|
|
|
if (dp->d_name[0] == '.')
|
|
|
|
continue; // Ignore names beginning with '.'
|
|
|
|
|
|
|
|
strlcpy(searchPath, Catalogs_Dir, sizeof(searchPath));
|
|
|
|
strlcat(searchPath, dp->d_name, sizeof(searchPath));
|
|
|
|
strlcat(searchPath, "/", sizeof(searchPath));
|
|
|
|
strlcat(searchPath, Catalog_Name, sizeof(searchPath));
|
|
|
|
strlcat(searchPath, ".mo", sizeof(searchPath));
|
|
|
|
if (stat(searchPath, &sbuf) != 0) continue;
|
|
|
|
// printf("Adding %s to supportedLanguages array\n", dp->d_name);
|
|
|
|
aLanguage = CFStringCreateWithCString(NULL, dp->d_name, kCFStringEncodingMacRoman);
|
|
|
|
CFArrayAppendValue(supportedLanguages, aLanguage);
|
2013-06-18 12:45:16 +00:00
|
|
|
CFRelease(aLanguage);
|
2013-06-14 11:50:06 +00:00
|
|
|
aLanguage = NULL;
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-08-15 11:24:20 +00:00
|
|
|
// If it has a region code ("it_IT") also try without region code ("it")
|
|
|
|
// TODO: Find a more general solution
|
|
|
|
strlcpy(shortLanguage, dp->d_name, sizeof(shortLanguage));
|
|
|
|
uscore = strchr(shortLanguage, '_');
|
|
|
|
if (uscore) {
|
|
|
|
*uscore = '\0';
|
|
|
|
aLanguage = CFStringCreateWithCString(NULL, shortLanguage, kCFStringEncodingMacRoman);
|
|
|
|
CFArrayAppendValue(supportedLanguages, aLanguage);
|
2013-10-17 11:22:05 +00:00
|
|
|
CFRelease(aLanguage);
|
2013-08-15 11:24:20 +00:00
|
|
|
aLanguage = NULL;
|
|
|
|
}
|
2013-06-14 11:50:06 +00:00
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
closedir(dirp);
|
|
|
|
|
|
|
|
// Write a temp file to tell our PostInstall.app our preferred languages
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "/tmp/%s/BOINC_preferred_languages", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
f = fopen(temp, "w");
|
2017-06-05 08:58:46 +00:00
|
|
|
if (!f) {
|
|
|
|
REPORT_ERROR(true);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
for (i=0; i<MAX_LANGUAGES_TO_TRY; ++i) {
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
preferredLanguages = CFBundleCopyLocalizationsForPreferences(supportedLanguages, NULL );
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
#if 0 // For testing
|
|
|
|
int c = CFArrayGetCount(preferredLanguages);
|
|
|
|
for (k=0; k<c; ++k) {
|
|
|
|
CFStringRef s = (CFStringRef)CFArrayGetValueAtIndex(preferredLanguages, k);
|
|
|
|
printf("Preferred language %u is %s\n", k, CFStringGetCStringPtr(s, kCFStringEncodingMacRoman));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (j=0; j<CFArrayGetCount(preferredLanguages); ++j) {
|
|
|
|
aLanguage = (CFStringRef)CFArrayGetValueAtIndex(preferredLanguages, j);
|
|
|
|
language = (char *)CFStringGetCStringPtr(aLanguage, kCFStringEncodingMacRoman);
|
2015-08-14 11:05:19 +00:00
|
|
|
if (language == NULL) {
|
|
|
|
if (CFStringGetCString(aLanguage, shortLanguage, sizeof(shortLanguage), kCFStringEncodingMacRoman)) {
|
|
|
|
language = shortLanguage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (f && language) {
|
2013-06-14 11:50:06 +00:00
|
|
|
fprintf(f, "%s\n", language);
|
2017-07-12 12:06:12 +00:00
|
|
|
#if CREATE_LOG
|
2017-06-04 13:05:58 +00:00
|
|
|
print_to_log_file("Adding language: %s\n", language);
|
2017-07-12 12:06:12 +00:00
|
|
|
#endif
|
2013-06-14 11:50:06 +00:00
|
|
|
}
|
2017-06-04 13:05:58 +00:00
|
|
|
// Remove all copies of this language from our list of supported languages
|
2013-08-16 12:11:32 +00:00
|
|
|
// so we can get the next preferred language in order of priority
|
|
|
|
for (k=CFArrayGetCount(supportedLanguages)-1; k>=0; --k) {
|
2013-06-14 11:50:06 +00:00
|
|
|
if (CFStringCompare(aLanguage, (CFStringRef)CFArrayGetValueAtIndex(supportedLanguages, k), 0) == kCFCompareEqualTo) {
|
|
|
|
CFArrayRemoveValueAtIndex(supportedLanguages, k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 18:05:20 +00:00
|
|
|
// Since the original strings are English, no
|
2013-06-14 11:50:06 +00:00
|
|
|
// further translation is needed for language en.
|
2015-08-14 11:05:19 +00:00
|
|
|
if (language) {
|
|
|
|
if (!strcmp(language, "en")) {
|
|
|
|
fclose(f);
|
|
|
|
CFRelease(preferredLanguages);
|
|
|
|
preferredLanguages = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-06-14 11:50:06 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-06-18 12:45:16 +00:00
|
|
|
CFRelease(preferredLanguages);
|
|
|
|
preferredLanguages = NULL;
|
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
}
|
2013-06-18 12:45:16 +00:00
|
|
|
|
2015-08-14 11:05:19 +00:00
|
|
|
if (f) {
|
|
|
|
fprintf(f, "en\n");
|
|
|
|
fclose(f);
|
|
|
|
}
|
2013-06-18 12:45:16 +00:00
|
|
|
|
2013-07-02 09:08:21 +00:00
|
|
|
cleanup:
|
2013-06-18 12:45:16 +00:00
|
|
|
CFArrayRemoveAllValues(supportedLanguages);
|
|
|
|
CFRelease(supportedLanguages);
|
|
|
|
supportedLanguages = NULL;
|
2017-07-12 12:06:12 +00:00
|
|
|
#if CREATE_LOG
|
2017-06-04 13:05:58 +00:00
|
|
|
print_to_log_file("Exiting GetPreferredLanguages");
|
2017-07-12 12:06:12 +00:00
|
|
|
#endif
|
2013-07-02 09:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void LoadPreferredLanguages(){
|
|
|
|
FILE *f;
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
char language[32];
|
2017-07-11 14:29:56 +00:00
|
|
|
char temp[MAXPATHLEN];
|
2013-07-02 09:08:21 +00:00
|
|
|
|
|
|
|
BOINCTranslationInit();
|
|
|
|
|
2013-07-02 10:53:02 +00:00
|
|
|
// GetPreferredLanguages() wrote a list of our preferred languages to a temp file
|
2017-07-15 12:11:32 +00:00
|
|
|
snprintf(temp, sizeof(temp), "/tmp/%s/BOINC_preferred_languages", tempDirName);
|
2017-07-11 14:29:56 +00:00
|
|
|
f = fopen(temp, "r");
|
2017-06-05 08:58:46 +00:00
|
|
|
if (!f) {
|
|
|
|
REPORT_ERROR(true);
|
|
|
|
return;
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-07-02 09:08:21 +00:00
|
|
|
for (i=0; i<MAX_LANGUAGES_TO_TRY; ++i) {
|
|
|
|
fgets(language, sizeof(language), f);
|
|
|
|
if (feof(f)) break;
|
|
|
|
language[sizeof(language)-1] = '\0'; // Guarantee a null terminator
|
|
|
|
p = strchr(language, '\n');
|
2023-05-05 18:05:20 +00:00
|
|
|
if (p) *p = '\0'; // Replace newline with null terminator
|
2013-07-02 09:08:21 +00:00
|
|
|
if (language[0]) {
|
2013-08-16 12:11:32 +00:00
|
|
|
if (!BOINCTranslationAddCatalog(Catalogs_Dir, language, Catalog_Name)) {
|
2017-06-05 08:58:46 +00:00
|
|
|
REPORT_ERROR(true);
|
2013-07-02 09:08:21 +00:00
|
|
|
printf("could not load catalog for langage %s\n", language);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-24 11:01:49 +00:00
|
|
|
static long GetOldBrandID()
|
|
|
|
{
|
|
|
|
long oldBrandId;
|
|
|
|
|
|
|
|
oldBrandId = 0; // Default value
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2018-06-24 11:01:49 +00:00
|
|
|
FILE *f = fopen("/Library/Application Support/BOINC Data/Branding", "r");
|
|
|
|
if (f) {
|
|
|
|
fscanf(f, "BrandId=%ld\n", &oldBrandId);
|
|
|
|
fclose(f);
|
|
|
|
}
|
2018-07-11 10:59:34 +00:00
|
|
|
if ((oldBrandId < 0) || (oldBrandId > (NUMBRANDS-1))) {
|
|
|
|
oldBrandId = 0;
|
|
|
|
}
|
2018-06-24 11:01:49 +00:00
|
|
|
return oldBrandId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-25 00:46:51 +00:00
|
|
|
static void ShowMessage(const char *format, ...) {
|
2013-07-02 09:08:21 +00:00
|
|
|
// CAUTION: vsprintf will produce undesirable results if the string
|
|
|
|
// contains a % character that is not a format specification!
|
|
|
|
// But CFString is OK!
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
char s[1024];
|
|
|
|
CFOptionFlags responseFlags;
|
2017-06-05 08:58:46 +00:00
|
|
|
CFURLRef myIconURLRef = NULL;
|
|
|
|
CFBundleRef myBundleRef;
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2017-06-05 08:58:46 +00:00
|
|
|
myBundleRef = CFBundleGetMainBundle();
|
|
|
|
if (myBundleRef) {
|
|
|
|
myIconURLRef = CFBundleCopyResourceURL(myBundleRef, CFSTR("MacInstaller.icns"), NULL, NULL);
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-07-02 09:08:21 +00:00
|
|
|
#if 1
|
|
|
|
va_start(args, format);
|
|
|
|
vsprintf(s, format, args);
|
|
|
|
va_end(args);
|
|
|
|
#else
|
|
|
|
strcpy(s, format);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If defaultButton is nil or an empty string, a default localized
|
2014-01-29 09:43:31 +00:00
|
|
|
// button title ("OK" in English) is used.
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2013-07-02 09:08:21 +00:00
|
|
|
CFStringRef myString = CFStringCreateWithCString(NULL, s, kCFStringEncodingUTF8);
|
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
BringAppToFront();
|
2021-06-25 00:46:51 +00:00
|
|
|
CFUserNotificationDisplayAlert(0.0, kCFUserNotificationPlainAlertLevel,
|
2017-06-05 08:58:46 +00:00
|
|
|
myIconURLRef, NULL, NULL, CFSTR(" "), myString,
|
2021-06-25 00:46:51 +00:00
|
|
|
NULL, NULL, NULL,
|
2013-07-02 09:08:21 +00:00
|
|
|
&responseFlags);
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2017-06-05 08:58:46 +00:00
|
|
|
if (myIconURLRef) CFRelease(myIconURLRef);
|
2013-07-02 09:08:21 +00:00
|
|
|
if (myString) CFRelease(myString);
|
2013-06-14 11:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
static OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon )
|
|
|
|
{
|
|
|
|
gQuitFlag = true;
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define NOT_IN_TOKEN 0
|
|
|
|
#define IN_SINGLE_QUOTED_TOKEN 1
|
|
|
|
#define IN_DOUBLE_QUOTED_TOKEN 2
|
|
|
|
#define IN_UNQUOTED_TOKEN 3
|
|
|
|
|
2022-04-06 08:26:49 +00:00
|
|
|
static int parse_posix_spawn_command_line(char* p, char** argv) {
|
2017-01-06 09:53:47 +00:00
|
|
|
int state = NOT_IN_TOKEN;
|
|
|
|
int argc=0;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
switch(state) {
|
|
|
|
case NOT_IN_TOKEN:
|
|
|
|
if (isspace(*p)) {
|
|
|
|
} else if (*p == '\'') {
|
|
|
|
p++;
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_SINGLE_QUOTED_TOKEN;
|
|
|
|
break;
|
|
|
|
} else if (*p == '\"') {
|
|
|
|
p++;
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_DOUBLE_QUOTED_TOKEN;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_UNQUOTED_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_SINGLE_QUOTED_TOKEN:
|
|
|
|
if (*p == '\'') {
|
|
|
|
if (*(p-1) == '\\') break;
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_DOUBLE_QUOTED_TOKEN:
|
|
|
|
if (*p == '\"') {
|
|
|
|
if (*(p-1) == '\\') break;
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_UNQUOTED_TOKEN:
|
|
|
|
if (isspace(*p)) {
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
2013-11-15 13:02:04 +00:00
|
|
|
}
|
2017-01-06 09:53:47 +00:00
|
|
|
argv[argc] = 0;
|
|
|
|
return argc;
|
2013-11-15 13:02:04 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
#include <spawn.h>
|
2013-11-15 13:02:04 +00:00
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
int callPosixSpawn(const char *cmdline) {
|
|
|
|
char command[1024];
|
|
|
|
char progName[1024];
|
|
|
|
char progPath[MAXPATHLEN];
|
|
|
|
char* argv[100];
|
2022-04-06 08:26:49 +00:00
|
|
|
int argc __attribute__((unused)) = 0;
|
2017-01-06 09:53:47 +00:00
|
|
|
char *p;
|
|
|
|
pid_t thePid = 0;
|
|
|
|
int result = 0;
|
|
|
|
int status = 0;
|
|
|
|
extern char **environ;
|
2017-06-04 13:05:58 +00:00
|
|
|
|
|
|
|
// Make a copy of cmdline because parse_posix_spawn_command_line modifies it
|
2017-01-06 09:53:47 +00:00
|
|
|
strlcpy(command, cmdline, sizeof(command));
|
2022-04-06 08:26:49 +00:00
|
|
|
argc = parse_posix_spawn_command_line(const_cast<char*>(command), argv);
|
2017-01-06 09:53:47 +00:00
|
|
|
strlcpy(progPath, argv[0], sizeof(progPath));
|
|
|
|
strlcpy(progName, argv[0], sizeof(progName));
|
|
|
|
p = strrchr(progName, '/');
|
|
|
|
if (p) {
|
|
|
|
argv[0] = p+1;
|
|
|
|
} else {
|
|
|
|
argv[0] = progName;
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
#if VERBOSE_TEST
|
|
|
|
print_to_log_file("***********");
|
|
|
|
for (int i=0; i<argc; ++i) {
|
|
|
|
print_to_log_file("argv[%d]=%s", i, argv[i]);
|
|
|
|
}
|
|
|
|
print_to_log_file("***********\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
result = posix_spawnp(&thePid, progPath, NULL, NULL, argv, environ);
|
|
|
|
#if VERBOSE_TEST
|
|
|
|
print_to_log_file("callPosixSpawn command: %s", cmdline);
|
|
|
|
print_to_log_file("callPosixSpawn: posix_spawnp returned %d: %s", result, strerror(result));
|
|
|
|
#endif
|
|
|
|
if (result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
// CAF int val =
|
|
|
|
waitpid(thePid, &status, WUNTRACED);
|
|
|
|
// CAF if (val < 0) printf("first waitpid returned %d\n", val);
|
|
|
|
if (status != 0) {
|
|
|
|
#if VERBOSE_TEST
|
|
|
|
print_to_log_file("waitpid() returned status=%d", status);
|
|
|
|
#endif
|
|
|
|
result = status;
|
|
|
|
} else {
|
|
|
|
if (WIFEXITED(status)) {
|
|
|
|
result = WEXITSTATUS(status);
|
|
|
|
if (result == 1) {
|
|
|
|
#if VERBOSE_TEST
|
|
|
|
print_to_log_file("WEXITSTATUS(status) returned 1, errno=%d: %s", errno, strerror(errno));
|
|
|
|
#endif
|
|
|
|
result = errno;
|
|
|
|
}
|
|
|
|
#if VERBOSE_TEST
|
|
|
|
else if (result) {
|
|
|
|
print_to_log_file("WEXITSTATUS(status) returned %d", result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} // end if (WIFEXITED(status)) else
|
|
|
|
} // end if waitpid returned 0 sstaus else
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2017-01-06 09:53:47 +00:00
|
|
|
return result;
|
2006-06-27 12:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// For debugging
|
|
|
|
void print_to_log_file(const char *format, ...) {
|
|
|
|
FILE *f;
|
|
|
|
va_list args;
|
2017-07-12 12:06:12 +00:00
|
|
|
char buf[MAXPATHLEN];
|
2006-06-27 12:56:11 +00:00
|
|
|
time_t t;
|
2017-07-12 12:06:12 +00:00
|
|
|
// strlcpy(buf, getenv("HOME"), sizeof(buf));
|
|
|
|
// strlcat(buf, "/Documents/test_log.txt", sizeof(buf));
|
|
|
|
|
2021-06-23 06:56:57 +00:00
|
|
|
snprintf(buf, sizeof(buf), "/tmp/%s/BOINC_Installer_Errors.txt", tempDirName);
|
2006-06-27 12:56:11 +00:00
|
|
|
f = fopen(buf, "a");
|
|
|
|
if (!f) return;
|
|
|
|
|
|
|
|
// freopen(buf, "a", stdout);
|
|
|
|
// freopen(buf, "a", stderr);
|
|
|
|
|
|
|
|
time(&t);
|
2017-01-06 09:53:47 +00:00
|
|
|
strlcpy(buf, asctime(localtime(&t)),sizeof(buf));
|
2006-06-27 12:56:11 +00:00
|
|
|
strip_cr(buf);
|
|
|
|
|
|
|
|
fputs(buf, f);
|
|
|
|
fputs(" ", f);
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(f, format, args);
|
|
|
|
va_end(args);
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
fputs("\n", f);
|
|
|
|
fflush(f);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void strip_cr(char *buf)
|
|
|
|
{
|
|
|
|
char *theCR;
|
|
|
|
|
|
|
|
theCR = strrchr(buf, '\n');
|
|
|
|
if (theCR)
|
|
|
|
*theCR = '\0';
|
|
|
|
theCR = strrchr(buf, '\r');
|
|
|
|
if (theCR)
|
|
|
|
*theCR = '\0';
|
|
|
|
}
|