2005-04-13 22:52:05 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
|
|
|
//
|
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
#include "cpp.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
2006-02-18 08:33:23 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2005-04-13 22:52:05 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <csignal>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <ctime>
|
|
|
|
#include <cstdarg>
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstring>
|
2006-02-18 15:07:38 +00:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
2005-04-13 22:52:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "parse.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2005-04-13 22:52:05 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "filesys.h"
|
|
|
|
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "hostinfo.h"
|
|
|
|
#include "hostinfo_network.h"
|
|
|
|
#include "network.h"
|
2005-08-09 22:01:28 +00:00
|
|
|
#include "http_curl.h"
|
2005-04-13 22:52:05 +00:00
|
|
|
#include "client_msgs.h"
|
2007-06-25 11:46:15 +00:00
|
|
|
#include "shmem.h"
|
2007-10-05 16:47:07 +00:00
|
|
|
#include "sandbox.h"
|
2005-04-13 22:52:05 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
|
|
|
|
using std::max;
|
|
|
|
|
|
|
|
CLIENT_STATE gstate;
|
|
|
|
|
2007-09-27 21:28:32 +00:00
|
|
|
CLIENT_STATE::CLIENT_STATE():
|
|
|
|
lookup_website_op(&gui_http),
|
|
|
|
get_current_version_op(&gui_http),
|
|
|
|
get_project_list_op(&gui_http)
|
|
|
|
{
|
2006-06-28 16:56:15 +00:00
|
|
|
http_ops = new HTTP_OP_SET();
|
2005-04-13 22:52:05 +00:00
|
|
|
file_xfers = new FILE_XFER_SET(http_ops);
|
|
|
|
pers_file_xfers = new PERS_FILE_XFER_SET(file_xfers);
|
|
|
|
scheduler_op = new SCHEDULER_OP(http_ops);
|
|
|
|
client_state_dirty = false;
|
|
|
|
exit_when_idle = false;
|
2007-05-29 21:45:01 +00:00
|
|
|
exit_before_start = false;
|
|
|
|
exit_after_finish = false;
|
2005-04-13 22:52:05 +00:00
|
|
|
check_all_logins = false;
|
|
|
|
allow_remote_gui_rpc = false;
|
2005-12-13 08:04:57 +00:00
|
|
|
cmdline_gui_rpc_port = 0;
|
2005-04-13 22:52:05 +00:00
|
|
|
run_cpu_benchmarks = false;
|
|
|
|
skip_cpu_benchmarks = false;
|
|
|
|
file_xfer_giveup_period = PERS_GIVEUP;
|
|
|
|
contacted_sched_server = false;
|
2005-12-24 06:32:07 +00:00
|
|
|
tasks_suspended = false;
|
2005-04-13 22:52:05 +00:00
|
|
|
network_suspended = false;
|
2006-08-07 03:56:34 +00:00
|
|
|
suspend_reason = 0;
|
|
|
|
network_suspend_reason = 0;
|
2006-12-14 00:42:43 +00:00
|
|
|
core_client_version.major = BOINC_MAJOR_VERSION;
|
|
|
|
core_client_version.minor = BOINC_MINOR_VERSION;
|
|
|
|
core_client_version.release = BOINC_RELEASE;
|
2008-04-17 16:18:16 +00:00
|
|
|
core_client_version.prerelease = BOINC_PRERELEASE;
|
2005-04-13 22:52:05 +00:00
|
|
|
exit_after_app_start_secs = 0;
|
|
|
|
app_started = 0;
|
|
|
|
exit_before_upload = false;
|
|
|
|
proxy_info.clear();
|
|
|
|
show_projects = false;
|
|
|
|
strcpy(detach_project_url, "");
|
|
|
|
strcpy(main_host_venue, "");
|
|
|
|
strcpy(attach_project_url, "");
|
|
|
|
strcpy(attach_project_auth, "");
|
2006-11-10 17:55:22 +00:00
|
|
|
run_mode.set(RUN_MODE_AUTO, 0);
|
|
|
|
network_mode.set(RUN_MODE_AUTO, 0);
|
2005-04-13 22:52:05 +00:00
|
|
|
started_by_screensaver = false;
|
|
|
|
requested_exit = false;
|
|
|
|
master_fetch_period = MASTER_FETCH_PERIOD;
|
|
|
|
retry_cap = RETRY_CAP;
|
|
|
|
master_fetch_retry_cap = MASTER_FETCH_RETRY_CAP;
|
|
|
|
master_fetch_interval = MASTER_FETCH_INTERVAL;
|
|
|
|
sched_retry_delay_min = SCHED_RETRY_DELAY_MIN;
|
|
|
|
sched_retry_delay_max = SCHED_RETRY_DELAY_MAX;
|
|
|
|
pers_retry_delay_min = PERS_RETRY_DELAY_MIN;
|
|
|
|
pers_retry_delay_max = PERS_RETRY_DELAY_MAX;
|
|
|
|
pers_giveup = PERS_GIVEUP;
|
2005-04-13 23:28:47 +00:00
|
|
|
executing_as_daemon = false;
|
2005-04-13 22:52:05 +00:00
|
|
|
redirect_io = false;
|
2006-03-16 20:29:44 +00:00
|
|
|
disable_graphics = false;
|
2005-04-13 22:52:05 +00:00
|
|
|
work_fetch_no_new_work = false;
|
2007-07-16 20:30:21 +00:00
|
|
|
cant_write_state_file = false;
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2006-08-22 20:58:57 +00:00
|
|
|
debt_interval_start = 0;
|
|
|
|
total_wall_cpu_time_this_debt_interval = 0;
|
2007-06-25 11:46:15 +00:00
|
|
|
retry_shmem_time = 0;
|
2005-04-13 22:52:05 +00:00
|
|
|
must_schedule_cpus = true;
|
2006-06-15 23:15:27 +00:00
|
|
|
must_enforce_cpu_schedule = true;
|
2005-07-23 08:10:39 +00:00
|
|
|
no_gui_rpc = false;
|
2005-11-10 06:03:39 +00:00
|
|
|
new_version_check_time = 0;
|
2007-03-19 19:13:40 +00:00
|
|
|
all_projects_list_check_time = 0;
|
2005-12-01 08:07:07 +00:00
|
|
|
detach_console = false;
|
2006-08-01 12:36:19 +00:00
|
|
|
#ifdef SANDBOX
|
|
|
|
g_use_sandbox = true; // User can override with -insecure command-line arg
|
|
|
|
#endif
|
2006-12-13 00:54:27 +00:00
|
|
|
launched_by_manager = false;
|
2006-08-03 16:39:57 +00:00
|
|
|
initialized = false;
|
2007-05-14 21:45:02 +00:00
|
|
|
last_wakeup_time = dtime();
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
|
2005-07-26 11:55:28 +00:00
|
|
|
void CLIENT_STATE::show_host_info() {
|
|
|
|
char buf[256], buf2[256];
|
2005-12-01 08:07:07 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2006-07-01 04:00:19 +00:00
|
|
|
"Processor: %d %s %s",
|
|
|
|
host_info.p_ncpus, host_info.p_vendor, host_info.p_model
|
2005-07-26 11:55:28 +00:00
|
|
|
);
|
2007-04-03 13:14:30 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"Processor features: %s", host_info.p_features
|
|
|
|
);
|
2007-07-16 18:09:54 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"OS: %s: %s", host_info.os_name, host_info.os_version
|
|
|
|
);
|
2005-07-26 11:55:28 +00:00
|
|
|
|
|
|
|
nbytes_to_string(host_info.m_nbytes, 0, buf, sizeof(buf));
|
|
|
|
nbytes_to_string(host_info.m_swap, 0, buf2, sizeof(buf2));
|
2005-12-01 08:07:07 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2005-07-26 11:55:28 +00:00
|
|
|
"Memory: %s physical, %s virtual",
|
|
|
|
buf, buf2
|
|
|
|
);
|
|
|
|
|
|
|
|
nbytes_to_string(host_info.d_total, 0, buf, sizeof(buf));
|
|
|
|
nbytes_to_string(host_info.d_free, 0, buf2, sizeof(buf2));
|
2006-02-18 08:33:23 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Disk: %s total, %s free", buf, buf2);
|
2007-07-14 20:04:47 +00:00
|
|
|
int tz = host_info.timezone/3600;
|
|
|
|
msg_printf(0, MSG_INFO, "Local time is UTC %s%d hours",
|
|
|
|
tz<0?"":"+", tz
|
|
|
|
);
|
2005-07-26 11:55:28 +00:00
|
|
|
}
|
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
int CLIENT_STATE::init() {
|
|
|
|
int retval;
|
|
|
|
unsigned int i;
|
|
|
|
char buf[256];
|
2005-10-23 07:19:03 +00:00
|
|
|
PROJECT* p;
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2005-07-06 09:14:43 +00:00
|
|
|
srand((unsigned int)time(0));
|
2005-06-07 19:22:50 +00:00
|
|
|
now = dtime();
|
2007-12-27 21:40:20 +00:00
|
|
|
client_start_time = now;
|
2005-06-01 06:18:25 +00:00
|
|
|
scheduler_op->url_random = drand();
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2007-05-06 20:22:39 +00:00
|
|
|
detect_platforms();
|
2007-12-02 15:57:08 +00:00
|
|
|
time_stats.start();
|
2007-05-02 17:53:35 +00:00
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
msg_printf(
|
2005-08-31 00:18:36 +00:00
|
|
|
NULL, MSG_INFO, "Starting BOINC client version %d.%d.%d for %s%s",
|
2006-12-14 00:42:43 +00:00
|
|
|
core_client_version.major,
|
|
|
|
core_client_version.minor,
|
|
|
|
core_client_version.release,
|
2007-08-16 17:33:41 +00:00
|
|
|
get_primary_platform(),
|
|
|
|
#ifdef _DEBUG
|
|
|
|
" (DEBUG)"
|
|
|
|
#else
|
|
|
|
""
|
|
|
|
#endif
|
2005-04-13 22:52:05 +00:00
|
|
|
);
|
2007-05-02 17:53:35 +00:00
|
|
|
|
2008-04-17 16:18:16 +00:00
|
|
|
if (core_client_version.prerelease) {
|
2008-05-07 21:46:49 +00:00
|
|
|
msg_printf(NULL, MSG_USER_ERROR,
|
|
|
|
"This a development version of BOINC and may not function properly"
|
|
|
|
);
|
2008-04-17 16:18:16 +00:00
|
|
|
}
|
|
|
|
|
2006-09-07 17:38:54 +00:00
|
|
|
log_flags.show();
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2006-06-23 22:25:08 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Libraries: %s", curl_version());
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
if (executing_as_daemon) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "Executing as a daemon");
|
|
|
|
}
|
|
|
|
|
|
|
|
relative_to_absolute("", buf);
|
|
|
|
msg_printf(NULL, MSG_INFO, "Data directory: %s", buf);
|
|
|
|
|
|
|
|
// if we are running as anybody other than localsystem
|
|
|
|
// and executing as a daemon then app graphics won't work.
|
2006-02-18 08:33:23 +00:00
|
|
|
// display a note at startup reminding user of that.
|
2005-04-13 22:52:05 +00:00
|
|
|
//
|
|
|
|
#ifdef _WIN32
|
|
|
|
DWORD buf_size = sizeof(buf);
|
|
|
|
LPTSTR pbuf = buf;
|
2005-12-01 08:07:07 +00:00
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
GetUserName(pbuf, &buf_size);
|
2007-02-12 23:53:16 +00:00
|
|
|
if (executing_as_daemon && (strcmp("SYSTEM", pbuf))) {
|
2005-04-13 22:52:05 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"BOINC is running as a service and as a non-system user."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-07-18 03:24:49 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
if (executing_as_daemon) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
2006-08-17 21:24:18 +00:00
|
|
|
"BOINC is running as a daemon."
|
|
|
|
);
|
2006-07-18 03:24:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-07-08 07:26:37 +00:00
|
|
|
parse_account_files();
|
2005-04-13 23:28:47 +00:00
|
|
|
parse_statistics_files();
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2005-04-13 23:28:47 +00:00
|
|
|
// check for app_info.xml file in project dirs.
|
|
|
|
// If find, read app info from there, set project.anonymous_platform
|
|
|
|
//
|
|
|
|
check_anonymous();
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
// Parse the client state file,
|
|
|
|
// ignoring any <project> tags (and associated stuff)
|
|
|
|
// for projects with no account file
|
|
|
|
//
|
2005-08-10 00:18:52 +00:00
|
|
|
host_info.clear_host_info();
|
2005-04-13 22:52:05 +00:00
|
|
|
parse_state_file();
|
2006-07-14 21:08:12 +00:00
|
|
|
parse_account_files_venue();
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2005-08-09 20:20:10 +00:00
|
|
|
host_info.get_host_info();
|
|
|
|
set_ncpus();
|
2005-08-10 00:18:52 +00:00
|
|
|
show_host_info();
|
2005-12-01 08:07:07 +00:00
|
|
|
|
2008-03-10 20:40:35 +00:00
|
|
|
coprocs.get();
|
2008-03-28 20:20:10 +00:00
|
|
|
#if 0
|
|
|
|
fake_cuda(coprocs);
|
|
|
|
#endif
|
2008-04-30 19:18:51 +00:00
|
|
|
if (coprocs.coprocs.size() == 0) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "No coprocessors");
|
|
|
|
} else {
|
|
|
|
for (i=0; i<coprocs.coprocs.size(); i++) {
|
|
|
|
COPROC* c = coprocs.coprocs[i];
|
2008-05-09 21:07:15 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Coprocessor: %s (%d)", c->type, c->count);
|
2008-04-30 19:18:51 +00:00
|
|
|
}
|
2008-03-10 20:40:35 +00:00
|
|
|
}
|
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
// Check to see if we can write the state file.
|
|
|
|
//
|
|
|
|
retval = write_state_file();
|
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_USER_ERROR, "Couldn't write state file");
|
|
|
|
msg_printf(NULL, MSG_USER_ERROR,
|
|
|
|
"Make sure directory permissions are set correctly"
|
2005-04-13 22:52:05 +00:00
|
|
|
);
|
2007-07-16 20:30:21 +00:00
|
|
|
cant_write_state_file = true;
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// scan user prefs; create file records
|
|
|
|
//
|
|
|
|
parse_preferences_for_user_files();
|
|
|
|
|
|
|
|
print_summary();
|
|
|
|
do_cmdline_actions();
|
|
|
|
|
2007-02-06 16:41:33 +00:00
|
|
|
// if new version of core client,
|
|
|
|
// - run CPU benchmarks
|
2007-10-02 23:29:28 +00:00
|
|
|
// - contact reference site or some project (to trigger firewall alert)
|
2007-02-06 16:41:33 +00:00
|
|
|
//
|
2006-12-14 00:42:43 +00:00
|
|
|
if ((core_client_version.major != old_major_version)
|
|
|
|
|| (core_client_version.minor != old_minor_version)
|
|
|
|
|| (core_client_version.release != old_release)
|
2005-09-01 19:27:04 +00:00
|
|
|
) {
|
2005-04-13 22:52:05 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2007-02-10 04:13:08 +00:00
|
|
|
"Version change (%d.%d.%d -> %d.%d.%d)",
|
2005-09-01 19:27:04 +00:00
|
|
|
old_major_version, old_minor_version, old_release,
|
2006-12-14 00:42:43 +00:00
|
|
|
core_client_version.major,
|
|
|
|
core_client_version.minor,
|
|
|
|
core_client_version.release
|
2005-04-13 22:52:05 +00:00
|
|
|
);
|
|
|
|
run_cpu_benchmarks = true;
|
2007-10-02 23:29:28 +00:00
|
|
|
if (config.dont_contact_ref_site) {
|
|
|
|
if (projects.size() > 0) {
|
|
|
|
projects[0]->master_url_fetch_pending = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
net_status.need_to_contact_reference_site = true;
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 20:53:46 +00:00
|
|
|
// show host IDs and venues on various projects
|
|
|
|
//
|
2005-04-13 22:52:05 +00:00
|
|
|
for (i=0; i<projects.size(); i++) {
|
2005-10-23 07:19:03 +00:00
|
|
|
p = projects[i];
|
2005-04-13 22:52:05 +00:00
|
|
|
if (p->hostid) {
|
2005-04-22 03:46:01 +00:00
|
|
|
sprintf(buf, "%d", p->hostid);
|
2005-04-13 22:52:05 +00:00
|
|
|
} else {
|
2005-04-22 03:46:01 +00:00
|
|
|
strcpy(buf, "not assigned yet");
|
|
|
|
}
|
2006-01-17 22:48:09 +00:00
|
|
|
msg_printf(p, MSG_INFO,
|
2006-03-07 21:58:14 +00:00
|
|
|
"URL: %s; Computer ID: %s; location: %s; project prefs: %s",
|
|
|
|
p->master_url,
|
2006-07-01 04:00:19 +00:00
|
|
|
buf, strlen(p->host_venue)?p->host_venue:"(none)",
|
2005-05-05 18:35:25 +00:00
|
|
|
p->using_venue_specific_prefs?p->host_venue:"default"
|
2005-04-22 03:46:01 +00:00
|
|
|
);
|
2007-05-24 16:07:21 +00:00
|
|
|
if (p->ended) {
|
|
|
|
msg_printf(p, MSG_INFO, "Project has ended - OK to detach");
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 20:53:46 +00:00
|
|
|
read_global_prefs();
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2006-07-10 00:46:07 +00:00
|
|
|
// do CPU scheduler and work fetch
|
2005-04-13 22:52:05 +00:00
|
|
|
//
|
2006-06-19 04:29:26 +00:00
|
|
|
request_schedule_cpus("Startup");
|
2006-07-10 00:46:07 +00:00
|
|
|
request_work_fetch("Startup");
|
2006-08-22 20:58:57 +00:00
|
|
|
debt_interval_start = now;
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
// set up the project and slot directories
|
|
|
|
//
|
2005-10-10 03:21:52 +00:00
|
|
|
delete_old_slot_dirs();
|
2005-04-13 22:52:05 +00:00
|
|
|
retval = make_project_dirs();
|
|
|
|
if (retval) return retval;
|
|
|
|
|
2006-06-19 04:29:26 +00:00
|
|
|
active_tasks.init();
|
2005-06-07 19:22:50 +00:00
|
|
|
active_tasks.report_overdue();
|
2005-04-28 23:19:58 +00:00
|
|
|
active_tasks.handle_upload_files();
|
2005-04-20 06:16:54 +00:00
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
// Just to be on the safe side; something may have been modified
|
|
|
|
//
|
|
|
|
set_client_state_dirty("init");
|
|
|
|
|
2005-09-22 08:46:51 +00:00
|
|
|
// initialize GUI RPC data structures before we start accepting
|
|
|
|
// GUI RPC's.
|
|
|
|
//
|
|
|
|
acct_mgr_info.init();
|
|
|
|
project_init.init();
|
|
|
|
|
2005-07-23 08:10:39 +00:00
|
|
|
if (!no_gui_rpc) {
|
2006-02-15 22:08:18 +00:00
|
|
|
// When we're running at boot time,
|
|
|
|
// it may be a few seconds before we can socket/bind/listen.
|
|
|
|
// So retry a few times.
|
|
|
|
//
|
|
|
|
for (i=0; i<30; i++) {
|
2007-04-05 18:17:15 +00:00
|
|
|
bool last_time = (i==29);
|
|
|
|
retval = gui_rpcs.init(last_time);
|
2006-02-15 22:08:18 +00:00
|
|
|
if (!retval) break;
|
|
|
|
boinc_sleep(1.0);
|
|
|
|
}
|
2005-07-23 08:10:39 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2007-04-30 21:49:27 +00:00
|
|
|
// If platform name changed, print warning
|
2006-02-18 08:33:23 +00:00
|
|
|
//
|
2007-05-02 17:53:35 +00:00
|
|
|
if (statefile_platform_name.size() && strcmp(get_primary_platform(), statefile_platform_name.c_str())) {
|
2006-02-18 08:33:23 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2007-04-30 21:49:27 +00:00
|
|
|
"Platform changed from %s to %s",
|
2007-05-02 17:53:35 +00:00
|
|
|
statefile_platform_name.c_str(), get_primary_platform()
|
2006-02-18 08:33:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-10-05 16:47:07 +00:00
|
|
|
#ifdef SANDBOX
|
|
|
|
get_project_gid();
|
2006-06-07 00:09:05 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-25 16:45:21 +00:00
|
|
|
check_file_existence();
|
2007-03-19 19:13:40 +00:00
|
|
|
if (!boinc_file_exists(ALL_PROJECTS_LIST_FILENAME)) {
|
|
|
|
all_projects_list_check_time = 0;
|
|
|
|
}
|
2007-06-12 16:15:53 +00:00
|
|
|
all_projects_list_check();
|
2006-07-25 16:45:21 +00:00
|
|
|
|
2007-04-09 02:17:26 +00:00
|
|
|
auto_update.init();
|
2007-04-11 21:49:57 +00:00
|
|
|
http_ops->cleanup_temp_files();
|
2007-06-25 11:46:15 +00:00
|
|
|
|
2006-08-03 16:39:57 +00:00
|
|
|
initialized = true;
|
2005-04-13 22:52:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-16 20:48:21 +00:00
|
|
|
static void double_to_timeval(double x, timeval& t) {
|
|
|
|
t.tv_sec = (int)x;
|
|
|
|
t.tv_usec = (int)(1000000*(x - (int)x));
|
|
|
|
}
|
|
|
|
|
|
|
|
FDSET_GROUP curl_fds;
|
|
|
|
FDSET_GROUP gui_rpc_fds;
|
|
|
|
FDSET_GROUP all_fds;
|
|
|
|
|
|
|
|
// Spend x seconds either doing I/O (if possible) or sleeping.
|
2005-04-13 22:52:05 +00:00
|
|
|
//
|
2005-08-16 21:10:28 +00:00
|
|
|
void CLIENT_STATE::do_io_or_sleep(double x) {
|
2005-08-16 20:48:21 +00:00
|
|
|
int n;
|
|
|
|
struct timeval tv;
|
|
|
|
now = dtime();
|
|
|
|
double end_time = now + x;
|
2006-05-09 02:00:04 +00:00
|
|
|
int loops = 0;
|
2005-08-16 20:48:21 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
curl_fds.zero();
|
|
|
|
gui_rpc_fds.zero();
|
2006-06-28 16:56:15 +00:00
|
|
|
http_ops->get_fdset(curl_fds);
|
2005-08-16 21:31:27 +00:00
|
|
|
all_fds = curl_fds;
|
|
|
|
gui_rpcs.get_fdset(gui_rpc_fds, all_fds);
|
2005-08-16 20:48:21 +00:00
|
|
|
double_to_timeval(x, tv);
|
|
|
|
n = select(
|
|
|
|
all_fds.max_fd+1,
|
|
|
|
&all_fds.read_fds, &all_fds.write_fds, &all_fds.exc_fds,
|
|
|
|
&tv
|
|
|
|
);
|
2005-08-16 21:51:51 +00:00
|
|
|
//printf("select in %d out %d\n", all_fds.max_fd, n);
|
2005-09-09 20:28:55 +00:00
|
|
|
|
|
|
|
// Note: curl apparently likes to have curl_multi_perform()
|
|
|
|
// (called from net_xfers->got_select())
|
|
|
|
// called pretty often, even if no descriptors are enabled.
|
|
|
|
// So do the "if (n==0) break" AFTER the got_selects().
|
|
|
|
|
2006-06-28 16:56:15 +00:00
|
|
|
http_ops->got_select(all_fds, x);
|
2005-08-16 20:48:21 +00:00
|
|
|
gui_rpcs.got_select(all_fds);
|
2005-09-09 20:28:55 +00:00
|
|
|
|
2005-09-08 21:07:28 +00:00
|
|
|
if (n==0) break;
|
2005-08-16 20:48:21 +00:00
|
|
|
|
2007-07-16 20:30:21 +00:00
|
|
|
// Limit number of times thru this loop.
|
|
|
|
// Can get stuck in while loop, if network isn't available,
|
2006-05-09 02:00:04 +00:00
|
|
|
// DNS lookups tend to eat CPU cycles.
|
|
|
|
//
|
|
|
|
if (loops++ > 99) {
|
|
|
|
boinc_sleep(.01);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-08-16 20:48:21 +00:00
|
|
|
now = dtime();
|
|
|
|
if (now > end_time) break;
|
|
|
|
x = end_time - now;
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define POLL_ACTION(name, func) \
|
2005-06-07 19:22:50 +00:00
|
|
|
do { if (func()) { \
|
2005-04-13 22:52:05 +00:00
|
|
|
++actions; \
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.poll_debug) { \
|
2006-09-07 20:39:25 +00:00
|
|
|
msg_printf(0, MSG_INFO, "[poll_debug] CLIENT_STATE::poll_slow_events(): " #name "\n"); \
|
2006-06-22 19:40:30 +00:00
|
|
|
} \
|
2005-04-13 22:52:05 +00:00
|
|
|
} } while(0)
|
|
|
|
|
2005-08-16 20:48:21 +00:00
|
|
|
// Poll the client's finite-state machines
|
2005-04-13 22:52:05 +00:00
|
|
|
// possibly triggering state transitions.
|
|
|
|
// Returns true if something happened
|
|
|
|
// (in which case should call this again immediately)
|
|
|
|
//
|
2005-08-16 20:48:21 +00:00
|
|
|
bool CLIENT_STATE::poll_slow_events() {
|
2006-08-07 03:56:34 +00:00
|
|
|
int actions = 0, retval;
|
2006-05-21 22:03:36 +00:00
|
|
|
static int last_suspend_reason=0;
|
2005-04-13 22:52:05 +00:00
|
|
|
static bool tasks_restarted = false;
|
2008-05-22 20:57:12 +00:00
|
|
|
static bool first=true;
|
2007-05-14 21:45:02 +00:00
|
|
|
double old_now = now;
|
2007-07-10 17:49:51 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
double idletime;
|
|
|
|
#endif
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2005-06-07 19:22:50 +00:00
|
|
|
now = dtime();
|
2007-07-16 20:30:21 +00:00
|
|
|
|
|
|
|
if (cant_write_state_file) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-05-14 21:45:02 +00:00
|
|
|
if (now - old_now > POLL_INTERVAL*10) {
|
2007-06-01 22:55:00 +00:00
|
|
|
if (log_flags.network_status_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"[network_status_debug] woke up after %f seconds",
|
|
|
|
now - old_now
|
|
|
|
);
|
|
|
|
}
|
2007-05-14 21:45:02 +00:00
|
|
|
last_wakeup_time = now;
|
|
|
|
}
|
2005-06-07 19:22:50 +00:00
|
|
|
|
2007-05-14 19:18:45 +00:00
|
|
|
if (should_run_cpu_benchmarks() && !are_cpu_benchmarks_running()) {
|
2005-04-13 22:52:05 +00:00
|
|
|
run_cpu_benchmarks = false;
|
2005-04-13 23:28:47 +00:00
|
|
|
start_cpu_benchmarks();
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-10 17:49:51 +00:00
|
|
|
bool old_user_active = user_active;
|
|
|
|
user_active = !host_info.users_idle(
|
|
|
|
check_all_logins, global_prefs.idle_time_to_run
|
|
|
|
#ifdef __APPLE__
|
|
|
|
, &idletime
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
if (user_active != old_user_active) {
|
|
|
|
request_schedule_cpus("Idle state change");
|
|
|
|
}
|
|
|
|
#ifdef __APPLE__
|
|
|
|
// Mac screensaver launches client if not already running.
|
|
|
|
// OS X quits screensaver when energy saver puts display to sleep,
|
|
|
|
// but we want to keep crunching.
|
|
|
|
// Also, user can start Mac screensaver by putting cursor in "hot corner"
|
|
|
|
// so idletime may be very small initially.
|
|
|
|
// If screensaver started client, this code tells client
|
|
|
|
// to exit when user becomes active, accounting for all these factors.
|
|
|
|
//
|
|
|
|
if (started_by_screensaver && (idletime < 30) && (getppid() == 1)) {
|
|
|
|
// pid is 1 if parent has exited
|
|
|
|
requested_exit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit if we were launched by Manager and it crashed.
|
|
|
|
//
|
|
|
|
if (launched_by_manager && (getppid() == 1)) {
|
|
|
|
gstate.requested_exit = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-19 23:22:19 +00:00
|
|
|
suspend_reason = check_suspend_processing();
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
// suspend or resume activities (but only if already did startup)
|
|
|
|
//
|
|
|
|
if (tasks_restarted) {
|
|
|
|
if (suspend_reason) {
|
2005-12-24 06:32:07 +00:00
|
|
|
if (!tasks_suspended) {
|
|
|
|
suspend_tasks(suspend_reason);
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
2006-05-21 22:03:36 +00:00
|
|
|
last_suspend_reason = suspend_reason;
|
2005-04-13 22:52:05 +00:00
|
|
|
} else {
|
2005-12-24 06:32:07 +00:00
|
|
|
if (tasks_suspended) {
|
2006-05-21 22:03:36 +00:00
|
|
|
resume_tasks(last_suspend_reason);
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-22 20:57:12 +00:00
|
|
|
} else if (first) {
|
|
|
|
// if suspended, show message the first time around
|
|
|
|
//
|
|
|
|
first = false;
|
|
|
|
if (suspend_reason) {
|
|
|
|
print_suspend_tasks_message(suspend_reason);
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
2005-12-24 06:32:07 +00:00
|
|
|
tasks_suspended = (suspend_reason != 0);
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
if (suspend_reason & SUSPEND_REASON_BENCHMARKS) {
|
2005-05-10 03:42:01 +00:00
|
|
|
cpu_benchmarks_poll();
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 23:22:19 +00:00
|
|
|
network_suspend_reason = check_suspend_network();
|
2005-12-24 06:32:07 +00:00
|
|
|
|
2006-09-08 22:28:10 +00:00
|
|
|
// if a recent GUI RPC needs network access, allow it
|
2005-12-24 06:32:07 +00:00
|
|
|
//
|
2006-09-08 22:28:10 +00:00
|
|
|
if (gui_rpcs.recent_rpc_needs_network(300)) {
|
|
|
|
network_suspend_reason = 0;
|
2005-12-24 06:32:07 +00:00
|
|
|
}
|
2006-05-21 22:03:36 +00:00
|
|
|
if (network_suspend_reason) {
|
2005-04-13 22:52:05 +00:00
|
|
|
if (!network_suspended) {
|
2006-05-21 22:03:36 +00:00
|
|
|
suspend_network(network_suspend_reason);
|
|
|
|
network_suspended = true;
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (network_suspended) {
|
|
|
|
resume_network();
|
2006-05-21 22:03:36 +00:00
|
|
|
network_suspended = false;
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE:
|
|
|
|
// The order of calls in the following lists generally doesn't matter,
|
|
|
|
// except for the following:
|
|
|
|
// must have:
|
|
|
|
// active_tasks_poll
|
|
|
|
// handle_finished_apps
|
2006-06-16 18:52:25 +00:00
|
|
|
// possibly_schedule_cpus
|
2006-06-15 23:15:27 +00:00
|
|
|
// enforce_schedule
|
2005-04-13 22:52:05 +00:00
|
|
|
// in that order (active_tasks_poll() sets must_schedule_cpus,
|
2006-06-16 18:52:25 +00:00
|
|
|
// and handle_finished_apps() must be done before possibly_schedule_cpus()
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2006-11-08 00:20:16 +00:00
|
|
|
check_project_timeout();
|
2006-12-11 23:42:54 +00:00
|
|
|
auto_update.poll();
|
2005-08-16 20:48:21 +00:00
|
|
|
POLL_ACTION(active_tasks , active_tasks.poll );
|
|
|
|
POLL_ACTION(garbage_collect , garbage_collect );
|
|
|
|
POLL_ACTION(update_results , update_results );
|
|
|
|
POLL_ACTION(gui_http , gui_http.poll );
|
2007-09-27 21:03:15 +00:00
|
|
|
POLL_ACTION(gui_rpc_http , gui_rpcs.poll );
|
2005-12-24 06:32:07 +00:00
|
|
|
if (!network_suspended) {
|
2007-08-17 18:05:39 +00:00
|
|
|
net_status.poll();
|
2006-03-14 00:46:41 +00:00
|
|
|
POLL_ACTION(acct_mgr , acct_mgr_info.poll );
|
2005-08-16 20:48:21 +00:00
|
|
|
POLL_ACTION(file_xfers , file_xfers->poll );
|
|
|
|
POLL_ACTION(pers_file_xfers , pers_file_xfers->poll );
|
|
|
|
POLL_ACTION(handle_pers_file_xfers , handle_pers_file_xfers );
|
|
|
|
}
|
|
|
|
POLL_ACTION(handle_finished_apps , handle_finished_apps );
|
2005-12-24 06:32:07 +00:00
|
|
|
if (!tasks_suspended) {
|
2006-06-16 18:52:25 +00:00
|
|
|
POLL_ACTION(possibly_schedule_cpus, possibly_schedule_cpus );
|
2006-06-15 23:15:27 +00:00
|
|
|
POLL_ACTION(enforce_schedule , enforce_schedule );
|
2006-06-19 04:29:26 +00:00
|
|
|
tasks_restarted = true;
|
2005-08-16 20:48:21 +00:00
|
|
|
}
|
2006-08-11 04:16:23 +00:00
|
|
|
if (!tasks_suspended && !network_suspended) {
|
|
|
|
POLL_ACTION(compute_work_requests, compute_work_requests );
|
|
|
|
}
|
2005-12-24 06:32:07 +00:00
|
|
|
if (!network_suspended) {
|
2005-08-16 20:48:21 +00:00
|
|
|
POLL_ACTION(scheduler_rpc , scheduler_rpc_poll );
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
retval = write_state_file_if_needed();
|
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_INTERNAL_ERROR,
|
2008-03-11 03:59:35 +00:00
|
|
|
"Couldn't write state file: %s; giving up", boincerror(retval)
|
2005-07-05 09:02:55 +00:00
|
|
|
);
|
2008-03-11 03:59:35 +00:00
|
|
|
exit(EXIT_STATEFILE_WRITE);
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.poll_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[poll_debug] CLIENT_STATE::do_something(): End poll: %d tasks active\n", actions
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
if (actions > 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2007-04-11 21:49:57 +00:00
|
|
|
time_stats.update(suspend_reason);
|
2006-06-23 20:41:47 +00:00
|
|
|
|
|
|
|
// on some systems, gethostbyname() only starts working
|
|
|
|
// a few minutes after system boot.
|
|
|
|
// If it didn't work before, try it again.
|
|
|
|
//
|
|
|
|
if (!strlen(host_info.domain_name)) {
|
|
|
|
host_info.get_local_network_info();
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if the project specified by master_url already exists
|
|
|
|
// in the client state record. Ignore any trailing "/" characters
|
|
|
|
//
|
|
|
|
PROJECT* CLIENT_STATE::lookup_project(const char* master_url) {
|
|
|
|
int len1, len2;
|
|
|
|
char *mu;
|
|
|
|
|
2006-09-07 18:19:25 +00:00
|
|
|
len1 = (int)strlen(master_url);
|
2005-04-13 22:52:05 +00:00
|
|
|
if (master_url[strlen(master_url)-1] == '/') len1--;
|
|
|
|
|
|
|
|
for (unsigned int i=0; i<projects.size(); i++) {
|
|
|
|
mu = projects[i]->master_url;
|
2006-09-07 18:19:25 +00:00
|
|
|
len2 = (int)strlen(mu);
|
2005-04-13 22:52:05 +00:00
|
|
|
if (mu[strlen(mu)-1] == '/') len2--;
|
|
|
|
if (!strncmp(master_url, projects[i]->master_url, max(len1,len2))) {
|
|
|
|
return projects[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
APP* CLIENT_STATE::lookup_app(PROJECT* p, const char* name) {
|
|
|
|
for (unsigned int i=0; i<apps.size(); i++) {
|
|
|
|
APP* app = apps[i];
|
|
|
|
if (app->project == p && !strcmp(name, app->name)) return app;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RESULT* CLIENT_STATE::lookup_result(PROJECT* p, const char* name) {
|
|
|
|
for (unsigned int i=0; i<results.size(); i++) {
|
|
|
|
RESULT* rp = results[i];
|
|
|
|
if (rp->project == p && !strcmp(name, rp->name)) return rp;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
WORKUNIT* CLIENT_STATE::lookup_workunit(PROJECT* p, const char* name) {
|
|
|
|
for (unsigned int i=0; i<workunits.size(); i++) {
|
|
|
|
WORKUNIT* wup = workunits[i];
|
|
|
|
if (wup->project == p && !strcmp(name, wup->name)) return wup;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-13 19:54:24 +00:00
|
|
|
APP_VERSION* CLIENT_STATE::lookup_app_version(
|
2008-03-27 18:25:29 +00:00
|
|
|
APP* app, char* platform, int version_num, char* plan_class
|
2007-06-13 19:54:24 +00:00
|
|
|
) {
|
2005-04-13 22:52:05 +00:00
|
|
|
for (unsigned int i=0; i<app_versions.size(); i++) {
|
|
|
|
APP_VERSION* avp = app_versions[i];
|
2007-05-14 19:18:45 +00:00
|
|
|
if (avp->app != app) continue;
|
2007-06-13 19:54:24 +00:00
|
|
|
if (version_num != avp->version_num) continue;
|
2007-05-21 14:51:33 +00:00
|
|
|
if (app->project->anonymous_platform) {
|
|
|
|
return avp;
|
|
|
|
}
|
2007-05-03 17:14:30 +00:00
|
|
|
if (strcmp(avp->platform, platform)) continue;
|
2008-03-27 18:25:29 +00:00
|
|
|
if (strcmp(avp->plan_class, plan_class)) continue;
|
2007-05-03 17:14:30 +00:00
|
|
|
return avp;
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE_INFO* CLIENT_STATE::lookup_file_info(PROJECT* p, const char* name) {
|
|
|
|
for (unsigned int i=0; i<file_infos.size(); i++) {
|
|
|
|
FILE_INFO* fip = file_infos[i];
|
|
|
|
if (fip->project == p && !strcmp(fip->name, name)) {
|
|
|
|
return fip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// functions to create links between state objects
|
|
|
|
// (which, in their XML form, reference one another by name)
|
|
|
|
// Return nonzero if already in client state.
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::link_app(PROJECT* p, APP* app) {
|
2005-04-13 23:28:47 +00:00
|
|
|
if (lookup_app(p, app->name)) return ERR_NOT_UNIQUE;
|
2005-04-13 22:52:05 +00:00
|
|
|
app->project = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::link_file_info(PROJECT* p, FILE_INFO* fip) {
|
2005-04-13 23:28:47 +00:00
|
|
|
if (lookup_file_info(p, fip->name)) return ERR_NOT_UNIQUE;
|
2005-04-13 22:52:05 +00:00
|
|
|
fip->project = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::link_app_version(PROJECT* p, APP_VERSION* avp) {
|
|
|
|
APP* app;
|
|
|
|
FILE_INFO* fip;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
avp->project = p;
|
|
|
|
app = lookup_app(p, avp->app_name);
|
|
|
|
if (!app) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(p, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"State file error: bad application name %s",
|
|
|
|
avp->app_name
|
|
|
|
);
|
2005-04-13 22:52:05 +00:00
|
|
|
return ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
avp->app = app;
|
|
|
|
|
2008-03-27 18:25:29 +00:00
|
|
|
if (lookup_app_version(app, avp->platform, avp->version_num, avp->plan_class)) {
|
2007-05-08 22:07:21 +00:00
|
|
|
msg_printf(p, MSG_INTERNAL_ERROR,
|
2008-03-27 18:25:29 +00:00
|
|
|
"State file error: duplicate app version: %s %s %d %s",
|
|
|
|
avp->app_name, avp->platform, avp->version_num, avp->plan_class
|
2007-05-08 22:07:21 +00:00
|
|
|
);
|
|
|
|
return ERR_NOT_UNIQUE;
|
|
|
|
}
|
2007-10-11 11:02:48 +00:00
|
|
|
|
|
|
|
avp->graphics_exec_path[0] = 0;
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
for (i=0; i<avp->app_files.size(); i++) {
|
|
|
|
FILE_REF& file_ref = avp->app_files[i];
|
|
|
|
fip = lookup_file_info(p, file_ref.file_name);
|
|
|
|
if (!fip) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(p, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"State file error: missing application file %s",
|
2005-04-13 22:52:05 +00:00
|
|
|
file_ref.file_name
|
|
|
|
);
|
|
|
|
return ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2007-09-25 16:04:45 +00:00
|
|
|
if (!strcmp(file_ref.open_name, GRAPHICS_APP_FILENAME)) {
|
2007-06-14 23:08:43 +00:00
|
|
|
char relpath[512], path[512];
|
|
|
|
get_pathname(fip, relpath, sizeof(relpath));
|
|
|
|
relative_to_absolute(relpath, path);
|
|
|
|
strlcpy(avp->graphics_exec_path, path, sizeof(avp->graphics_exec_path));
|
|
|
|
}
|
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
// any file associated with an app version must be signed
|
|
|
|
//
|
|
|
|
fip->signature_required = true;
|
|
|
|
file_ref.file_info = fip;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::link_file_ref(PROJECT* p, FILE_REF* file_refp) {
|
|
|
|
FILE_INFO* fip;
|
|
|
|
|
|
|
|
fip = lookup_file_info(p, file_refp->file_name);
|
|
|
|
if (!fip) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(p, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"State file error: missing file %s",
|
|
|
|
file_refp->file_name
|
|
|
|
);
|
2005-04-13 22:52:05 +00:00
|
|
|
return ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
file_refp->file_info = fip;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::link_workunit(PROJECT* p, WORKUNIT* wup) {
|
|
|
|
APP* app;
|
|
|
|
unsigned int i;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
app = lookup_app(p, wup->app_name);
|
|
|
|
if (!app) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(p, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"State file error: missing application %s",
|
|
|
|
wup->app_name
|
|
|
|
);
|
2005-04-13 22:52:05 +00:00
|
|
|
return ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
wup->project = p;
|
|
|
|
wup->app = app;
|
|
|
|
for (i=0; i<wup->input_files.size(); i++) {
|
|
|
|
retval = link_file_ref(p, &wup->input_files[i]);
|
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(p, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"State file error: missing input file %s\n",
|
2005-04-13 22:52:05 +00:00
|
|
|
wup->input_files[i].file_name
|
|
|
|
);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::link_result(PROJECT* p, RESULT* rp) {
|
|
|
|
WORKUNIT* wup;
|
|
|
|
unsigned int i;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
wup = lookup_workunit(p, rp->wu_name);
|
|
|
|
if (!wup) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(p, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"State file error: missing task %s\n", rp->wu_name
|
|
|
|
);
|
2005-04-13 22:52:05 +00:00
|
|
|
return ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
rp->project = p;
|
|
|
|
rp->wup = wup;
|
|
|
|
rp->app = wup->app;
|
|
|
|
for (i=0; i<rp->output_files.size(); i++) {
|
|
|
|
retval = link_file_ref(p, &rp->output_files[i]);
|
2006-01-17 22:48:09 +00:00
|
|
|
if (retval) return retval;
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print debugging information about how many projects/files/etc
|
|
|
|
// are currently in the client state record
|
|
|
|
//
|
|
|
|
void CLIENT_STATE::print_summary() {
|
|
|
|
unsigned int i;
|
2005-06-07 19:22:50 +00:00
|
|
|
double t;
|
2005-04-13 22:52:05 +00:00
|
|
|
if (!log_flags.state_debug) return;
|
|
|
|
|
2006-09-07 20:39:25 +00:00
|
|
|
msg_printf(0, MSG_INFO, "[state_debug] CLIENT_STATE::print_summary(): Client state summary:\n");
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, "%d projects:\n", (int)projects.size());
|
2005-04-13 22:52:05 +00:00
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
t = projects[i]->min_rpc_time;
|
|
|
|
if (t) {
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, " %s min RPC %f.0 seconds from now\n", projects[i]->master_url, t-now);
|
2005-04-13 22:52:05 +00:00
|
|
|
} else {
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, " %s\n", projects[i]->master_url);
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, "%d file_infos:\n", (int)file_infos.size());
|
2005-04-13 22:52:05 +00:00
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, " %s status:%d %s\n", file_infos[i]->name, file_infos[i]->status, file_infos[i]->pers_file_xfer?"active":"inactive");
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, "%d app_versions\n", (int)app_versions.size());
|
2005-04-13 22:52:05 +00:00
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, " %s %d\n", app_versions[i]->app_name, app_versions[i]->version_num);
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, "%d workunits\n", (int)workunits.size());
|
2005-04-13 22:52:05 +00:00
|
|
|
for (i=0; i<workunits.size(); i++) {
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, " %s\n", workunits[i]->name);
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, "%d results\n", (int)results.size());
|
2005-04-13 22:52:05 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
2007-01-24 21:20:57 +00:00
|
|
|
msg_printf(0, MSG_INFO, " %s state:%d\n", results[i]->name, results[i]->state());
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, "%d persistent file xfers\n", (int)pers_file_xfers->pers_file_xfers.size());
|
2005-04-13 22:52:05 +00:00
|
|
|
for (i=0; i<pers_file_xfers->pers_file_xfers.size(); i++) {
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, " %s http op state: %d\n", pers_file_xfers->pers_file_xfers[i]->fip->name, (pers_file_xfers->pers_file_xfers[i]->fxp?pers_file_xfers->pers_file_xfers[i]->fxp->http_op_state:-1));
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, "%d active tasks\n", (int)active_tasks.active_tasks.size());
|
2005-04-13 22:52:05 +00:00
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO, " %s\n", active_tasks.active_tasks[i]->result->name);
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:24:52 +00:00
|
|
|
int CLIENT_STATE::nresults_for_project(PROJECT* p) {
|
|
|
|
int n=0;
|
|
|
|
for (unsigned int i=0; i<results.size(); i++) {
|
|
|
|
if (results[i]->project == p) n++;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2005-06-07 19:22:50 +00:00
|
|
|
bool CLIENT_STATE::garbage_collect() {
|
|
|
|
static double last_time=0;
|
|
|
|
if (gstate.now - last_time < 1.0) return false;
|
|
|
|
last_time = gstate.now;
|
|
|
|
|
2007-02-23 20:24:52 +00:00
|
|
|
bool action = garbage_collect_always();
|
|
|
|
if (action) return true;
|
|
|
|
|
|
|
|
// Detach projects that are marked for detach when done
|
|
|
|
// and are in fact done (have no results).
|
|
|
|
// This is done here (not in garbage_collect_always())
|
|
|
|
// because detach_project() calls garbage_collect_always(),
|
|
|
|
// and we need to avoid infinite recursion
|
|
|
|
//
|
|
|
|
for (unsigned i=0; i<projects.size(); i++) {
|
|
|
|
PROJECT* p = projects[i];
|
|
|
|
if (p->detach_when_done && !nresults_for_project(p)) {
|
|
|
|
detach_project(p);
|
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return action;
|
2005-06-07 19:22:50 +00:00
|
|
|
}
|
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
// delete unneeded records and files
|
|
|
|
//
|
2005-06-07 19:22:50 +00:00
|
|
|
bool CLIENT_STATE::garbage_collect_always() {
|
2005-04-13 22:52:05 +00:00
|
|
|
unsigned int i, j;
|
|
|
|
int failnum;
|
|
|
|
FILE_INFO* fip;
|
|
|
|
RESULT* rp;
|
|
|
|
WORKUNIT* wup;
|
|
|
|
APP_VERSION* avp, *avp2;
|
|
|
|
vector<RESULT*>::iterator result_iter;
|
|
|
|
vector<WORKUNIT*>::iterator wu_iter;
|
|
|
|
vector<FILE_INFO*>::iterator fi_iter;
|
|
|
|
vector<APP_VERSION*>::iterator avp_iter;
|
|
|
|
bool action = false, found;
|
|
|
|
string error_msgs;
|
|
|
|
PROJECT* project;
|
|
|
|
|
|
|
|
// zero references counts on WUs, FILE_INFOs and APP_VERSIONs
|
|
|
|
|
|
|
|
for (i=0; i<workunits.size(); i++) {
|
|
|
|
wup = workunits[i];
|
|
|
|
wup->ref_cnt = 0;
|
|
|
|
}
|
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
|
|
|
fip = file_infos[i];
|
|
|
|
fip->ref_cnt = 0;
|
|
|
|
}
|
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
avp = app_versions[i];
|
|
|
|
avp->ref_cnt = 0;
|
|
|
|
}
|
|
|
|
|
2006-06-27 17:31:43 +00:00
|
|
|
// reference-count user and project files
|
2005-04-13 22:52:05 +00:00
|
|
|
//
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
project = projects[i];
|
|
|
|
for (j=0; j<project->user_files.size(); j++) {
|
|
|
|
project->user_files[j].file_info->ref_cnt++;
|
|
|
|
}
|
2006-06-27 17:31:43 +00:00
|
|
|
for (j=0; j<project->project_files.size(); j++) {
|
|
|
|
project->project_files[j].file_info->ref_cnt++;
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
|
2006-12-11 23:42:54 +00:00
|
|
|
// reference-count auto update files
|
|
|
|
//
|
|
|
|
if (auto_update.present) {
|
|
|
|
for (i=0; i<auto_update.file_refs.size(); i++) {
|
|
|
|
auto_update.file_refs[i].file_info->ref_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
// Scan through RESULTs.
|
|
|
|
// delete RESULTs that have been reported and acked.
|
|
|
|
// Check for results whose WUs had download failures
|
|
|
|
// Check for results that had upload failures
|
|
|
|
// Reference-count output files
|
|
|
|
// Reference-count WUs
|
|
|
|
//
|
|
|
|
result_iter = results.begin();
|
|
|
|
while (result_iter != results.end()) {
|
|
|
|
rp = *result_iter;
|
|
|
|
if (rp->got_server_ack) {
|
2007-01-18 19:29:15 +00:00
|
|
|
// see if - for some reason - there's an active task
|
|
|
|
// for this result. don't want to create dangling ptr.
|
|
|
|
//
|
|
|
|
ACTIVE_TASK* atp = active_tasks.lookup_result(rp);
|
|
|
|
if (atp) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(rp->project, MSG_INTERNAL_ERROR,
|
2007-01-24 16:32:33 +00:00
|
|
|
"garbage_collect(); still have active task for acked result %s; state %d",
|
2007-01-24 21:20:57 +00:00
|
|
|
rp->name, atp->task_state()
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
2007-01-24 21:20:57 +00:00
|
|
|
atp->set_task_state(PROCESS_EXITED, "garbage_collect");
|
|
|
|
// this will get rid of it
|
2007-01-18 19:29:15 +00:00
|
|
|
} else {
|
|
|
|
if (log_flags.state_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"[state_debug] garbage_collect: deleting result %s\n",
|
|
|
|
rp->name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
delete rp;
|
|
|
|
result_iter = results.erase(result_iter);
|
|
|
|
action = true;
|
|
|
|
continue;
|
2006-06-22 19:40:30 +00:00
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
// See if the files for this result's workunit had
|
|
|
|
// any errors (download failure, MD5, RSA, etc)
|
|
|
|
// and we don't already have an error for this result
|
|
|
|
//
|
|
|
|
if (!rp->ready_to_report) {
|
|
|
|
wup = rp->wup;
|
|
|
|
if (wup->had_download_failure(failnum)) {
|
|
|
|
wup->get_file_errors(error_msgs);
|
|
|
|
report_result_error(
|
|
|
|
*rp, "WU download error: %s", error_msgs.c_str()
|
|
|
|
);
|
2007-05-03 17:14:30 +00:00
|
|
|
} else if (rp->avp && rp->avp->had_download_failure(failnum)) {
|
|
|
|
rp->avp->get_file_errors(error_msgs);
|
2005-04-13 22:52:05 +00:00
|
|
|
report_result_error(
|
|
|
|
*rp, "app_version download error: %s", error_msgs.c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool found_error = false;
|
2006-03-30 22:21:18 +00:00
|
|
|
string error_str;
|
2005-04-13 22:52:05 +00:00
|
|
|
for (i=0; i<rp->output_files.size(); i++) {
|
|
|
|
// If one of the output files had an upload failure,
|
|
|
|
// mark the result as done and report the error.
|
|
|
|
// The result, workunits, and file infos
|
|
|
|
// will be cleaned up after the server is notified
|
|
|
|
//
|
|
|
|
if (!rp->ready_to_report) {
|
|
|
|
fip = rp->output_files[i].file_info;
|
2006-03-30 22:21:18 +00:00
|
|
|
if (fip->had_failure(failnum)) {
|
|
|
|
string msg;
|
|
|
|
fip->failure_message(msg);
|
2005-04-13 22:52:05 +00:00
|
|
|
found_error = true;
|
2006-03-30 22:21:18 +00:00
|
|
|
error_str += msg;
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rp->output_files[i].file_info->ref_cnt++;
|
|
|
|
}
|
|
|
|
if (found_error) {
|
2006-11-28 21:16:04 +00:00
|
|
|
report_result_error(*rp, "%s", error_str.c_str());
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
2007-05-03 17:14:30 +00:00
|
|
|
rp->avp->ref_cnt++;
|
2005-04-13 22:52:05 +00:00
|
|
|
rp->wup->ref_cnt++;
|
|
|
|
result_iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete WORKUNITs not referenced by any in-progress result;
|
|
|
|
// reference-count files and APP_VERSIONs referred to by other WUs
|
|
|
|
//
|
|
|
|
wu_iter = workunits.begin();
|
|
|
|
while (wu_iter != workunits.end()) {
|
|
|
|
wup = *wu_iter;
|
|
|
|
if (wup->ref_cnt == 0) {
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.state_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[state_debug] CLIENT_STATE::garbage_collect(): deleting workunit %s\n",
|
2006-06-22 19:40:30 +00:00
|
|
|
wup->name
|
|
|
|
);
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
delete wup;
|
|
|
|
wu_iter = workunits.erase(wu_iter);
|
|
|
|
action = true;
|
|
|
|
} else {
|
|
|
|
for (i=0; i<wup->input_files.size(); i++) {
|
|
|
|
wup->input_files[i].file_info->ref_cnt++;
|
|
|
|
}
|
|
|
|
wu_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// go through APP_VERSIONs;
|
|
|
|
// delete any not referenced by any WORKUNIT
|
|
|
|
// and superceded by a more recent version.
|
|
|
|
//
|
|
|
|
avp_iter = app_versions.begin();
|
|
|
|
while (avp_iter != app_versions.end()) {
|
|
|
|
avp = *avp_iter;
|
|
|
|
if (avp->ref_cnt == 0) {
|
|
|
|
found = false;
|
|
|
|
for (j=0; j<app_versions.size(); j++) {
|
|
|
|
avp2 = app_versions[j];
|
|
|
|
if (avp2->app==avp->app && avp2->version_num>avp->version_num) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
delete avp;
|
|
|
|
avp_iter = app_versions.erase(avp_iter);
|
|
|
|
action = true;
|
|
|
|
} else {
|
|
|
|
avp_iter++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
avp_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then go through remaining APP_VERSIONs,
|
|
|
|
// bumping refcnt of associated files.
|
|
|
|
//
|
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
avp = app_versions[i];
|
|
|
|
for (j=0; j<avp->app_files.size(); j++) {
|
|
|
|
avp->app_files[j].file_info->ref_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// reference count files involved in PERS_FILE_XFER or FILE_XFER
|
|
|
|
// (this seems redundant, but apparently not)
|
|
|
|
//
|
|
|
|
for (i=0; i<file_xfers->file_xfers.size(); i++) {
|
|
|
|
file_xfers->file_xfers[i]->fip->ref_cnt++;
|
|
|
|
}
|
|
|
|
for (i=0; i<pers_file_xfers->pers_file_xfers.size(); i++) {
|
|
|
|
pers_file_xfers->pers_file_xfers[i]->fip->ref_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete FILE_INFOs (and corresponding files) that are not referenced
|
|
|
|
// Don't do this if sticky and not marked for delete
|
|
|
|
//
|
|
|
|
fi_iter = file_infos.begin();
|
|
|
|
while (fi_iter != file_infos.end()) {
|
|
|
|
fip = *fi_iter;
|
|
|
|
bool exempt = fip->sticky;
|
|
|
|
if (fip->status < 0) exempt = false;
|
|
|
|
if (fip->marked_for_delete) exempt = false;
|
|
|
|
if (fip->ref_cnt==0 && !exempt) {
|
|
|
|
if (fip->pers_file_xfer) {
|
|
|
|
pers_file_xfers->remove(fip->pers_file_xfer);
|
|
|
|
delete fip->pers_file_xfer;
|
|
|
|
fip->pers_file_xfer = 0;
|
|
|
|
}
|
|
|
|
fip->delete_file();
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.state_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[state_debug] CLIENT_STATE::garbage_collect(): deleting file %s\n",
|
2006-06-22 19:40:30 +00:00
|
|
|
fip->name
|
|
|
|
);
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
delete fip;
|
|
|
|
fi_iter = file_infos.erase(fi_iter);
|
|
|
|
action = true;
|
|
|
|
} else {
|
|
|
|
fi_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
print_summary();
|
|
|
|
}
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2006-06-14 21:58:23 +00:00
|
|
|
// For results that are waiting for file transfer,
|
|
|
|
// check if the transfer is done,
|
|
|
|
// and if so switch to new state and take other actions.
|
|
|
|
// Also set some fields for newly-aborted results.
|
2005-04-13 22:52:05 +00:00
|
|
|
//
|
2005-06-07 19:22:50 +00:00
|
|
|
bool CLIENT_STATE::update_results() {
|
2005-04-13 22:52:05 +00:00
|
|
|
RESULT* rp;
|
|
|
|
vector<RESULT*>::iterator result_iter;
|
|
|
|
bool action = false;
|
|
|
|
static double last_time=0;
|
2006-06-20 19:34:42 +00:00
|
|
|
int retval;
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2005-06-07 19:22:50 +00:00
|
|
|
if (gstate.now - last_time < 1.0) return false;
|
|
|
|
last_time = gstate.now;
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
result_iter = results.begin();
|
|
|
|
while (result_iter != results.end()) {
|
|
|
|
rp = *result_iter;
|
|
|
|
|
2007-01-24 21:20:57 +00:00
|
|
|
switch (rp->state()) {
|
2005-04-13 22:52:05 +00:00
|
|
|
case RESULT_NEW:
|
2007-01-24 21:20:57 +00:00
|
|
|
rp->set_state(RESULT_FILES_DOWNLOADING, "CS::update_results");
|
2005-04-13 22:52:05 +00:00
|
|
|
action = true;
|
|
|
|
break;
|
|
|
|
case RESULT_FILES_DOWNLOADING:
|
2006-06-20 19:34:42 +00:00
|
|
|
retval = input_files_available(rp, false);
|
|
|
|
if (!retval) {
|
2007-01-24 21:20:57 +00:00
|
|
|
rp->set_state(RESULT_FILES_DOWNLOADED, "CS::update_results");
|
2007-05-03 17:14:30 +00:00
|
|
|
if (rp->avp->app_files.size()==0) {
|
2006-06-19 17:40:53 +00:00
|
|
|
// if this is a file-transfer app, start the upload phase
|
|
|
|
//
|
2007-01-24 21:20:57 +00:00
|
|
|
rp->set_state(RESULT_FILES_UPLOADING, "CS::update_results");
|
2006-06-19 17:40:53 +00:00
|
|
|
rp->clear_uploaded_flags();
|
|
|
|
} else {
|
|
|
|
// else try to start the computation
|
|
|
|
//
|
|
|
|
request_schedule_cpus("files downloaded");
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESULT_FILES_UPLOADING:
|
|
|
|
if (rp->is_upload_done()) {
|
|
|
|
rp->ready_to_report = true;
|
2005-06-07 19:22:50 +00:00
|
|
|
rp->completed_time = gstate.now;
|
2007-01-24 21:20:57 +00:00
|
|
|
rp->set_state(RESULT_FILES_UPLOADED, "CS::update_results");
|
2005-04-13 22:52:05 +00:00
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESULT_FILES_UPLOADED:
|
|
|
|
break;
|
2006-06-14 21:58:23 +00:00
|
|
|
case RESULT_ABORTED:
|
|
|
|
if (!rp->ready_to_report) {
|
|
|
|
rp->ready_to_report = true;
|
|
|
|
rp->completed_time = now;
|
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
break;
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
result_iter++;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if client should exit because of debugging criteria
|
|
|
|
// (timeout or idle)
|
|
|
|
//
|
|
|
|
bool CLIENT_STATE::time_to_exit() {
|
|
|
|
if (exit_after_app_start_secs
|
|
|
|
&& (app_started>0)
|
2005-06-07 19:22:50 +00:00
|
|
|
&& ((now - app_started) >= exit_after_app_start_secs)
|
2005-04-13 22:52:05 +00:00
|
|
|
) {
|
2006-01-17 22:48:09 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"Exiting because time is up: %d", exit_after_app_start_secs
|
|
|
|
);
|
2005-04-13 22:52:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (exit_when_idle && (results.size() == 0) && contacted_sched_server) {
|
2006-01-17 22:48:09 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "exiting because no more results");
|
2005-04-13 22:52:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-07-16 20:30:21 +00:00
|
|
|
if (cant_write_state_file) {
|
|
|
|
static bool first = true;
|
|
|
|
double t = now - last_wakeup_time;
|
|
|
|
if (first && t > 50) {
|
|
|
|
first = false;
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"Can't write state file, exiting in 10 seconds"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (t > 60) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"Can't write state file, exiting now"
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call this when a result has a nonrecoverable error.
|
|
|
|
// - back off on contacting the project's scheduler
|
|
|
|
// (so don't crash over and over)
|
|
|
|
// - Append a description of the error to result.stderr_out
|
2006-06-20 19:34:42 +00:00
|
|
|
// - If result state is FILES_DOWNLOADED, change it to COMPUTE_ERROR
|
|
|
|
// so that we don't try to run it again.
|
2005-04-13 22:52:05 +00:00
|
|
|
//
|
2005-06-25 23:54:07 +00:00
|
|
|
int CLIENT_STATE::report_result_error(RESULT& res, const char* format, ...) {
|
2005-10-03 18:05:58 +00:00
|
|
|
char buf[4096], err_msg[4096];
|
|
|
|
// The above store 1-line messages and short XML snippets.
|
|
|
|
// Shouldn't exceed a few hundred bytes.
|
2005-04-13 22:52:05 +00:00
|
|
|
unsigned int i;
|
|
|
|
int failnum;
|
|
|
|
|
|
|
|
// only do this once per result
|
|
|
|
//
|
|
|
|
if (res.ready_to_report) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
res.ready_to_report = true;
|
2005-06-07 19:22:50 +00:00
|
|
|
res.completed_time = now;
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
|
|
|
vsnprintf(err_msg, sizeof(err_msg), format, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
sprintf(buf, "Unrecoverable error for result %s (%s)", res.name, err_msg);
|
|
|
|
scheduler_op->backoff(res.project, buf);
|
|
|
|
|
2006-04-24 00:31:33 +00:00
|
|
|
sprintf( buf, "<message>\n%s\n</message>\n", err_msg);
|
2005-04-13 22:52:05 +00:00
|
|
|
res.stderr_out.append(buf);
|
|
|
|
|
2007-01-24 21:20:57 +00:00
|
|
|
switch(res.state()) {
|
2005-04-13 22:52:05 +00:00
|
|
|
case RESULT_NEW:
|
|
|
|
case RESULT_FILES_DOWNLOADING:
|
|
|
|
// called from:
|
|
|
|
// CLIENT_STATE::garbage_collect()
|
|
|
|
// if WU or app_version had a download failure
|
|
|
|
//
|
|
|
|
if (!res.exit_status) {
|
|
|
|
res.exit_status = ERR_RESULT_DOWNLOAD;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESULT_FILES_DOWNLOADED:
|
|
|
|
// called from:
|
|
|
|
// ACTIVE_TASK::start (if couldn't start app)
|
|
|
|
// ACTIVE_TASK::restart (if files missing)
|
|
|
|
// ACITVE_TASK_SET::restart_tasks (catch other error returns)
|
|
|
|
// ACTIVE_TASK::handle_exited_app (on nonzero exit or signal)
|
|
|
|
// ACTIVE_TASK::abort_task (if exceeded resource limit)
|
|
|
|
// CLIENT_STATE::schedule_cpus (catch-all for resume/start errors)
|
|
|
|
//
|
2007-01-24 21:20:57 +00:00
|
|
|
res.set_state(RESULT_COMPUTE_ERROR, "CS::report_result_error");
|
2005-04-13 22:52:05 +00:00
|
|
|
if (!res.exit_status) {
|
|
|
|
res.exit_status = ERR_RESULT_START;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESULT_FILES_UPLOADING:
|
|
|
|
// called from
|
|
|
|
// CLIENT_STATE::garbage_collect() if result had an upload error
|
|
|
|
//
|
|
|
|
for (i=0; i<res.output_files.size(); i++) {
|
|
|
|
if (res.output_files[i].file_info->had_failure(failnum)) {
|
|
|
|
sprintf(buf,
|
|
|
|
"<upload_error>\n"
|
|
|
|
" <file_name>%s</file_name>\n"
|
|
|
|
" <error_code>%d</error_code>\n"
|
|
|
|
"</upload_error>\n",
|
|
|
|
res.output_files[i].file_info->name, failnum
|
|
|
|
);
|
|
|
|
res.stderr_out.append(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!res.exit_status) {
|
|
|
|
res.exit_status = ERR_RESULT_UPLOAD;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESULT_FILES_UPLOADED:
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(res.project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Error reported for completed task %s", res.name
|
|
|
|
);
|
2005-04-13 22:52:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-10-03 18:05:58 +00:00
|
|
|
res.stderr_out = res.stderr_out.substr(0, MAX_STDERR_LEN);
|
2005-04-13 22:52:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "Reset" a project: (clear error conditions)
|
|
|
|
// - stop all active tasks
|
|
|
|
// - stop all file transfers
|
|
|
|
// - stop scheduler RPC if any
|
|
|
|
// - delete all workunits and results
|
|
|
|
// - delete all apps and app_versions
|
|
|
|
// - garbage collect to delete unneeded files
|
|
|
|
//
|
|
|
|
// Note: does NOT delete persistent files or user-supplied files;
|
|
|
|
// does not delete project dir
|
|
|
|
//
|
2007-12-03 17:46:07 +00:00
|
|
|
int CLIENT_STATE::reset_project(PROJECT* project, bool detaching) {
|
2005-04-13 22:52:05 +00:00
|
|
|
unsigned int i;
|
|
|
|
APP_VERSION* avp;
|
|
|
|
APP* app;
|
|
|
|
vector<APP*>::iterator app_iter;
|
|
|
|
vector<APP_VERSION*>::iterator avp_iter;
|
|
|
|
RESULT* rp;
|
|
|
|
PERS_FILE_XFER* pxp;
|
|
|
|
|
|
|
|
msg_printf(project, MSG_INFO, "Resetting project");
|
|
|
|
active_tasks.abort_project(project);
|
|
|
|
|
|
|
|
for (i=0; i<pers_file_xfers->pers_file_xfers.size(); i++) {
|
|
|
|
pxp = pers_file_xfers->pers_file_xfers[i];
|
|
|
|
if (pxp->fip->project == project) {
|
|
|
|
if (pxp->fxp) {
|
|
|
|
file_xfers->remove(pxp->fxp);
|
2007-02-20 04:18:02 +00:00
|
|
|
delete pxp->fxp;
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
pers_file_xfers->remove(pxp);
|
2007-02-20 04:18:02 +00:00
|
|
|
delete pxp;
|
2005-04-13 22:52:05 +00:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we're in the middle of a scheduler op to the project, abort it
|
|
|
|
//
|
2005-06-01 21:51:32 +00:00
|
|
|
scheduler_op->abort(project);
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
// mark results as server-acked.
|
|
|
|
// This will cause garbage_collect to delete them,
|
|
|
|
// and in turn their WUs will be deleted
|
|
|
|
//
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
rp = results[i];
|
|
|
|
if (rp->project == project) {
|
|
|
|
rp->got_server_ack = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-25 16:45:21 +00:00
|
|
|
project->user_files.clear();
|
|
|
|
project->project_files.clear();
|
|
|
|
|
2005-06-07 19:22:50 +00:00
|
|
|
garbage_collect_always();
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2005-04-13 23:28:47 +00:00
|
|
|
// forcibly remove apps and app_versions
|
|
|
|
// (but not if anonymous platform)
|
|
|
|
//
|
2007-12-03 17:46:07 +00:00
|
|
|
if (!project->anonymous_platform || detaching) {
|
2005-04-13 23:28:47 +00:00
|
|
|
avp_iter = app_versions.begin();
|
|
|
|
while (avp_iter != app_versions.end()) {
|
|
|
|
avp = *avp_iter;
|
|
|
|
if (avp->project == project) {
|
|
|
|
avp_iter = app_versions.erase(avp_iter);
|
|
|
|
delete avp;
|
|
|
|
} else {
|
|
|
|
avp_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
app_iter = apps.begin();
|
|
|
|
while (app_iter != apps.end()) {
|
|
|
|
app = *app_iter;
|
|
|
|
if (app->project == project) {
|
|
|
|
app_iter = apps.erase(app_iter);
|
|
|
|
delete app;
|
|
|
|
} else {
|
|
|
|
app_iter++;
|
|
|
|
}
|
|
|
|
}
|
2005-06-07 19:22:50 +00:00
|
|
|
garbage_collect_always();
|
2005-04-13 23:28:47 +00:00
|
|
|
}
|
2005-04-13 22:52:05 +00:00
|
|
|
|
2006-01-17 07:30:28 +00:00
|
|
|
project->duration_correction_factor = 1;
|
2007-01-29 16:19:51 +00:00
|
|
|
project->ams_resource_share = -1;
|
2005-04-13 22:52:05 +00:00
|
|
|
write_state_file();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "Detach" a project:
|
|
|
|
// - Reset (see above)
|
|
|
|
// - delete all file infos
|
|
|
|
// - delete account file
|
|
|
|
// - delete account directory
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::detach_project(PROJECT* project) {
|
|
|
|
vector<PROJECT*>::iterator project_iter;
|
|
|
|
vector<FILE_INFO*>::iterator fi_iter;
|
|
|
|
FILE_INFO* fip;
|
|
|
|
PROJECT* p;
|
|
|
|
char path[256];
|
|
|
|
int retval;
|
|
|
|
|
2007-12-03 17:46:07 +00:00
|
|
|
reset_project(project, true);
|
2005-04-13 22:52:05 +00:00
|
|
|
|
|
|
|
msg_printf(project, MSG_INFO, "Detaching from project");
|
|
|
|
|
|
|
|
// delete all FILE_INFOs associated with this project
|
|
|
|
//
|
|
|
|
fi_iter = file_infos.begin();
|
|
|
|
while (fi_iter != file_infos.end()) {
|
|
|
|
fip = *fi_iter;
|
|
|
|
if (fip->project == project) {
|
2006-10-02 17:44:27 +00:00
|
|
|
fi_iter = file_infos.erase(fi_iter);
|
2005-04-13 23:28:47 +00:00
|
|
|
delete fip;
|
2005-04-13 22:52:05 +00:00
|
|
|
} else {
|
|
|
|
fi_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if global prefs came from this project, delete file and reinit
|
|
|
|
//
|
|
|
|
p = lookup_project(global_prefs.source_project);
|
|
|
|
if (p == project) {
|
|
|
|
boinc_delete_file(GLOBAL_PREFS_FILE_NAME);
|
|
|
|
global_prefs.defaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
// find project and remove it from the vector
|
|
|
|
//
|
|
|
|
for (project_iter = projects.begin(); project_iter != projects.end(); project_iter++) {
|
|
|
|
p = *project_iter;
|
|
|
|
if (p == project) {
|
2006-10-02 17:44:27 +00:00
|
|
|
project_iter = projects.erase(project_iter);
|
2005-04-13 22:52:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-19 21:04:45 +00:00
|
|
|
// delete statistics file
|
2005-04-13 23:28:47 +00:00
|
|
|
//
|
|
|
|
get_statistics_filename(project->master_url, path);
|
2005-04-13 22:52:05 +00:00
|
|
|
retval = boinc_delete_file(path);
|
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Can't delete statistics file: %s", boincerror(retval)
|
2005-07-05 09:02:55 +00:00
|
|
|
);
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// delete account file
|
|
|
|
//
|
|
|
|
get_account_filename(project->master_url, path);
|
|
|
|
retval = boinc_delete_file(path);
|
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Can't delete account file: %s", boincerror(retval)
|
2005-07-05 09:02:55 +00:00
|
|
|
);
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
|
|
|
|
2007-03-13 19:33:27 +00:00
|
|
|
get_sched_request_filename(*project, path, sizeof(path));
|
2007-02-24 20:53:12 +00:00
|
|
|
retval = boinc_delete_file(path);
|
|
|
|
|
2007-03-13 19:33:27 +00:00
|
|
|
get_sched_reply_filename(*project, path, sizeof(path));
|
2007-02-24 20:53:12 +00:00
|
|
|
retval = boinc_delete_file(path);
|
|
|
|
|
2007-03-13 19:33:27 +00:00
|
|
|
get_master_filename(*project, path, sizeof(path));
|
2007-02-24 20:53:12 +00:00
|
|
|
retval = boinc_delete_file(path);
|
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
// remove project directory and its contents
|
|
|
|
//
|
|
|
|
retval = remove_project_dir(*project);
|
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Can't delete project directory: %s", boincerror(retval)
|
2005-07-05 09:02:55 +00:00
|
|
|
);
|
2005-04-13 22:52:05 +00:00
|
|
|
}
|
2005-09-22 08:46:51 +00:00
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
delete project;
|
|
|
|
write_state_file();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-17 16:38:53 +00:00
|
|
|
// Quit running applications, quit benchmarks,
|
|
|
|
// write the client_state.xml file
|
|
|
|
// (in principle we could also terminate net_xfers here,
|
|
|
|
// e.g. flush buffers, but why bother)
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::quit_activities() {
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
// calculate long-term debts (for state file)
|
|
|
|
//
|
|
|
|
adjust_debts();
|
|
|
|
|
|
|
|
retval = active_tasks.exit_tasks();
|
|
|
|
if (retval) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_INTERNAL_ERROR,
|
2006-07-17 16:38:53 +00:00
|
|
|
"Couldn't exit tasks: %s", boincerror(retval)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
write_state_file();
|
|
|
|
gui_rpcs.close();
|
|
|
|
abort_cpu_benchmarks();
|
2007-04-11 21:49:57 +00:00
|
|
|
time_stats.quit();
|
2006-07-17 16:38:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-27 20:03:51 +00:00
|
|
|
// return a random double in the range [rmin,rmax)
|
|
|
|
static inline double rand_range(double rmin, double rmax) {
|
|
|
|
if (rmin < rmax) {
|
|
|
|
return drand() * (rmax-rmin) + rmin;
|
|
|
|
} else {
|
|
|
|
return rmin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return a random double in the range [MIN,min(e^n,MAX))
|
|
|
|
//
|
2005-12-06 03:18:02 +00:00
|
|
|
double calculate_exponential_backoff( int n, double MIN, double MAX) {
|
|
|
|
double rmax = std::min(MAX, exp((double)n));
|
2005-10-27 20:03:51 +00:00
|
|
|
return rand_range(MIN, rmax);
|
|
|
|
}
|
|
|
|
|
2005-04-13 22:52:05 +00:00
|
|
|
const char *BOINC_RCSID_e836980ee1 = "$Id$";
|