2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-08-11 11:30:25 +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.
|
2005-01-20 23:22:22 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +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/>.
|
2004-08-11 11:30:25 +00:00
|
|
|
|
|
|
|
// initialization and starting of applications
|
|
|
|
|
|
|
|
#include "cpp.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
2008-02-15 15:52:16 +00:00
|
|
|
#include "win_util.h"
|
2013-07-05 21:18:45 +00:00
|
|
|
#define unlink _unlink
|
2009-08-22 17:00:19 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#define strdup _strdup
|
2013-07-10 07:05:27 +00:00
|
|
|
#define getcwd _getcwd
|
2009-08-22 17:00:19 +00:00
|
|
|
#endif
|
2004-08-11 11:30:25 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2011-09-27 19:45:27 +00:00
|
|
|
#if HAVE_SCHED_SETSCHEDULER && defined (__linux__)
|
2009-09-23 16:51:40 +00:00
|
|
|
#include <sched.h>
|
|
|
|
#endif
|
2004-08-16 11:31:59 +00:00
|
|
|
#if HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
2004-08-11 11:30:25 +00:00
|
|
|
#endif
|
2004-08-11 15:27:46 +00:00
|
|
|
#if HAVE_SYS_RESOURCE_H
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
2004-08-16 11:31:59 +00:00
|
|
|
#if HAVE_SYS_IPC_H
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#endif
|
2004-08-11 15:27:46 +00:00
|
|
|
#if HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
2004-08-11 11:30:25 +00:00
|
|
|
#include <unistd.h>
|
2004-08-12 13:02:25 +00:00
|
|
|
#include <cerrno>
|
2008-01-18 02:08:25 +00:00
|
|
|
#include <sys/stat.h>
|
2008-07-24 19:05:26 +00:00
|
|
|
#include <string>
|
2004-08-11 11:30:25 +00:00
|
|
|
#endif
|
|
|
|
|
2005-12-02 22:29:35 +00:00
|
|
|
#ifdef __EMX__
|
|
|
|
#include <process.h>
|
|
|
|
#endif
|
|
|
|
|
2007-10-24 00:44:42 +00:00
|
|
|
#if (defined (__APPLE__) && (defined(__i386__) || defined(__x86_64__)))
|
2006-02-06 23:44:05 +00:00
|
|
|
#include <mach-o/loader.h>
|
|
|
|
#include <mach-o/fat.h>
|
|
|
|
#include <mach/machine.h>
|
|
|
|
#include <libkern/OSByteOrder.h>
|
|
|
|
#endif
|
|
|
|
|
2007-09-26 10:16:04 +00:00
|
|
|
#if(!defined (_WIN32) && !defined (__EMX__))
|
2007-08-28 06:12:48 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
2008-07-01 21:27:25 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
using std::vector;
|
2008-07-21 16:25:03 +00:00
|
|
|
using std::string;
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2012-02-03 18:33:39 +00:00
|
|
|
#include "base64.h"
|
2004-08-11 11:30:25 +00:00
|
|
|
#include "error_numbers.h"
|
2012-02-03 18:33:39 +00:00
|
|
|
#include "filesys.h"
|
2004-08-11 11:30:25 +00:00
|
|
|
#include "shmem.h"
|
2012-02-03 18:33:39 +00:00
|
|
|
#include "str_replace.h"
|
|
|
|
#include "str_util.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#include "async_file.h"
|
2004-08-11 11:30:25 +00:00
|
|
|
#include "client_msgs.h"
|
|
|
|
#include "client_state.h"
|
|
|
|
#include "file_names.h"
|
2012-04-30 21:00:28 +00:00
|
|
|
#include "result.h"
|
2007-10-05 16:47:07 +00:00
|
|
|
#include "sandbox.h"
|
2008-03-11 03:59:35 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2011-09-02 18:47:15 +00:00
|
|
|
#include "run_app_windows.h"
|
2008-03-11 03:59:35 +00:00
|
|
|
#endif
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2009-12-05 00:51:05 +00:00
|
|
|
#include "cs_proxy.h"
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
#include "app.h"
|
|
|
|
|
2008-05-02 15:59:37 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2008-05-11 23:11:16 +00:00
|
|
|
// Dynamically link to these functions at runtime;
|
|
|
|
// otherwise BOINC cannot run on Win98
|
2008-05-02 15:59:37 +00:00
|
|
|
|
|
|
|
// CreateEnvironmentBlock
|
|
|
|
typedef BOOL (WINAPI *tCEB)(LPVOID *lpEnvironment, HANDLE hToken, BOOL bInherit);
|
|
|
|
// DestroyEnvironmentBlock
|
|
|
|
typedef BOOL (WINAPI *tDEB)(LPVOID lpEnvironment);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-11-26 20:49:31 +00:00
|
|
|
// print each string in an array
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2006-11-20 17:12:55 +00:00
|
|
|
#ifndef _WIN32
|
2006-06-22 19:40:30 +00:00
|
|
|
static void debug_print_argv(char** argv) {
|
2010-04-29 20:32:51 +00:00
|
|
|
msg_printf(0, MSG_INFO, "[task] Arguments:");
|
2008-03-19 16:54:36 +00:00
|
|
|
for (int i=0; argv[i]; i++) {
|
2010-04-29 20:32:51 +00:00
|
|
|
msg_printf(0, MSG_INFO, "[task] argv[%d]: %s\n", i, argv[i]);
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-20 17:12:55 +00:00
|
|
|
#endif
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2009-08-19 23:21:55 +00:00
|
|
|
// For apps that use coprocessors, append "--device x" to the command line.
|
2011-09-11 03:28:22 +00:00
|
|
|
// NOTE: this is deprecated. Use app_init_data instead.
|
2008-07-21 16:25:03 +00:00
|
|
|
//
|
2009-03-06 23:10:45 +00:00
|
|
|
static void coproc_cmdline(
|
2009-09-22 21:02:06 +00:00
|
|
|
int rsc_type, RESULT* rp, double ninstances, char* cmdline
|
2009-03-06 23:10:45 +00:00
|
|
|
) {
|
2011-08-25 06:33:35 +00:00
|
|
|
char buf[256];
|
2011-03-25 03:44:09 +00:00
|
|
|
COPROC* coproc = &coprocs.coprocs[rsc_type];
|
2009-08-19 23:21:55 +00:00
|
|
|
for (int j=0; j<ninstances; j++) {
|
2009-09-22 21:02:06 +00:00
|
|
|
int k = rp->coproc_indices[j];
|
2009-08-19 23:21:55 +00:00
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
if (k < 0 || k >= coproc->count) {
|
2011-08-25 06:33:35 +00:00
|
|
|
msg_printf(0, MSG_INTERNAL_ERROR,
|
|
|
|
"coproc_cmdline: coproc index %d out of range", k
|
|
|
|
);
|
|
|
|
k = 0;
|
2009-03-06 23:10:45 +00:00
|
|
|
}
|
2009-08-19 23:21:55 +00:00
|
|
|
sprintf(buf, " --device %d", coproc->device_nums[k]);
|
|
|
|
strcat(cmdline, buf);
|
2008-07-21 16:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-21 22:41:48 +00:00
|
|
|
// Make a unique key for client/app shared memory segment.
|
2008-05-11 23:11:16 +00:00
|
|
|
// Windows: also create and attach to the segment.
|
2004-08-31 21:02:17 +00:00
|
|
|
//
|
|
|
|
int ACTIVE_TASK::get_shmem_seg_name() {
|
|
|
|
#ifdef _WIN32
|
2008-05-11 23:11:16 +00:00
|
|
|
int i;
|
|
|
|
char seg_name[256];
|
2004-08-31 21:02:17 +00:00
|
|
|
|
2008-06-20 21:33:02 +00:00
|
|
|
bool try_global = (sandbox_account_service_token != NULL);
|
2004-08-31 21:02:17 +00:00
|
|
|
for (i=0; i<1024; i++) {
|
2008-05-11 23:11:16 +00:00
|
|
|
sprintf(seg_name, "%sboinc_%d", SHM_PREFIX, i);
|
2008-08-16 20:59:53 +00:00
|
|
|
shm_handle = create_shmem(
|
2008-06-20 21:33:02 +00:00
|
|
|
seg_name, sizeof(SHARED_MEM), (void**)&app_client_shm.shm,
|
|
|
|
try_global
|
2008-05-11 23:11:16 +00:00
|
|
|
);
|
2008-08-16 20:59:53 +00:00
|
|
|
if (shm_handle) break;
|
2004-08-31 21:02:17 +00:00
|
|
|
}
|
2008-08-16 20:59:53 +00:00
|
|
|
if (!shm_handle) return ERR_SHMGET;
|
2008-05-11 23:11:16 +00:00
|
|
|
sprintf(shmem_seg_name, "boinc_%d", i);
|
2004-11-02 23:12:29 +00:00
|
|
|
#else
|
2012-05-09 16:11:50 +00:00
|
|
|
char init_data_path[MAXPATHLEN];
|
2007-09-26 10:16:04 +00:00
|
|
|
#ifndef __EMX__
|
2011-09-27 19:45:27 +00:00
|
|
|
// shmem_seg_name is not used with mmap() shared memory
|
2014-07-30 20:16:42 +00:00
|
|
|
if (app_version->api_version_at_least(6, 0)) {
|
2007-09-26 10:16:04 +00:00
|
|
|
shmem_seg_name = -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2006-03-03 21:34:03 +00:00
|
|
|
sprintf(init_data_path, "%s/%s", slot_dir, INIT_DATA_FILE);
|
2005-06-25 05:26:54 +00:00
|
|
|
|
2007-09-21 15:07:15 +00:00
|
|
|
// ftok() only works if there's a file at the given location
|
|
|
|
//
|
2010-01-23 00:36:12 +00:00
|
|
|
if (!boinc_file_exists(init_data_path)) {
|
|
|
|
FILE* f = boinc_fopen(init_data_path, "w");
|
2010-05-18 16:45:55 +00:00
|
|
|
if (f) {
|
|
|
|
fclose(f);
|
|
|
|
} else {
|
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
|
|
|
"error: can't open file for shmem seg name"
|
|
|
|
);
|
|
|
|
}
|
2010-01-23 00:36:12 +00:00
|
|
|
}
|
2007-05-23 20:36:49 +00:00
|
|
|
shmem_seg_name = ftok(init_data_path, 1);
|
2010-05-18 16:45:55 +00:00
|
|
|
if (shmem_seg_name == -1) {
|
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
|
|
|
"error: can't open file for shmem seg name: %d", errno
|
|
|
|
);
|
|
|
|
perror("ftok");
|
|
|
|
return ERR_SHMEM_NAME;
|
|
|
|
}
|
2004-08-31 21:02:17 +00:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-11 17:26:31 +00:00
|
|
|
void ACTIVE_TASK::init_app_init_data(APP_INIT_DATA& aid) {
|
2005-08-31 00:18:36 +00:00
|
|
|
aid.major_version = BOINC_MAJOR_VERSION;
|
|
|
|
aid.minor_version = BOINC_MINOR_VERSION;
|
|
|
|
aid.release = BOINC_RELEASE;
|
2005-10-12 18:40:53 +00:00
|
|
|
aid.app_version = app_version->version_num;
|
2004-08-11 11:30:25 +00:00
|
|
|
safe_strcpy(aid.app_name, wup->app->name);
|
2006-05-22 09:54:31 +00:00
|
|
|
safe_strcpy(aid.symstore, wup->project->symstore);
|
2010-09-08 18:06:56 +00:00
|
|
|
safe_strcpy(aid.acct_mgr_url, gstate.acct_mgr_info.master_url);
|
2004-08-11 11:30:25 +00:00
|
|
|
if (wup->project->project_specific_prefs.length()) {
|
2011-09-11 17:26:31 +00:00
|
|
|
aid.project_preferences = strdup(
|
|
|
|
wup->project->project_specific_prefs.c_str()
|
|
|
|
);
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2011-01-13 22:40:48 +00:00
|
|
|
aid.userid = wup->project->userid;
|
|
|
|
aid.teamid = wup->project->teamid;
|
2009-02-11 23:01:21 +00:00
|
|
|
aid.hostid = wup->project->hostid;
|
|
|
|
safe_strcpy(aid.user_name, wup->project->user_name);
|
|
|
|
safe_strcpy(aid.team_name, wup->project->team_name);
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(aid.project_dir, wup->project->project_dir_absolute());
|
2004-08-11 11:30:25 +00:00
|
|
|
relative_to_absolute("", aid.boinc_dir);
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(aid.authenticator, wup->project->authenticator);
|
2004-08-11 11:30:25 +00:00
|
|
|
aid.slot = slot;
|
2012-10-11 16:41:31 +00:00
|
|
|
#ifdef _WIN32
|
2012-10-11 19:22:34 +00:00
|
|
|
if (strstr(gstate.host_info.os_name, "Windows 2000")) {
|
2012-10-11 16:41:31 +00:00
|
|
|
// Win2K immediately reuses PIDs, so can't use this mechanism
|
|
|
|
//
|
|
|
|
aid.client_pid = 0;
|
|
|
|
} else {
|
|
|
|
aid.client_pid = GetCurrentProcessId();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
aid.client_pid = getpid();
|
|
|
|
#endif
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(aid.wu_name, wup->name);
|
|
|
|
safe_strcpy(aid.result_name, result->name);
|
2004-08-11 11:30:25 +00:00
|
|
|
aid.user_total_credit = wup->project->user_total_credit;
|
|
|
|
aid.user_expavg_credit = wup->project->user_expavg_credit;
|
|
|
|
aid.host_total_credit = wup->project->host_total_credit;
|
|
|
|
aid.host_expavg_credit = wup->project->host_expavg_credit;
|
2009-12-02 03:41:52 +00:00
|
|
|
double rrs = gstate.runnable_resource_share(RSC_TYPE_CPU);
|
2006-06-26 17:09:23 +00:00
|
|
|
if (rrs) {
|
|
|
|
aid.resource_share_fraction = wup->project->resource_share/rrs;
|
|
|
|
} else {
|
|
|
|
aid.resource_share_fraction = 1;
|
|
|
|
}
|
2011-09-11 03:28:22 +00:00
|
|
|
aid.host_info = gstate.host_info;
|
|
|
|
aid.proxy_info = working_proxy_info;
|
|
|
|
aid.global_prefs = gstate.global_prefs;
|
|
|
|
aid.starting_elapsed_time = checkpoint_elapsed_time;
|
2011-10-21 06:58:35 +00:00
|
|
|
aid.using_sandbox = g_use_sandbox;
|
2013-10-04 03:52:05 +00:00
|
|
|
aid.vm_extensions_disabled = gstate.host_info.p_vm_extensions_disabled;
|
2006-06-09 02:33:00 +00:00
|
|
|
aid.rsc_fpops_est = wup->rsc_fpops_est;
|
|
|
|
aid.rsc_fpops_bound = wup->rsc_fpops_bound;
|
|
|
|
aid.rsc_memory_bound = wup->rsc_memory_bound;
|
|
|
|
aid.rsc_disk_bound = wup->rsc_disk_bound;
|
2008-06-12 19:05:14 +00:00
|
|
|
aid.computation_deadline = result->computation_deadline();
|
2011-09-11 17:26:31 +00:00
|
|
|
int rt = app_version->gpu_usage.rsc_type;
|
2011-09-11 03:28:22 +00:00
|
|
|
if (rt) {
|
|
|
|
COPROC& cp = coprocs.coprocs[rt];
|
2014-07-23 12:18:51 +00:00
|
|
|
if (coproc_type_name_to_num(cp.type) >= 0) {
|
|
|
|
// Standardized vendor name ("NVIDIA", "ATI" or "intel_gpu")
|
|
|
|
safe_strcpy(aid.gpu_type, cp.type);
|
|
|
|
} else {
|
|
|
|
// For other vendors, use vendor name as returned by OpenCL
|
|
|
|
safe_strcpy(aid.gpu_type, cp.opencl_prop.vendor);
|
|
|
|
}
|
2011-09-11 03:28:22 +00:00
|
|
|
int k = result->coproc_indices[0];
|
2011-09-11 17:26:31 +00:00
|
|
|
if (k<0 || k>=cp.count) {
|
2011-09-11 03:28:22 +00:00
|
|
|
msg_printf(0, MSG_INTERNAL_ERROR,
|
2011-10-24 17:53:09 +00:00
|
|
|
"init_app_init_data(): coproc index %d out of range", k
|
2011-09-11 03:28:22 +00:00
|
|
|
);
|
|
|
|
k = 0;
|
|
|
|
}
|
2011-09-11 17:26:31 +00:00
|
|
|
aid.gpu_device_num = cp.device_nums[k];
|
2012-01-20 13:30:47 +00:00
|
|
|
aid.gpu_opencl_dev_index = cp.opencl_device_indexes[k];
|
2013-03-21 03:37:26 +00:00
|
|
|
aid.gpu_usage = app_version->gpu_usage.usage;
|
2011-09-11 03:28:22 +00:00
|
|
|
} else {
|
|
|
|
strcpy(aid.gpu_type, "");
|
2011-09-11 17:26:31 +00:00
|
|
|
aid.gpu_device_num = -1;
|
2012-01-20 13:30:47 +00:00
|
|
|
aid.gpu_opencl_dev_index = -1;
|
2013-03-21 03:37:26 +00:00
|
|
|
aid.gpu_usage = 0;
|
2011-09-11 03:28:22 +00:00
|
|
|
}
|
2011-12-01 18:44:19 +00:00
|
|
|
aid.ncpus = app_version->avg_ncpus;
|
2014-05-08 07:51:18 +00:00
|
|
|
aid.vbox_window = cc_config.vbox_window;
|
2009-10-12 23:54:02 +00:00
|
|
|
aid.checkpoint_period = gstate.global_prefs.disk_interval;
|
2004-08-11 11:30:25 +00:00
|
|
|
aid.fraction_done_start = 0;
|
|
|
|
aid.fraction_done_end = 1;
|
2004-08-31 21:02:17 +00:00
|
|
|
#ifdef _WIN32
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(aid.shmem_seg_name, shmem_seg_name);
|
2004-08-31 21:02:17 +00:00
|
|
|
#else
|
|
|
|
aid.shmem_seg_name = shmem_seg_name;
|
2004-08-11 11:30:25 +00:00
|
|
|
#endif
|
2009-07-01 17:35:56 +00:00
|
|
|
aid.wu_cpu_time = checkpoint_cpu_time;
|
2011-09-11 03:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// write the app init file.
|
2011-11-03 03:29:07 +00:00
|
|
|
// This is done before starting or restarting the app,
|
2011-09-11 03:28:22 +00:00
|
|
|
// and when project prefs have changed during app execution
|
|
|
|
//
|
2011-09-11 17:26:31 +00:00
|
|
|
int ACTIVE_TASK::write_app_init_file(APP_INIT_DATA& aid) {
|
2011-09-11 03:28:22 +00:00
|
|
|
FILE *f;
|
2012-05-09 16:11:50 +00:00
|
|
|
char init_data_path[MAXPATHLEN];
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2013-11-29 19:44:09 +00:00
|
|
|
#if 0
|
2014-05-02 04:03:49 +00:00
|
|
|
msg_printf(wup->project, MSG_INFO,
|
|
|
|
"writing app_init.xml for %s; slot %d rt %s gpu_device_num %d", result->name, slot, aid.gpu_type, aid.gpu_device_num
|
|
|
|
);
|
2013-11-29 19:44:09 +00:00
|
|
|
#endif
|
|
|
|
|
2006-03-03 21:34:03 +00:00
|
|
|
sprintf(init_data_path, "%s/%s", slot_dir, INIT_DATA_FILE);
|
2010-01-26 00:21:57 +00:00
|
|
|
|
|
|
|
// delete the file using the switcher (Unix)
|
|
|
|
// in case it's owned by another user and we don't have write access
|
|
|
|
//
|
|
|
|
delete_project_owned_file(init_data_path, false);
|
2004-08-11 11:30:25 +00:00
|
|
|
f = boinc_fopen(init_data_path, "w");
|
|
|
|
if (!f) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Failed to open init file %s",
|
2004-08-11 11:30:25 +00:00
|
|
|
init_data_path
|
|
|
|
);
|
|
|
|
return ERR_FOPEN;
|
|
|
|
}
|
|
|
|
|
2011-09-11 03:28:22 +00:00
|
|
|
int retval = write_init_data_file(f, aid);
|
2004-08-11 11:30:25 +00:00
|
|
|
fclose(f);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-02-11 00:37:01 +00:00
|
|
|
// Given a logical name of the form D1/D2/.../Dn/F,
|
|
|
|
// create the directories D1 ... Dn in the slot dir
|
|
|
|
//
|
|
|
|
static int create_dirs_for_logical_name(
|
|
|
|
const char* name, const char* slot_dir
|
|
|
|
) {
|
|
|
|
char buf[1024];
|
2012-05-09 16:11:50 +00:00
|
|
|
char dir_path[MAXPATHLEN];
|
2011-02-11 00:37:01 +00:00
|
|
|
int retval;
|
|
|
|
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(buf, name);
|
|
|
|
safe_strcpy(dir_path, slot_dir);
|
2011-02-11 00:37:01 +00:00
|
|
|
char* p = buf;
|
|
|
|
while (1) {
|
|
|
|
char* q = strstr(p, "/");
|
|
|
|
if (!q) break;
|
|
|
|
*q = 0;
|
|
|
|
strcat(dir_path, "/");
|
|
|
|
strcat(dir_path, p);
|
|
|
|
retval = boinc_mkdir(dir_path);
|
|
|
|
if (retval) return retval;
|
|
|
|
p = q+1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-04 03:24:48 +00:00
|
|
|
static void prepend_prefix(APP_VERSION* avp, char* in, char* out, int len) {
|
2011-08-03 18:14:45 +00:00
|
|
|
if (strlen(avp->file_prefix)) {
|
|
|
|
sprintf(out, "%s/%s", avp->file_prefix, in);
|
|
|
|
} else {
|
2013-06-04 03:24:48 +00:00
|
|
|
strlcpy(out, in, len);
|
2011-08-03 18:14:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-03 19:47:26 +00:00
|
|
|
// an input/output file must be copied if either
|
|
|
|
// - the FILE_REFERENCE says so or
|
|
|
|
// - the APP_VERSION has a non-empty file_prefix
|
|
|
|
//
|
|
|
|
bool ACTIVE_TASK::must_copy_file(FILE_REF& fref, bool is_io_file) {
|
2013-04-03 00:23:37 +00:00
|
|
|
if (fref.copy_file) return true;
|
|
|
|
if (is_io_file && strlen(app_version->file_prefix)) return true;
|
|
|
|
return false;
|
2011-08-03 19:47:26 +00:00
|
|
|
}
|
|
|
|
|
2008-03-19 16:54:36 +00:00
|
|
|
// set up a file reference, given a slot dir and project dir.
|
|
|
|
// This means:
|
|
|
|
// 1) copy the file to slot dir, if reference is by copy
|
2008-07-04 19:41:58 +00:00
|
|
|
// 2) else make a soft link
|
2004-08-11 12:15:31 +00:00
|
|
|
//
|
2011-08-03 18:14:45 +00:00
|
|
|
int ACTIVE_TASK::setup_file(
|
2011-08-03 19:47:26 +00:00
|
|
|
FILE_INFO* fip, FILE_REF& fref, char* file_path, bool input, bool is_io_file
|
2004-08-11 12:15:31 +00:00
|
|
|
) {
|
2012-05-09 16:11:50 +00:00
|
|
|
char link_path[MAXPATHLEN], rel_file_path[MAXPATHLEN], open_name[256];
|
2004-08-11 12:15:31 +00:00
|
|
|
int retval;
|
2011-08-03 18:14:45 +00:00
|
|
|
PROJECT* project = result->project;
|
2004-08-11 12:15:31 +00:00
|
|
|
|
2011-02-11 00:37:01 +00:00
|
|
|
if (strlen(fref.open_name)) {
|
2013-04-03 00:23:37 +00:00
|
|
|
if (is_io_file) {
|
2013-06-04 03:24:48 +00:00
|
|
|
prepend_prefix(
|
|
|
|
app_version, fref.open_name, open_name, sizeof(open_name)
|
|
|
|
);
|
2013-04-03 00:23:37 +00:00
|
|
|
} else {
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(open_name, fref.open_name);
|
2013-04-03 00:23:37 +00:00
|
|
|
}
|
2011-08-03 18:14:45 +00:00
|
|
|
retval = create_dirs_for_logical_name(open_name, slot_dir);
|
2011-08-03 16:45:00 +00:00
|
|
|
if (retval) return retval;
|
2011-08-03 18:14:45 +00:00
|
|
|
sprintf(link_path, "%s/%s", slot_dir, open_name);
|
2011-02-11 00:37:01 +00:00
|
|
|
} else {
|
|
|
|
sprintf(link_path, "%s/%s", slot_dir, fip->name);
|
|
|
|
}
|
|
|
|
|
2008-03-19 18:24:42 +00:00
|
|
|
sprintf(rel_file_path, "../../%s", file_path );
|
2006-10-11 16:32:59 +00:00
|
|
|
|
2012-02-08 21:14:34 +00:00
|
|
|
if (boinc_file_exists(link_path)) {
|
2008-03-19 16:54:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-03 19:47:26 +00:00
|
|
|
if (must_copy_file(fref, is_io_file)) {
|
2006-10-11 16:32:59 +00:00
|
|
|
if (input) {
|
2012-02-03 18:33:39 +00:00
|
|
|
// the file may be there already (async copy case)
|
|
|
|
//
|
|
|
|
if (boinc_file_exists(link_path)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-09 00:47:04 +00:00
|
|
|
if (fip->nbytes > ASYNC_FILE_THRESHOLD) {
|
2012-02-03 18:33:39 +00:00
|
|
|
ASYNC_COPY* ac = new ASYNC_COPY;
|
2012-03-21 18:36:00 +00:00
|
|
|
retval = ac->init(this, fip, file_path, link_path);
|
2012-02-03 18:33:39 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
return ERR_IN_PROGRESS;
|
|
|
|
} else {
|
|
|
|
retval = boinc_copy(file_path, link_path);
|
|
|
|
if (retval) {
|
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
|
|
|
"Can't copy %s to %s: %s", file_path, link_path,
|
|
|
|
boincerror(retval)
|
|
|
|
);
|
|
|
|
return retval;
|
|
|
|
}
|
2012-03-21 18:36:00 +00:00
|
|
|
retval = fip->set_permissions(link_path);
|
|
|
|
if (retval) return retval;
|
2006-10-11 16:32:59 +00:00
|
|
|
}
|
2004-08-11 12:15:31 +00:00
|
|
|
}
|
2006-10-11 16:32:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-19 16:54:36 +00:00
|
|
|
#ifdef _WIN32
|
2008-03-27 18:25:29 +00:00
|
|
|
retval = make_soft_link(project, link_path, rel_file_path);
|
|
|
|
if (retval) return retval;
|
2008-03-19 16:54:36 +00:00
|
|
|
#else
|
2008-04-14 04:04:45 +00:00
|
|
|
if (project->use_symlinks) {
|
|
|
|
retval = symlink(rel_file_path, link_path);
|
|
|
|
} else {
|
2008-03-27 18:25:29 +00:00
|
|
|
retval = make_soft_link(project, link_path, rel_file_path);
|
2008-03-19 16:54:36 +00:00
|
|
|
}
|
2008-04-14 04:04:45 +00:00
|
|
|
if (retval) return retval;
|
2008-03-19 16:54:36 +00:00
|
|
|
#endif
|
2014-07-27 17:19:11 +00:00
|
|
|
if (g_use_sandbox) set_to_project_group(link_path);
|
2008-03-19 16:54:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ACTIVE_TASK::link_user_files() {
|
|
|
|
PROJECT* project = wup->project;
|
|
|
|
unsigned int i;
|
|
|
|
FILE_REF fref;
|
|
|
|
FILE_INFO* fip;
|
2012-05-09 16:11:50 +00:00
|
|
|
char file_path[MAXPATHLEN];
|
2008-03-19 16:54:36 +00:00
|
|
|
|
|
|
|
for (i=0; i<project->user_files.size(); i++) {
|
|
|
|
fref = project->user_files[i];
|
|
|
|
fip = fref.file_info;
|
|
|
|
if (fip->status != FILE_PRESENT) continue;
|
|
|
|
get_pathname(fip, file_path, sizeof(file_path));
|
2011-08-03 19:47:26 +00:00
|
|
|
setup_file(fip, fref, file_path, true, false);
|
2004-08-11 12:15:31 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-14 18:04:12 +00:00
|
|
|
int ACTIVE_TASK::copy_output_files() {
|
2011-08-03 18:14:45 +00:00
|
|
|
char slotfile[256], projfile[256], open_name[256];
|
2006-06-14 18:04:12 +00:00
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<result->output_files.size(); i++) {
|
|
|
|
FILE_REF& fref = result->output_files[i];
|
2011-08-03 19:47:26 +00:00
|
|
|
if (!must_copy_file(fref, true)) continue;
|
2006-06-14 18:04:12 +00:00
|
|
|
FILE_INFO* fip = fref.file_info;
|
2013-06-04 03:24:48 +00:00
|
|
|
prepend_prefix(
|
|
|
|
app_version, fref.open_name, open_name, sizeof(open_name)
|
|
|
|
);
|
2011-08-03 18:14:45 +00:00
|
|
|
sprintf(slotfile, "%s/%s", slot_dir, open_name);
|
2007-03-13 19:33:27 +00:00
|
|
|
get_pathname(fip, projfile, sizeof(projfile));
|
2009-09-17 22:54:09 +00:00
|
|
|
#if 1
|
|
|
|
boinc_rename(slotfile, projfile);
|
|
|
|
#else
|
2006-06-14 18:04:12 +00:00
|
|
|
int retval = boinc_rename(slotfile, projfile);
|
2009-09-17 21:06:11 +00:00
|
|
|
// this isn't a BOINC error.
|
|
|
|
// it just means the app didn't create an output file
|
|
|
|
// that it was supposed to.
|
|
|
|
//
|
2006-06-14 18:04:12 +00:00
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
2008-06-26 03:50:03 +00:00
|
|
|
"Can't rename output file %s to %s: %s",
|
|
|
|
fip->name, projfile, boincerror(retval)
|
2006-06-14 18:04:12 +00:00
|
|
|
);
|
|
|
|
}
|
2009-09-17 21:06:11 +00:00
|
|
|
#endif
|
2006-06-14 18:04:12 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
// Start a task in a slot directory.
|
|
|
|
// This includes setting up soft links,
|
|
|
|
// passing preferences, and starting the process
|
|
|
|
//
|
|
|
|
// Current dir is top-level BOINC dir
|
|
|
|
//
|
2006-06-20 19:34:42 +00:00
|
|
|
// postcondition:
|
|
|
|
// If any error occurs
|
|
|
|
// ACTIVE_TASK::task_state is PROCESS_COULDNT_START
|
|
|
|
// report_result_error() is called
|
2011-11-03 03:29:07 +00:00
|
|
|
// else
|
2006-06-20 19:34:42 +00:00
|
|
|
// ACTIVE_TASK::task_state is PROCESS_EXECUTING
|
2004-10-07 19:18:37 +00:00
|
|
|
//
|
2013-07-04 23:00:10 +00:00
|
|
|
// If "test" is set, we're doing the API test; just run "test_app".
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK::start(bool test) {
|
2012-05-09 16:11:50 +00:00
|
|
|
char exec_name[256], file_path[MAXPATHLEN], buf[256], exec_path[MAXPATHLEN];
|
2011-04-04 18:03:50 +00:00
|
|
|
char cmdline[80000]; // 64KB plus some extra
|
2004-08-11 11:30:25 +00:00
|
|
|
unsigned int i;
|
2004-08-11 12:15:31 +00:00
|
|
|
FILE_REF fref;
|
2004-08-11 11:30:25 +00:00
|
|
|
FILE_INFO* fip;
|
2014-07-31 00:00:35 +00:00
|
|
|
int retval;
|
2011-09-11 17:26:31 +00:00
|
|
|
APP_INIT_DATA aid;
|
2014-05-01 17:40:58 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
bool success = false;
|
|
|
|
LPVOID environment_block=NULL;
|
|
|
|
#endif
|
2008-07-21 19:56:01 +00:00
|
|
|
|
2012-02-04 00:18:37 +00:00
|
|
|
if (async_copy) {
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(wup->project, MSG_INFO,
|
2012-02-09 00:47:04 +00:00
|
|
|
"[task_debug] ACTIVE_TASK::start(): async file copy already in progress"
|
2012-02-04 00:18:37 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-07 18:27:17 +00:00
|
|
|
// run it at above idle priority if it uses less than one CPU
|
|
|
|
// or is a wrapper
|
2008-09-26 22:56:42 +00:00
|
|
|
//
|
2013-11-07 18:27:17 +00:00
|
|
|
bool high_priority = false;
|
|
|
|
if (app_version->avg_ncpus < 1) high_priority = true;
|
|
|
|
if (app_version->is_wrapper) high_priority = true;
|
2008-09-26 22:56:42 +00:00
|
|
|
|
2006-06-20 17:36:28 +00:00
|
|
|
if (wup->project->verify_files_on_app_start) {
|
2008-02-03 21:46:30 +00:00
|
|
|
fip=0;
|
2007-11-07 19:32:32 +00:00
|
|
|
retval = gstate.input_files_available(result, true, &fip);
|
2006-06-20 19:34:42 +00:00
|
|
|
if (retval) {
|
2007-11-07 19:32:32 +00:00
|
|
|
if (fip) {
|
|
|
|
snprintf(
|
2011-11-03 03:29:07 +00:00
|
|
|
buf, sizeof(buf),
|
2012-10-31 19:44:18 +00:00
|
|
|
"Input file %s missing or invalid: %s",
|
|
|
|
fip->name, boincerror(retval)
|
2007-11-07 19:32:32 +00:00
|
|
|
);
|
|
|
|
} else {
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(buf, "Input file missing or invalid");
|
2007-11-07 19:32:32 +00:00
|
|
|
}
|
2006-06-20 19:34:42 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2006-06-20 17:36:28 +00:00
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
current_cpu_time = checkpoint_cpu_time;
|
2010-05-27 19:46:09 +00:00
|
|
|
elapsed_time = checkpoint_elapsed_time;
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2007-09-21 15:07:15 +00:00
|
|
|
graphics_request_queue.init(result->name); // reset message queues
|
|
|
|
process_control_queue.init(result->name);
|
2006-12-09 00:10:53 +00:00
|
|
|
|
2014-04-30 07:21:29 +00:00
|
|
|
bytes_sent_episode = 0;
|
|
|
|
bytes_received_episode = 0;
|
2012-01-09 03:00:10 +00:00
|
|
|
|
2004-08-31 21:02:17 +00:00
|
|
|
if (!app_client_shm.shm) {
|
|
|
|
retval = get_shmem_seg_name();
|
|
|
|
if (retval) {
|
2006-06-20 19:34:42 +00:00
|
|
|
sprintf(buf,
|
|
|
|
"Can't get shared memory segment name: %s",
|
|
|
|
boincerror(retval)
|
2004-08-31 21:02:17 +00:00
|
|
|
);
|
2006-06-20 19:34:42 +00:00
|
|
|
goto error;
|
2004-08-31 21:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-01 04:59:32 +00:00
|
|
|
|
2006-12-09 00:10:53 +00:00
|
|
|
// this must go AFTER creating shmem name,
|
2005-06-25 05:26:54 +00:00
|
|
|
// since the shmem name is part of the file
|
|
|
|
//
|
2011-09-11 17:26:31 +00:00
|
|
|
init_app_init_data(aid);
|
|
|
|
retval = write_app_init_file(aid);
|
2006-06-20 19:34:42 +00:00
|
|
|
if (retval) {
|
2012-10-31 19:44:18 +00:00
|
|
|
sprintf(buf, "Can't write init file: %s", boincerror(retval));
|
2006-06-20 19:34:42 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2005-06-25 05:26:54 +00:00
|
|
|
|
2004-08-11 12:15:31 +00:00
|
|
|
// set up applications files
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2013-07-04 23:00:10 +00:00
|
|
|
if (test) {
|
|
|
|
strcpy(exec_name, "test_app");
|
|
|
|
strcpy(exec_path, "test_app");
|
|
|
|
} else {
|
|
|
|
strcpy(exec_name, "");
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
for (i=0; i<app_version->app_files.size(); i++) {
|
2005-02-18 23:50:38 +00:00
|
|
|
fref = app_version->app_files[i];
|
2004-08-11 11:30:25 +00:00
|
|
|
fip = fref.file_info;
|
2007-03-13 19:33:27 +00:00
|
|
|
get_pathname(fip, file_path, sizeof(file_path));
|
2004-08-11 11:30:25 +00:00
|
|
|
if (fref.main_program) {
|
2005-04-06 19:41:31 +00:00
|
|
|
if (is_image_file(fip->name)) {
|
2006-06-20 19:34:42 +00:00
|
|
|
sprintf(buf, "Main program %s is an image file", fip->name);
|
|
|
|
retval = ERR_NO_SIGNATURE;
|
|
|
|
goto error;
|
2005-04-06 19:41:31 +00:00
|
|
|
}
|
2005-03-08 00:23:58 +00:00
|
|
|
if (!fip->executable && !wup->project->anonymous_platform) {
|
2006-06-20 19:34:42 +00:00
|
|
|
sprintf(buf, "Main program %s is not executable", fip->name);
|
|
|
|
retval = ERR_NO_SIGNATURE;
|
|
|
|
goto error;
|
2005-02-11 18:26:59 +00:00
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
safe_strcpy(exec_name, fip->name);
|
|
|
|
safe_strcpy(exec_path, file_path);
|
|
|
|
}
|
2012-02-08 21:14:34 +00:00
|
|
|
retval = setup_file(fip, fref, file_path, true, false);
|
|
|
|
if (retval == ERR_IN_PROGRESS) {
|
|
|
|
set_task_state(PROCESS_COPY_PENDING, "start");
|
|
|
|
return 0;
|
|
|
|
} else if (retval) {
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(buf, "Can't link app version file");
|
2012-02-08 21:14:34 +00:00
|
|
|
goto error;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-11 18:26:59 +00:00
|
|
|
if (!strlen(exec_name)) {
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(buf, "No main program specified");
|
2006-06-20 19:34:42 +00:00
|
|
|
retval = ERR_NOT_FOUND;
|
|
|
|
goto error;
|
2005-02-11 18:26:59 +00:00
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2006-04-28 17:23:00 +00:00
|
|
|
// set up input, output files
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2012-02-08 21:14:34 +00:00
|
|
|
for (i=0; i<wup->input_files.size(); i++) {
|
|
|
|
fref = wup->input_files[i];
|
|
|
|
fip = fref.file_info;
|
|
|
|
get_pathname(fref.file_info, file_path, sizeof(file_path));
|
|
|
|
retval = setup_file(fip, fref, file_path, true, true);
|
|
|
|
if (retval == ERR_IN_PROGRESS) {
|
|
|
|
set_task_state(PROCESS_COPY_PENDING, "start");
|
|
|
|
return 0;
|
|
|
|
} else if (retval) {
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(buf, "Can't link input file");
|
2012-02-08 21:14:34 +00:00
|
|
|
goto error;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2012-02-08 21:14:34 +00:00
|
|
|
}
|
|
|
|
for (i=0; i<result->output_files.size(); i++) {
|
|
|
|
fref = result->output_files[i];
|
|
|
|
if (must_copy_file(fref, true)) continue;
|
|
|
|
fip = fref.file_info;
|
|
|
|
get_pathname(fref.file_info, file_path, sizeof(file_path));
|
|
|
|
retval = setup_file(fip, fref, file_path, false, true);
|
|
|
|
if (retval) {
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(buf, "Can't link output file");
|
2012-02-08 21:14:34 +00:00
|
|
|
goto error;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
link_user_files();
|
2011-08-03 16:45:00 +00:00
|
|
|
// don't check retval here
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2012-02-10 05:31:30 +00:00
|
|
|
// remove temporary exit file from last run
|
2009-12-13 05:16:40 +00:00
|
|
|
//
|
|
|
|
sprintf(file_path, "%s/%s", slot_dir, TEMPORARY_EXIT_FILE);
|
2009-12-14 19:24:06 +00:00
|
|
|
delete_project_owned_file(file_path, true);
|
2009-12-13 05:16:40 +00:00
|
|
|
|
2014-05-08 07:51:18 +00:00
|
|
|
if (cc_config.exit_before_start) {
|
2011-09-07 22:45:00 +00:00
|
|
|
msg_printf(0, MSG_INFO, "about to start a job; exiting");
|
2007-05-29 21:45:01 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
PROCESS_INFORMATION process_info;
|
|
|
|
STARTUPINFO startup_info;
|
2012-05-09 16:11:50 +00:00
|
|
|
char slotdirpath[MAXPATHLEN];
|
2005-02-17 21:18:17 +00:00
|
|
|
char error_msg[1024];
|
2008-05-20 21:47:02 +00:00
|
|
|
char error_msg2[1024];
|
2014-12-09 06:02:09 +00:00
|
|
|
DWORD last_error = 0;
|
2014-07-31 00:00:35 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
memset(&process_info, 0, sizeof(process_info));
|
|
|
|
memset(&startup_info, 0, sizeof(startup_info));
|
2007-05-15 20:29:26 +00:00
|
|
|
startup_info.cb = sizeof(startup_info);
|
2008-02-15 15:52:16 +00:00
|
|
|
|
2007-09-21 15:07:15 +00:00
|
|
|
// suppress 2-sec rotating hourglass cursor on startup
|
2008-02-15 15:52:16 +00:00
|
|
|
//
|
|
|
|
startup_info.dwFlags = STARTF_FORCEOFFFEEDBACK;
|
2007-05-15 20:29:26 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
app_client_shm.reset_msgs();
|
|
|
|
|
2014-05-08 07:51:18 +00:00
|
|
|
if (cc_config.run_apps_manually) {
|
2012-06-26 20:30:56 +00:00
|
|
|
// fill in client's PID so we won't think app has exited
|
2008-08-16 20:59:53 +00:00
|
|
|
//
|
2008-01-13 04:16:58 +00:00
|
|
|
pid = GetCurrentProcessId();
|
2010-04-23 22:31:08 +00:00
|
|
|
process_handle = GetCurrentProcess();
|
2008-01-13 04:16:58 +00:00
|
|
|
set_task_state(PROCESS_EXECUTING, "start");
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2008-07-21 16:25:03 +00:00
|
|
|
sprintf(cmdline, "%s %s %s",
|
2008-07-21 19:56:01 +00:00
|
|
|
exec_path, wup->command_line.c_str(), app_version->cmdline
|
2008-07-21 16:25:03 +00:00
|
|
|
);
|
2014-07-30 20:16:42 +00:00
|
|
|
if (!app_version->api_version_at_least(7, 5)) {
|
2014-07-31 00:07:02 +00:00
|
|
|
int rt = app_version->gpu_usage.rsc_type;
|
2014-07-30 20:16:42 +00:00
|
|
|
if (rt) {
|
|
|
|
coproc_cmdline(rt, result, app_version->gpu_usage.usage, cmdline);
|
|
|
|
}
|
2009-08-17 16:50:40 +00:00
|
|
|
}
|
2008-07-21 16:25:03 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
relative_to_absolute(slot_dir, slotdirpath);
|
2009-03-20 18:56:54 +00:00
|
|
|
int prio_mask;
|
2014-05-08 07:51:18 +00:00
|
|
|
if (cc_config.no_priority_change) {
|
2009-03-20 18:56:54 +00:00
|
|
|
prio_mask = 0;
|
|
|
|
} else if (high_priority) {
|
|
|
|
prio_mask = BELOW_NORMAL_PRIORITY_CLASS;
|
|
|
|
} else {
|
|
|
|
prio_mask = IDLE_PRIORITY_CLASS;
|
|
|
|
}
|
2008-03-06 17:18:59 +00:00
|
|
|
|
2005-02-17 21:18:17 +00:00
|
|
|
for (i=0; i<5; i++) {
|
2014-07-11 19:31:23 +00:00
|
|
|
last_error = 0;
|
2008-03-13 21:18:04 +00:00
|
|
|
if (sandbox_account_service_token != NULL) {
|
2008-02-15 15:52:16 +00:00
|
|
|
|
2014-03-06 23:27:54 +00:00
|
|
|
if (!CreateEnvironmentBlock(&environment_block, sandbox_account_service_token, FALSE)) {
|
2008-02-15 15:52:16 +00:00
|
|
|
if (log_flags.task) {
|
2013-01-08 05:36:44 +00:00
|
|
|
windows_format_error_string(GetLastError(), error_msg, sizeof(error_msg));
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(wup->project, MSG_INFO,
|
2008-02-15 15:52:16 +00:00
|
|
|
"Process environment block creation failed: %s", error_msg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-01 22:08:48 +00:00
|
|
|
if (CreateProcessAsUser(
|
2008-03-13 21:18:04 +00:00
|
|
|
sandbox_account_service_token,
|
2008-02-01 22:08:48 +00:00
|
|
|
exec_path,
|
2008-07-21 16:25:03 +00:00
|
|
|
cmdline,
|
2008-02-01 22:08:48 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
2008-09-26 22:56:42 +00:00
|
|
|
CREATE_NEW_PROCESS_GROUP|CREATE_NO_WINDOW|prio_mask|CREATE_UNICODE_ENVIRONMENT,
|
2008-02-15 15:52:16 +00:00
|
|
|
environment_block,
|
2008-02-01 22:08:48 +00:00
|
|
|
slotdirpath,
|
|
|
|
&startup_info,
|
|
|
|
&process_info
|
|
|
|
)) {
|
|
|
|
success = true;
|
|
|
|
break;
|
2008-02-15 15:52:16 +00:00
|
|
|
} else {
|
2014-07-11 19:31:23 +00:00
|
|
|
last_error = GetLastError();
|
|
|
|
windows_format_error_string(last_error, error_msg, sizeof(error_msg));
|
2008-02-15 15:52:16 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
2014-07-11 19:31:23 +00:00
|
|
|
"Process creation failed: %s - error code %d (0x%x)",
|
|
|
|
error_msg, last_error, last_error
|
2008-02-15 15:52:16 +00:00
|
|
|
);
|
2008-02-01 22:08:48 +00:00
|
|
|
}
|
2008-02-15 15:52:16 +00:00
|
|
|
|
2014-03-06 23:27:54 +00:00
|
|
|
if (!DestroyEnvironmentBlock(environment_block)) {
|
2008-02-15 15:52:16 +00:00
|
|
|
if (log_flags.task) {
|
2013-01-08 05:36:44 +00:00
|
|
|
windows_format_error_string(GetLastError(), error_msg, sizeof(error_msg2));
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(wup->project, MSG_INFO,
|
2008-05-20 21:47:02 +00:00
|
|
|
"Process environment block cleanup failed: %s",
|
|
|
|
error_msg2
|
2008-02-15 15:52:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-01 22:08:48 +00:00
|
|
|
} else {
|
|
|
|
if (CreateProcess(
|
|
|
|
exec_path,
|
2008-07-21 16:25:03 +00:00
|
|
|
cmdline,
|
2008-02-01 22:08:48 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
2008-09-26 22:56:42 +00:00
|
|
|
CREATE_NEW_PROCESS_GROUP|CREATE_NO_WINDOW|prio_mask,
|
2008-02-01 22:08:48 +00:00
|
|
|
NULL,
|
|
|
|
slotdirpath,
|
|
|
|
&startup_info,
|
|
|
|
&process_info
|
|
|
|
)) {
|
|
|
|
success = true;
|
|
|
|
break;
|
2008-02-15 15:52:16 +00:00
|
|
|
} else {
|
2014-07-11 19:31:23 +00:00
|
|
|
last_error = GetLastError();
|
|
|
|
windows_format_error_string(last_error, error_msg, sizeof(error_msg));
|
2008-02-15 15:52:16 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
2014-07-11 19:31:23 +00:00
|
|
|
"Process creation failed: %s - error code %d (0x%x)",
|
|
|
|
error_msg, last_error, last_error
|
2008-02-15 15:52:16 +00:00
|
|
|
);
|
2008-02-01 22:08:48 +00:00
|
|
|
}
|
2005-02-17 21:18:17 +00:00
|
|
|
}
|
|
|
|
boinc_sleep(drand());
|
|
|
|
}
|
2008-03-06 17:18:59 +00:00
|
|
|
|
2005-02-17 21:18:17 +00:00
|
|
|
if (!success) {
|
2006-06-20 19:34:42 +00:00
|
|
|
sprintf(buf, "CreateProcess() failed - %s", error_msg);
|
2014-07-11 19:31:23 +00:00
|
|
|
|
|
|
|
if (last_error == ERROR_NOT_ENOUGH_MEMORY) {
|
|
|
|
// if CreateProcess() failed because system is low on memory,
|
|
|
|
// treat this like a temporary exit;
|
|
|
|
// retry in 10 min, and give up after 100 times
|
|
|
|
//
|
|
|
|
bool will_restart;
|
|
|
|
handle_temporary_exit(will_restart, 600, "not enough memory", false);
|
|
|
|
if (will_restart) return 0;
|
|
|
|
}
|
2006-06-20 19:34:42 +00:00
|
|
|
retval = ERR_EXEC;
|
|
|
|
goto error;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
pid = process_info.dwProcessId;
|
2010-04-23 22:31:08 +00:00
|
|
|
process_handle = process_info.hProcess;
|
2008-12-24 23:19:40 +00:00
|
|
|
CloseHandle(process_info.hThread); // thread handle is not used
|
2005-12-02 22:29:35 +00:00
|
|
|
#elif defined(__EMX__)
|
|
|
|
|
2007-09-21 15:07:15 +00:00
|
|
|
char* argv[100];
|
|
|
|
char current_dir[_MAX_PATH];
|
2005-12-02 22:29:35 +00:00
|
|
|
|
2013-06-21 22:41:48 +00:00
|
|
|
// Set up client/app shared memory seg if needed
|
2005-12-02 22:29:35 +00:00
|
|
|
//
|
|
|
|
if (!app_client_shm.shm) {
|
|
|
|
retval = create_shmem(
|
|
|
|
shmem_seg_name, sizeof(SHARED_MEM), (void**)&app_client_shm.shm
|
|
|
|
);
|
|
|
|
if (retval) {
|
2007-06-25 11:46:15 +00:00
|
|
|
return retval;
|
2005-12-02 22:29:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
app_client_shm.reset_msgs();
|
|
|
|
|
2007-09-21 15:07:15 +00:00
|
|
|
// save current dir
|
2008-07-10 21:57:18 +00:00
|
|
|
getcwd(current_dir, sizeof(current_dir));
|
2007-09-21 15:07:15 +00:00
|
|
|
|
|
|
|
// chdir() into the slot directory
|
|
|
|
//
|
|
|
|
retval = chdir(slot_dir);
|
|
|
|
if (retval) {
|
2012-10-31 19:44:18 +00:00
|
|
|
sprintf(buf, "Can't change directory to %s: %s", slot_dir, boincerror(retval));
|
2007-09-21 15:07:15 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hook up stderr to a specially-named file
|
|
|
|
//
|
|
|
|
//freopen(STDERR_FILE, "a", stderr);
|
|
|
|
|
|
|
|
argv[0] = exec_name;
|
|
|
|
char cmdline[8192];
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(cmdline, wup->command_line.c_str());
|
2008-03-27 18:25:29 +00:00
|
|
|
if (strlen(result->cmdline)) {
|
|
|
|
strcat(cmdline, " ");
|
|
|
|
strcat(cmdline, result->cmdline);
|
|
|
|
}
|
2007-09-21 15:07:15 +00:00
|
|
|
parse_command_line(cmdline, argv+1);
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.task_debug) {
|
|
|
|
debug_print_argv(argv);
|
|
|
|
}
|
2007-09-21 15:07:15 +00:00
|
|
|
sprintf(buf, "../../%s", exec_path );
|
|
|
|
pid = spawnv(P_NOWAIT, buf, argv);
|
|
|
|
if (pid == -1) {
|
2012-10-31 19:44:18 +00:00
|
|
|
sprintf(buf, "Process creation failed: %s\n", boincerror(retval));
|
2007-09-21 15:07:15 +00:00
|
|
|
chdir(current_dir);
|
2006-06-20 19:34:42 +00:00
|
|
|
retval = ERR_EXEC;
|
|
|
|
goto error;
|
2007-09-21 15:07:15 +00:00
|
|
|
}
|
2005-12-02 22:29:35 +00:00
|
|
|
|
2007-09-21 15:07:15 +00:00
|
|
|
// restore current dir
|
|
|
|
chdir(current_dir);
|
2006-06-22 19:40:30 +00:00
|
|
|
|
|
|
|
if (log_flags.task_debug) {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(wup->project, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[task] ACTIVE_TASK::start(): forked process: pid %d\n", pid
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2005-12-02 22:29:35 +00:00
|
|
|
|
2014-05-08 07:51:18 +00:00
|
|
|
if (!cc_config.no_priority_change) {
|
2009-03-20 18:56:54 +00:00
|
|
|
if (setpriority(PRIO_PROCESS, pid,
|
|
|
|
high_priority?PROCESS_MEDIUM_PRIORITY:PROCESS_IDLE_PRIORITY)
|
|
|
|
) {
|
|
|
|
perror("setpriority");
|
|
|
|
}
|
2005-12-02 22:29:35 +00:00
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
#else
|
2006-11-10 17:55:22 +00:00
|
|
|
// Unix/Linux/Mac case
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
char* argv[100];
|
2008-07-10 21:57:18 +00:00
|
|
|
char current_dir[1024];
|
|
|
|
|
2013-07-09 17:34:32 +00:00
|
|
|
if (getcwd(current_dir, sizeof(current_dir)) == NULL) {
|
|
|
|
sprintf(buf, "Can't get cwd");
|
|
|
|
goto error;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2009-08-13 16:24:21 +00:00
|
|
|
sprintf(cmdline, "%s %s",
|
|
|
|
wup->command_line.c_str(), app_version->cmdline
|
|
|
|
);
|
2011-03-25 09:51:39 +00:00
|
|
|
|
2014-07-30 20:16:42 +00:00
|
|
|
if (!app_version->api_version_at_least(7, 5)) {
|
|
|
|
int rt = app_version->gpu_usage.rsc_type;
|
|
|
|
if (rt) {
|
|
|
|
coproc_cmdline(rt, result, app_version->gpu_usage.usage, cmdline);
|
|
|
|
}
|
2009-08-17 16:50:40 +00:00
|
|
|
}
|
2009-08-13 16:24:21 +00:00
|
|
|
|
2013-06-21 22:41:48 +00:00
|
|
|
// Set up client/app shared memory seg if needed
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2004-08-31 21:02:17 +00:00
|
|
|
if (!app_client_shm.shm) {
|
2013-06-21 22:41:48 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
if (true) {
|
|
|
|
#else
|
2014-07-30 20:16:42 +00:00
|
|
|
if (app_version->api_version_at_least(6, 0)) {
|
2013-06-21 22:41:48 +00:00
|
|
|
#endif
|
2007-09-26 10:16:04 +00:00
|
|
|
// Use mmap() shared memory
|
|
|
|
sprintf(buf, "%s/%s", slot_dir, MMAPPED_FILE_NAME);
|
|
|
|
if (g_use_sandbox) {
|
|
|
|
if (!boinc_file_exists(buf)) {
|
|
|
|
int fd = open(buf, O_RDWR | O_CREAT, 0660);
|
|
|
|
if (fd >= 0) {
|
|
|
|
close (fd);
|
2014-07-27 17:19:11 +00:00
|
|
|
if (g_use_sandbox) set_to_project_group(buf);
|
2007-09-26 10:16:04 +00:00
|
|
|
}
|
2007-08-28 06:12:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-26 10:16:04 +00:00
|
|
|
retval = create_shmem_mmap(
|
|
|
|
buf, sizeof(SHARED_MEM), (void**)&app_client_shm.shm
|
|
|
|
);
|
2011-10-07 20:05:54 +00:00
|
|
|
if (retval) {
|
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
|
|
|
"ACTIVE_TASK::start(): can't create memory-mapped file: %s",
|
|
|
|
boincerror(retval)
|
|
|
|
);
|
|
|
|
return retval;
|
|
|
|
}
|
2007-09-26 10:16:04 +00:00
|
|
|
} else {
|
|
|
|
// Use shmget() shared memory
|
|
|
|
retval = create_shmem(
|
|
|
|
shmem_seg_name, sizeof(SHARED_MEM), gstate.boinc_project_gid,
|
|
|
|
(void**)&app_client_shm.shm
|
|
|
|
);
|
|
|
|
|
|
|
|
if (retval) {
|
|
|
|
needs_shmem = true;
|
2008-01-13 00:12:14 +00:00
|
|
|
destroy_shmem(shmem_seg_name);
|
2007-09-26 10:16:04 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2004-08-31 21:02:17 +00:00
|
|
|
}
|
2007-06-25 11:46:15 +00:00
|
|
|
needs_shmem = false;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
app_client_shm.reset_msgs();
|
|
|
|
|
2007-10-24 00:44:42 +00:00
|
|
|
#if (defined (__APPLE__) && (defined(__i386__) || defined(__x86_64__)))
|
2006-02-06 23:44:05 +00:00
|
|
|
// PowerPC apps emulated on i386 Macs crash if running graphics
|
|
|
|
powerpc_emulated_on_i386 = ! is_native_i386_app(exec_path);
|
|
|
|
#endif
|
2014-05-08 07:51:18 +00:00
|
|
|
if (cc_config.run_apps_manually) {
|
2008-01-13 00:12:14 +00:00
|
|
|
pid = getpid(); // use the client's PID
|
|
|
|
set_task_state(PROCESS_EXECUTING, "start");
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
pid = fork();
|
|
|
|
if (pid == -1) {
|
2006-06-20 19:34:42 +00:00
|
|
|
sprintf(buf, "fork() failed: %s", strerror(errno));
|
|
|
|
retval = ERR_FORK;
|
|
|
|
goto error;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
if (pid == 0) {
|
|
|
|
// from here on we're running in a new process.
|
2006-10-11 16:32:59 +00:00
|
|
|
// If an error happens,
|
2012-06-26 20:30:56 +00:00
|
|
|
// exit nonzero so that the client knows there was a problem.
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2008-05-09 17:05:26 +00:00
|
|
|
// don't pass stdout to the app
|
2008-05-09 16:27:20 +00:00
|
|
|
//
|
2008-05-09 17:05:26 +00:00
|
|
|
int fd = open("/dev/null", O_RDWR);
|
2008-05-13 21:46:50 +00:00
|
|
|
dup2(fd, STDOUT_FILENO);
|
2008-05-09 17:05:26 +00:00
|
|
|
close(fd);
|
2008-05-09 16:27:20 +00:00
|
|
|
|
2009-06-16 20:24:36 +00:00
|
|
|
// prepend to library path:
|
2008-08-01 22:50:07 +00:00
|
|
|
// - the project dir (../../projects/X)
|
|
|
|
// - the slot dir (.)
|
|
|
|
// - the BOINC dir (../..)
|
2010-01-09 16:41:17 +00:00
|
|
|
// (Mac) /usr/local/cuda/lib/
|
2008-08-01 22:50:07 +00:00
|
|
|
// We use relative paths in case higher-level dirs
|
|
|
|
// are not readable to the account under which app runs
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2006-10-11 16:32:59 +00:00
|
|
|
char libpath[8192];
|
2010-01-09 16:41:17 +00:00
|
|
|
char newlibs[256];
|
2013-04-18 20:57:33 +00:00
|
|
|
sprintf(newlibs, "../../%s:.:../..", wup->project->project_dir());
|
2010-01-09 16:41:17 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
strcat(newlibs, ":/usr/local/cuda/lib/");
|
|
|
|
#endif
|
2008-08-28 18:41:18 +00:00
|
|
|
char* p = getenv("LD_LIBRARY_PATH");
|
|
|
|
if (p) {
|
2010-01-09 16:41:17 +00:00
|
|
|
sprintf(libpath, "%s:%s", newlibs, p);
|
2008-08-28 18:41:18 +00:00
|
|
|
} else {
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(libpath, newlibs);
|
2008-08-28 18:41:18 +00:00
|
|
|
}
|
2006-10-11 16:32:59 +00:00
|
|
|
setenv("LD_LIBRARY_PATH", libpath, 1);
|
|
|
|
|
2009-12-18 17:49:38 +00:00
|
|
|
// On the Mac, do the same for DYLD_LIBRARY_PATH
|
2009-06-16 20:24:36 +00:00
|
|
|
//
|
|
|
|
#ifdef __APPLE__
|
2009-12-18 17:49:38 +00:00
|
|
|
p = getenv("DYLD_LIBRARY_PATH");
|
2009-06-16 20:24:36 +00:00
|
|
|
if (p) {
|
2010-01-09 16:41:17 +00:00
|
|
|
sprintf(libpath, "%s:%s", newlibs, p);
|
2009-06-16 20:24:36 +00:00
|
|
|
} else {
|
2013-06-04 03:24:48 +00:00
|
|
|
safe_strcpy(libpath, newlibs);
|
2009-06-16 20:24:36 +00:00
|
|
|
}
|
2009-12-18 17:49:38 +00:00
|
|
|
setenv("DYLD_LIBRARY_PATH", libpath, 1);
|
2009-06-16 20:24:36 +00:00
|
|
|
#endif
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
retval = chdir(slot_dir);
|
|
|
|
if (retval) {
|
|
|
|
perror("chdir");
|
2005-10-05 20:39:00 +00:00
|
|
|
fflush(NULL);
|
2007-04-05 23:15:20 +00:00
|
|
|
_exit(errno);
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
|
2007-02-02 17:12:07 +00:00
|
|
|
#if 0
|
2007-01-29 22:57:10 +00:00
|
|
|
// set stack size limit to the max.
|
|
|
|
// Some BOINC apps have reported problems with exceeding
|
|
|
|
// small stack limits (e.g. 8 MB)
|
|
|
|
// and it seems like the best thing to raise it as high as possible
|
|
|
|
//
|
|
|
|
struct rlimit rlim;
|
2007-01-31 21:55:12 +00:00
|
|
|
#define MIN_STACK_LIMIT 64000000
|
2007-01-29 22:57:10 +00:00
|
|
|
getrlimit(RLIMIT_STACK, &rlim);
|
2007-01-31 21:55:12 +00:00
|
|
|
if (rlim.rlim_cur != RLIM_INFINITY && rlim.rlim_cur <= MIN_STACK_LIMIT) {
|
|
|
|
if (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_max > MIN_STACK_LIMIT) {
|
|
|
|
rlim.rlim_cur = MIN_STACK_LIMIT;
|
|
|
|
} else {
|
|
|
|
rlim.rlim_cur = rlim.rlim_max;
|
|
|
|
}
|
|
|
|
setrlimit(RLIMIT_STACK, &rlim);
|
2007-01-30 18:31:07 +00:00
|
|
|
}
|
2007-02-02 17:12:07 +00:00
|
|
|
#endif
|
2007-01-29 22:57:10 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
// hook up stderr to a specially-named file
|
|
|
|
//
|
2013-07-09 17:34:32 +00:00
|
|
|
(void) freopen(STDERR_FILE, "a", stderr);
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2014-02-07 19:35:34 +00:00
|
|
|
// lower our priority if needed
|
|
|
|
//
|
2014-05-08 07:51:18 +00:00
|
|
|
if (!cc_config.no_priority_change) {
|
2011-09-27 19:45:27 +00:00
|
|
|
#if HAVE_SETPRIORITY
|
2009-03-20 18:56:54 +00:00
|
|
|
if (setpriority(PRIO_PROCESS, 0,
|
|
|
|
high_priority?PROCESS_MEDIUM_PRIORITY:PROCESS_IDLE_PRIORITY)
|
|
|
|
) {
|
|
|
|
perror("setpriority");
|
|
|
|
}
|
2006-04-14 17:55:02 +00:00
|
|
|
#endif
|
2014-02-07 19:35:34 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
// Android has its own notion of background scheduling
|
|
|
|
if (!high_priority) {
|
|
|
|
FILE* f = fopen("/dev/cpuctl/apps/bg_non_interactive/tasks", "w");
|
|
|
|
if (!f) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "Can't open /dev/cpuctl/apps/bg_non_interactive/tasks");
|
|
|
|
} else {
|
|
|
|
fprintf(f, "%d", getpid());
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-09-27 19:45:27 +00:00
|
|
|
#if HAVE_SCHED_SETSCHEDULER && defined(SCHED_BATCH) && defined (__linux__)
|
2009-09-23 16:51:40 +00:00
|
|
|
if (!high_priority) {
|
2011-06-12 20:58:43 +00:00
|
|
|
struct sched_param sp;
|
|
|
|
sp.sched_priority = 0;
|
|
|
|
if (sched_setscheduler(0, SCHED_BATCH, &sp)) {
|
2009-09-23 16:51:40 +00:00
|
|
|
perror("sched_setscheduler");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2014-02-07 19:35:34 +00:00
|
|
|
|
|
|
|
// Run the application program.
|
|
|
|
// If using account-based sandboxing, use a helper app
|
|
|
|
// to do this, to set the right user ID
|
|
|
|
//
|
2013-07-04 23:00:10 +00:00
|
|
|
if (test) {
|
|
|
|
strcpy(buf, exec_path);
|
|
|
|
} else {
|
|
|
|
sprintf(buf, "../../%s", exec_path);
|
|
|
|
}
|
2006-08-01 12:36:19 +00:00
|
|
|
if (g_use_sandbox) {
|
2012-05-09 16:11:50 +00:00
|
|
|
char switcher_path[MAXPATHLEN];
|
2009-07-28 19:19:14 +00:00
|
|
|
sprintf(switcher_path, "../../%s/%s",
|
|
|
|
SWITCHER_DIR, SWITCHER_FILE_NAME
|
|
|
|
);
|
2011-06-26 00:10:19 +00:00
|
|
|
argv[0] = const_cast<char*>(SWITCHER_FILE_NAME);
|
2006-08-01 12:36:19 +00:00
|
|
|
argv[1] = buf;
|
|
|
|
argv[2] = exec_name;
|
|
|
|
parse_command_line(cmdline, argv+3);
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
debug_print_argv(argv);
|
|
|
|
}
|
2009-07-28 19:19:14 +00:00
|
|
|
// Files written by projects have user boinc_project
|
2011-09-27 19:45:27 +00:00
|
|
|
// and group boinc_project,
|
|
|
|
// so they must be world-readable so BOINC CLient can read them
|
2009-07-28 19:19:14 +00:00
|
|
|
//
|
2008-01-18 02:08:25 +00:00
|
|
|
umask(2);
|
2006-08-01 12:36:19 +00:00
|
|
|
retval = execv(switcher_path, argv);
|
|
|
|
} else {
|
2009-07-28 19:19:14 +00:00
|
|
|
argv[0] = buf;
|
2006-08-01 12:36:19 +00:00
|
|
|
parse_command_line(cmdline, argv+1);
|
|
|
|
retval = execv(buf, argv);
|
2006-06-23 20:05:12 +00:00
|
|
|
}
|
2013-07-04 23:00:10 +00:00
|
|
|
fprintf(stderr,
|
2009-07-28 19:19:14 +00:00
|
|
|
"Process creation (%s) failed: %s, errno=%d\n",
|
|
|
|
buf, boincerror(retval), errno
|
2004-08-11 11:30:25 +00:00
|
|
|
);
|
|
|
|
perror("execv");
|
2005-10-05 20:39:00 +00:00
|
|
|
fflush(NULL);
|
2004-08-11 11:30:25 +00:00
|
|
|
_exit(errno);
|
|
|
|
}
|
|
|
|
|
2014-02-07 19:35:34 +00:00
|
|
|
// parent process (client) continues here
|
|
|
|
//
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.task_debug) {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(wup->project, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[task] ACTIVE_TASK::start(): forked process: pid %d\n", pid
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2014-02-07 19:35:34 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
#endif
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
#endif
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_EXECUTING, "start");
|
2004-08-11 11:30:25 +00:00
|
|
|
return 0;
|
2006-06-20 19:34:42 +00:00
|
|
|
|
|
|
|
// go here on error; "buf" contains error message, "retval" is nonzero
|
|
|
|
//
|
|
|
|
error:
|
2013-07-04 23:00:10 +00:00
|
|
|
if (test) {
|
|
|
|
return retval;
|
|
|
|
}
|
2008-07-21 19:56:01 +00:00
|
|
|
|
2007-09-21 15:07:15 +00:00
|
|
|
// if something failed, it's possible that the executable was munged.
|
|
|
|
// Verify it to trigger another download.
|
|
|
|
//
|
|
|
|
gstate.input_files_available(result, true);
|
2012-10-31 19:44:18 +00:00
|
|
|
gstate.report_result_error(*result, "couldn't start app: %s", buf);
|
2009-10-07 18:42:51 +00:00
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(wup->project, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[task] couldn't start app: %s", buf
|
2009-10-07 18:42:51 +00:00
|
|
|
);
|
|
|
|
}
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_COULDNT_START, "start");
|
2006-06-20 19:34:42 +00:00
|
|
|
return retval;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
|
2004-10-07 19:18:37 +00:00
|
|
|
// Resume the task if it was previously running; otherwise start it
|
|
|
|
// Postcondition: "state" is set correctly
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2007-02-02 17:12:07 +00:00
|
|
|
int ACTIVE_TASK::resume_or_start(bool first_time) {
|
2005-02-18 23:50:38 +00:00
|
|
|
const char* str = "??";
|
2004-08-11 11:30:25 +00:00
|
|
|
int retval;
|
|
|
|
|
2007-01-24 21:20:57 +00:00
|
|
|
switch (task_state()) {
|
2004-08-23 22:06:48 +00:00
|
|
|
case PROCESS_UNINITIALIZED:
|
2012-02-08 21:14:34 +00:00
|
|
|
str = (first_time)?"Starting":"Restarting";
|
|
|
|
retval = start();
|
2007-06-25 11:46:15 +00:00
|
|
|
if ((retval == ERR_SHMGET) || (retval == ERR_SHMAT)) {
|
|
|
|
return retval;
|
|
|
|
}
|
2004-10-07 19:18:37 +00:00
|
|
|
if (retval) {
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_COULDNT_START, "resume_or_start1");
|
2004-10-07 19:18:37 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2004-08-23 22:06:48 +00:00
|
|
|
break;
|
|
|
|
case PROCESS_SUSPENDED:
|
2004-08-11 11:30:25 +00:00
|
|
|
retval = unsuspend();
|
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Couldn't resume task %s", result->name
|
2004-08-11 11:30:25 +00:00
|
|
|
);
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_COULDNT_START, "resume_or_start2");
|
2004-08-11 11:30:25 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2004-08-24 17:58:51 +00:00
|
|
|
str = "Resuming";
|
2004-08-23 22:06:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(result->project, MSG_INTERNAL_ERROR,
|
2007-01-24 21:20:57 +00:00
|
|
|
"Unexpected state %d for task %s", task_state(), result->name
|
2004-08-23 22:06:48 +00:00
|
|
|
);
|
|
|
|
return 0;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2014-01-23 01:26:26 +00:00
|
|
|
if (log_flags.task && first_time) {
|
2014-05-02 04:03:49 +00:00
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"Starting task %s", result->name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (log_flags.cpu_sched) {
|
2011-10-15 20:28:26 +00:00
|
|
|
char buf[256];
|
|
|
|
strcpy(buf, "");
|
|
|
|
if (strlen(app_version->plan_class)) {
|
|
|
|
sprintf(buf, " (%s)", app_version->plan_class);
|
|
|
|
}
|
2006-05-21 22:03:36 +00:00
|
|
|
msg_printf(result->project, MSG_INFO,
|
2014-01-23 01:26:26 +00:00
|
|
|
"[cpu_sched] %s task %s using %s version %d%s in slot %d",
|
2006-05-21 22:03:36 +00:00
|
|
|
str,
|
|
|
|
result->name,
|
|
|
|
app_version->app->name,
|
2011-10-15 20:28:26 +00:00
|
|
|
app_version->version_num,
|
2012-02-03 22:08:11 +00:00
|
|
|
buf,
|
|
|
|
slot
|
2006-05-21 22:03:36 +00:00
|
|
|
);
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-24 00:44:42 +00:00
|
|
|
#if (defined (__APPLE__) && (defined(__i386__) || defined(__x86_64__)))
|
2006-02-06 23:44:05 +00:00
|
|
|
|
|
|
|
union headeru {
|
|
|
|
fat_header fat;
|
|
|
|
mach_header mach;
|
|
|
|
};
|
|
|
|
|
2007-06-29 15:45:15 +00:00
|
|
|
// Read the mach-o headers to determine the architectures
|
|
|
|
// supported by executable file.
|
2013-07-04 23:00:10 +00:00
|
|
|
// Returns 1 if application can run natively on i386 / x86_64 Macs,
|
|
|
|
// else returns 0.
|
2007-06-29 15:45:15 +00:00
|
|
|
//
|
2006-02-06 23:44:05 +00:00
|
|
|
int ACTIVE_TASK::is_native_i386_app(char* exec_path) {
|
|
|
|
FILE *f;
|
2013-07-29 08:31:09 +00:00
|
|
|
int retval = 0;
|
2006-02-06 23:44:05 +00:00
|
|
|
|
|
|
|
headeru myHeader;
|
|
|
|
fat_arch fatHeader;
|
|
|
|
|
|
|
|
uint32_t n, i, len;
|
2008-02-20 12:04:56 +00:00
|
|
|
uint32_t theMagic;
|
|
|
|
integer_t theType;
|
2006-02-06 23:44:05 +00:00
|
|
|
|
|
|
|
f = boinc_fopen(exec_path, "rb");
|
2007-06-29 15:45:15 +00:00
|
|
|
if (!f) {
|
2013-07-29 08:31:09 +00:00
|
|
|
return retval; // Should never happen
|
2007-06-29 15:45:15 +00:00
|
|
|
}
|
2006-02-06 23:44:05 +00:00
|
|
|
|
|
|
|
myHeader.fat.magic = 0;
|
|
|
|
myHeader.fat.nfat_arch = 0;
|
|
|
|
|
|
|
|
fread(&myHeader, 1, sizeof(fat_header), f);
|
2008-02-20 12:04:56 +00:00
|
|
|
theMagic = myHeader.mach.magic;
|
|
|
|
switch (theMagic) {
|
|
|
|
case MH_CIGAM:
|
2006-02-06 23:44:05 +00:00
|
|
|
case MH_MAGIC:
|
2008-02-20 12:04:56 +00:00
|
|
|
case MH_MAGIC_64:
|
|
|
|
case MH_CIGAM_64:
|
|
|
|
theType = myHeader.mach.cputype;
|
|
|
|
if ((theMagic == MH_CIGAM) || (theMagic == MH_CIGAM_64)) {
|
|
|
|
theType = OSSwapInt32(theType);
|
|
|
|
}
|
|
|
|
if ((theType == CPU_TYPE_I386) || (theType == CPU_TYPE_X86_64)) {
|
2013-07-29 08:31:09 +00:00
|
|
|
retval = 1; // Single-architecture i386or x86_64 file
|
2007-06-29 15:45:15 +00:00
|
|
|
}
|
2006-02-06 23:44:05 +00:00
|
|
|
break;
|
2008-02-20 12:04:56 +00:00
|
|
|
case FAT_MAGIC:
|
2006-02-06 23:44:05 +00:00
|
|
|
case FAT_CIGAM:
|
2008-02-20 12:04:56 +00:00
|
|
|
n = myHeader.fat.nfat_arch;
|
|
|
|
if (theMagic == FAT_CIGAM) {
|
|
|
|
n = OSSwapInt32(myHeader.fat.nfat_arch);
|
|
|
|
}
|
2007-06-29 15:45:15 +00:00
|
|
|
// Multiple architecture (fat) file
|
2006-02-06 23:44:05 +00:00
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
len = fread(&fatHeader, 1, sizeof(fat_arch), f);
|
2007-06-29 15:45:15 +00:00
|
|
|
if (len < sizeof(fat_arch)) {
|
2006-02-06 23:44:05 +00:00
|
|
|
break; // Should never happen
|
2007-06-29 15:45:15 +00:00
|
|
|
}
|
2008-02-20 12:04:56 +00:00
|
|
|
theType = fatHeader.cputype;
|
|
|
|
if (theMagic == FAT_CIGAM) {
|
|
|
|
theType = OSSwapInt32(theType);
|
|
|
|
}
|
|
|
|
if ((theType == CPU_TYPE_I386) || (theType == CPU_TYPE_X86_64)) {
|
2013-07-29 08:31:09 +00:00
|
|
|
retval = 1;
|
2006-02-06 23:44:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (f);
|
2013-07-29 08:31:09 +00:00
|
|
|
return retval;
|
2006-02-06 23:44:05 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-07-04 23:00:10 +00:00
|
|
|
|
|
|
|
// The following runs "test_app" and sends it various messages.
|
|
|
|
// Used for testing the runtime system.
|
|
|
|
//
|
|
|
|
void run_test_app() {
|
|
|
|
WORKUNIT wu;
|
|
|
|
PROJECT project;
|
|
|
|
APP app;
|
|
|
|
APP_VERSION av;
|
|
|
|
ACTIVE_TASK at;
|
|
|
|
ACTIVE_TASK_SET ats;
|
|
|
|
RESULT result;
|
2013-07-17 04:40:13 +00:00
|
|
|
int retval;
|
2013-07-04 23:00:10 +00:00
|
|
|
|
2013-07-10 00:44:03 +00:00
|
|
|
char buf[256];
|
2013-07-10 07:05:27 +00:00
|
|
|
getcwd(buf, sizeof(buf)); // so we can see where we're running
|
2013-07-10 00:44:03 +00:00
|
|
|
|
2013-07-04 23:00:10 +00:00
|
|
|
gstate.run_test_app = true;
|
|
|
|
|
|
|
|
wu.project = &project;
|
|
|
|
wu.app = &app;
|
|
|
|
wu.command_line = string("--critical_section");
|
|
|
|
|
|
|
|
strcpy(app.name, "test app");
|
|
|
|
av.init();
|
|
|
|
av.avg_ncpus = 1;
|
|
|
|
|
|
|
|
strcpy(result.name, "test result");
|
|
|
|
result.avp = &av;
|
|
|
|
result.wup = &wu;
|
|
|
|
result.project = &project;
|
|
|
|
result.app = &app;
|
|
|
|
|
|
|
|
at.result = &result;
|
|
|
|
at.wup = &wu;
|
|
|
|
at.app_version = &av;
|
|
|
|
at.max_elapsed_time = 1e6;
|
|
|
|
at.max_disk_usage = 1e14;
|
|
|
|
at.max_mem_usage = 1e14;
|
|
|
|
strcpy(at.slot_dir, ".");
|
|
|
|
|
2013-07-17 04:40:13 +00:00
|
|
|
#if 1
|
|
|
|
// test file copy
|
|
|
|
//
|
|
|
|
ASYNC_COPY* ac = new ASYNC_COPY;
|
|
|
|
FILE_INFO fi;
|
|
|
|
retval = ac->init(&at, &fi, "big_file", "./big_file_copy");
|
|
|
|
if (retval) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
while (1) {
|
|
|
|
do_async_file_ops();
|
|
|
|
if (at.async_copy == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "done\n");
|
|
|
|
exit(0);
|
|
|
|
#endif
|
2013-07-04 23:00:10 +00:00
|
|
|
ats.active_tasks.push_back(&at);
|
|
|
|
|
|
|
|
unlink("boinc_finish_called");
|
|
|
|
unlink("boinc_lockfile");
|
|
|
|
unlink("boinc_temporary_exit");
|
|
|
|
unlink("stderr.txt");
|
2013-07-17 04:40:13 +00:00
|
|
|
retval = at.start(true);
|
2013-07-04 23:00:10 +00:00
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "start() failed: %s\n", boincerror(retval));
|
|
|
|
}
|
|
|
|
while (1) {
|
|
|
|
gstate.now = dtime();
|
|
|
|
at.preempt(REMOVE_NEVER);
|
|
|
|
ats.poll();
|
2013-07-05 21:18:45 +00:00
|
|
|
boinc_sleep(.1);
|
2013-07-04 23:00:10 +00:00
|
|
|
at.unsuspend();
|
|
|
|
ats.poll();
|
2013-07-05 21:18:45 +00:00
|
|
|
boinc_sleep(.2);
|
2013-07-10 00:44:03 +00:00
|
|
|
//at.request_reread_prefs();
|
2013-07-04 23:00:10 +00:00
|
|
|
}
|
|
|
|
}
|