2003-07-01 20:37:09 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-07-01 20:37:09 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-07-02 02:02:18 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2003-07-02 02:02:18 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
2003-07-01 20:37:09 +00:00
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-07-02 02:02:18 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-06-06 18:42:01 +00:00
|
|
|
#include "windows_cpp.h"
|
|
|
|
|
2002-12-09 23:51:55 +00:00
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
2003-02-05 19:32:44 +00:00
|
|
|
#if HAVE_SIGNAL_H
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_SIGNAL_H
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#endif
|
2002-12-09 23:51:55 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2003-07-29 23:26:32 +00:00
|
|
|
#include <cassert>
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
2002-12-18 21:05:18 +00:00
|
|
|
#include <stdlib.h>
|
2002-06-21 18:31:32 +00:00
|
|
|
#include <time.h>
|
2003-07-21 12:42:42 +00:00
|
|
|
#include <cassert>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-01-07 01:02:08 +00:00
|
|
|
#include "parse.h"
|
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "error_numbers.h"
|
2002-08-07 22:52:10 +00:00
|
|
|
#include "filesys.h"
|
2003-01-07 01:02:08 +00:00
|
|
|
|
|
|
|
#include "account.h"
|
|
|
|
#include "file_names.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "hostinfo.h"
|
2003-01-07 01:02:08 +00:00
|
|
|
#include "http.h"
|
2002-06-21 18:31:32 +00:00
|
|
|
#include "speed_stats.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "client_state.h"
|
2003-07-02 02:02:18 +00:00
|
|
|
#include "log_flags.h"
|
2003-07-21 12:42:43 +00:00
|
|
|
#include "maybe_gui.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-02-24 21:25:16 +00:00
|
|
|
#define BENCHMARK_PERIOD (SECONDS_PER_DAY*30)
|
|
|
|
// rerun CPU benchmarks this often (hardware may have been upgraded)
|
2002-06-21 18:31:32 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
CLIENT_STATE gstate;
|
|
|
|
|
|
|
|
CLIENT_STATE::CLIENT_STATE() {
|
|
|
|
net_xfers = new NET_XFER_SET;
|
|
|
|
http_ops = new HTTP_OP_SET(net_xfers);
|
|
|
|
file_xfers = new FILE_XFER_SET(http_ops);
|
2003-07-29 23:26:32 +00:00
|
|
|
pers_file_xfers = new PERS_FILE_XFER_SET(file_xfers);
|
2002-06-21 06:52:47 +00:00
|
|
|
scheduler_op = new SCHEDULER_OP(http_ops);
|
2002-04-30 22:22:54 +00:00
|
|
|
client_state_dirty = false;
|
|
|
|
exit_when_idle = false;
|
2003-08-14 00:02:15 +00:00
|
|
|
return_results_immediately = false;
|
2003-04-01 03:28:37 +00:00
|
|
|
run_cpu_benchmarks = false;
|
|
|
|
skip_cpu_benchmarks = false;
|
2003-03-16 21:59:11 +00:00
|
|
|
file_xfer_giveup_period = PERS_GIVEUP;
|
2002-04-30 22:22:54 +00:00
|
|
|
contacted_sched_server = false;
|
|
|
|
activities_suspended = false;
|
2003-07-29 05:46:10 +00:00
|
|
|
previous_activities_suspended = false;
|
2002-12-01 06:14:28 +00:00
|
|
|
core_client_major_version = MAJOR_VERSION;
|
|
|
|
core_client_minor_version = MINOR_VERSION;
|
2003-06-23 23:22:57 +00:00
|
|
|
platform_name = HOSTTYPE;
|
2003-02-12 19:53:46 +00:00
|
|
|
exit_after_app_start_secs = 0;
|
2002-07-31 19:05:15 +00:00
|
|
|
app_started = 0;
|
2003-03-31 23:18:55 +00:00
|
|
|
exit_before_upload = false;
|
2002-11-19 21:51:17 +00:00
|
|
|
user_idle = true;
|
2002-12-19 00:00:43 +00:00
|
|
|
use_http_proxy = false;
|
|
|
|
use_socks_proxy = false;
|
2003-05-15 17:10:26 +00:00
|
|
|
show_projects = false;
|
|
|
|
strcpy(detach_project_url, "");
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(proxy_server_name, "");
|
2002-12-18 21:05:18 +00:00
|
|
|
proxy_server_port = 80;
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(socks_user_name, "");
|
|
|
|
strcpy(socks_user_passwd, "");
|
|
|
|
strcpy(host_venue, "");
|
2003-07-30 22:02:54 +00:00
|
|
|
user_run_request = USER_RUN_REQUEST_AUTO;
|
2003-03-03 19:13:16 +00:00
|
|
|
start_saver = false;
|
2003-04-08 18:36:03 +00:00
|
|
|
requested_exit = false;
|
2002-12-09 23:51:55 +00:00
|
|
|
#ifdef _WIN32
|
2003-04-01 03:28:37 +00:00
|
|
|
cpu_benchmarks_handle = NULL;
|
2002-12-09 23:51:55 +00:00
|
|
|
#endif
|
2003-04-01 03:28:37 +00:00
|
|
|
cpu_benchmarks_id = 0;
|
2003-06-11 22:15:25 +00:00
|
|
|
master_fetch_period = MASTER_FETCH_PERIOD;
|
|
|
|
retry_base_period = RETRY_BASE_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;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2003-05-08 18:16:58 +00:00
|
|
|
#if 0
|
2003-04-01 07:36:19 +00:00
|
|
|
// Deallocate memory to prevent unneeded reporting of memory leaks
|
|
|
|
//
|
2003-03-19 18:46:58 +00:00
|
|
|
void CLIENT_STATE::free_mem() {
|
|
|
|
vector<PROJECT*>::iterator proj_iter;
|
|
|
|
vector<APP*>::iterator app_iter;
|
|
|
|
vector<FILE_INFO*>::iterator fi_iter;
|
|
|
|
vector<APP_VERSION*>::iterator av_iter;
|
|
|
|
vector<WORKUNIT*>::iterator wu_iter;
|
|
|
|
vector<RESULT*>::iterator res_iter;
|
2003-04-01 07:36:19 +00:00
|
|
|
PROJECT *proj;
|
|
|
|
APP *app;
|
|
|
|
FILE_INFO *fi;
|
|
|
|
APP_VERSION *av;
|
|
|
|
WORKUNIT *wu;
|
|
|
|
RESULT *res;
|
2003-03-19 18:46:58 +00:00
|
|
|
|
|
|
|
proj_iter = projects.begin();
|
|
|
|
while (proj_iter != projects.end()) {
|
2003-04-01 07:36:19 +00:00
|
|
|
proj = projects[0];
|
2003-03-19 18:46:58 +00:00
|
|
|
proj_iter = projects.erase(proj_iter);
|
2003-04-01 07:36:19 +00:00
|
|
|
delete proj;
|
2003-03-19 18:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app_iter = apps.begin();
|
|
|
|
while (app_iter != apps.end()) {
|
2003-04-01 07:36:19 +00:00
|
|
|
app = apps[0];
|
2003-03-19 18:46:58 +00:00
|
|
|
app_iter = apps.erase(app_iter);
|
2003-04-01 07:36:19 +00:00
|
|
|
delete app;
|
2003-03-19 18:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fi_iter = file_infos.begin();
|
|
|
|
while (fi_iter != file_infos.end()) {
|
2003-04-01 07:36:19 +00:00
|
|
|
fi = file_infos[0];
|
2003-03-19 18:46:58 +00:00
|
|
|
fi_iter = file_infos.erase(fi_iter);
|
2003-04-01 07:36:19 +00:00
|
|
|
delete fi;
|
2003-03-19 18:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
av_iter = app_versions.begin();
|
|
|
|
while (av_iter != app_versions.end()) {
|
2003-04-01 07:36:19 +00:00
|
|
|
av = app_versions[0];
|
2003-03-19 18:46:58 +00:00
|
|
|
av_iter = app_versions.erase(av_iter);
|
2003-04-01 07:36:19 +00:00
|
|
|
delete av;
|
2003-03-19 18:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wu_iter = workunits.begin();
|
|
|
|
while (wu_iter != workunits.end()) {
|
2003-04-01 07:36:19 +00:00
|
|
|
wu = workunits[0];
|
2003-03-19 18:46:58 +00:00
|
|
|
wu_iter = workunits.erase(wu_iter);
|
2003-04-01 07:36:19 +00:00
|
|
|
delete wu;
|
2003-03-19 18:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res_iter = results.begin();
|
|
|
|
while (res_iter != results.end()) {
|
2003-04-01 07:36:19 +00:00
|
|
|
res = results[0];
|
2003-03-19 18:46:58 +00:00
|
|
|
res_iter = results.erase(res_iter);
|
2003-04-01 07:36:19 +00:00
|
|
|
delete res;
|
2003-03-19 18:46:58 +00:00
|
|
|
}
|
|
|
|
|
2003-04-01 07:36:19 +00:00
|
|
|
active_tasks.free_mem();
|
2003-03-19 18:46:58 +00:00
|
|
|
}
|
2003-05-08 18:16:58 +00:00
|
|
|
#endif
|
2003-03-19 18:46:58 +00:00
|
|
|
|
2003-02-26 00:47:57 +00:00
|
|
|
void CLIENT_STATE::install_global_prefs() {
|
|
|
|
net_xfers->max_bytes_sec_up = global_prefs.max_bytes_sec_up;
|
|
|
|
net_xfers->max_bytes_sec_down = global_prefs.max_bytes_sec_down;
|
|
|
|
net_xfers->bytes_left_up = global_prefs.max_bytes_sec_up;
|
|
|
|
net_xfers->bytes_left_down = global_prefs.max_bytes_sec_down;
|
|
|
|
}
|
|
|
|
|
2002-08-12 23:18:47 +00:00
|
|
|
int CLIENT_STATE::init() {
|
|
|
|
int retval;
|
2003-02-20 00:58:55 +00:00
|
|
|
unsigned int i;
|
2002-08-12 23:18:47 +00:00
|
|
|
|
2002-12-05 21:56:33 +00:00
|
|
|
srand(time(NULL));
|
2002-09-26 05:57:10 +00:00
|
|
|
|
2003-06-04 17:42:37 +00:00
|
|
|
language.read_language_file(LANGUAGE_FILE_NAME);
|
2003-05-29 23:27:39 +00:00
|
|
|
|
2003-08-11 03:49:19 +00:00
|
|
|
// printing the platform name here helps bug reports because users often
|
|
|
|
// give us this line but don't say what platform they have
|
|
|
|
msg_printf(NULL, MSG_INFO, "Starting BOINC client version %d.%02d (%s)",
|
|
|
|
core_client_major_version, core_client_minor_version, platform_name
|
|
|
|
);
|
2003-08-01 21:50:09 +00:00
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
// parse account files.
|
|
|
|
// If there are none, prompt user for project URL and create file
|
2002-12-19 22:43:38 +00:00
|
|
|
//
|
2002-09-26 05:57:10 +00:00
|
|
|
retval = parse_account_files();
|
|
|
|
if (projects.size() == 0) {
|
2002-12-19 22:43:38 +00:00
|
|
|
retval = add_new_project();
|
2002-09-26 05:57:10 +00:00
|
|
|
if (retval) {
|
|
|
|
printf("can't get initial project\n");
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
retval = parse_account_files();
|
|
|
|
if (projects.size() == 0) {
|
|
|
|
if (retval) {
|
|
|
|
printf("can't get initial project\n");
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
// Parse the client state file,
|
2002-06-21 06:52:47 +00:00
|
|
|
// ignoring any <project> tags (and associated stuff)
|
2002-09-26 05:57:10 +00:00
|
|
|
// for projects with no account file
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2002-12-09 23:51:55 +00:00
|
|
|
clear_host_info(host_info);
|
2002-06-21 06:52:47 +00:00
|
|
|
parse_state_file();
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-07-02 02:02:18 +00:00
|
|
|
print_summary();
|
2002-12-19 22:43:38 +00:00
|
|
|
|
2003-05-15 17:10:26 +00:00
|
|
|
if (show_projects) {
|
|
|
|
printf("projects:\n");
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
2003-09-04 00:41:51 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "URL: %s name: %s\n",
|
2003-05-15 17:10:26 +00:00
|
|
|
projects[i]->master_url, projects[i]->project_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(detach_project_url)) {
|
|
|
|
PROJECT* project = lookup_project(detach_project_url);
|
|
|
|
if (project) {
|
|
|
|
detach_project(project);
|
2003-09-04 00:41:51 +00:00
|
|
|
msg_printf(project, MSG_INFO, "detached from %s\n", detach_project_url);
|
2003-05-15 17:10:26 +00:00
|
|
|
} else {
|
2003-09-04 00:41:51 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "project %s not found\n", detach_project_url);
|
2003-05-15 17:10:26 +00:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(reset_project_url)) {
|
|
|
|
PROJECT* project = lookup_project(reset_project_url);
|
|
|
|
if (project) {
|
|
|
|
reset_project(project);
|
2003-09-04 00:41:51 +00:00
|
|
|
msg_printf(project, MSG_INFO, "Project %s has been reset", reset_project_url);
|
2003-05-15 17:10:26 +00:00
|
|
|
} else {
|
2003-09-04 00:41:51 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "project %s not found\n", reset_project_url);
|
2003-05-15 17:10:26 +00:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(update_prefs_url)) {
|
|
|
|
PROJECT* project = lookup_project(update_prefs_url);
|
|
|
|
if (project) {
|
|
|
|
project->sched_rpc_pending = true;
|
|
|
|
} else {
|
2003-09-04 00:41:51 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "project %s not found\n", update_prefs_url);
|
2003-05-15 17:10:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (core_client_major_version != old_major_version) {
|
2003-06-11 22:15:25 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"State file has different major version (%d.%02d); resetting projects\n",
|
|
|
|
old_major_version, old_minor_version
|
|
|
|
);
|
2003-05-15 17:10:26 +00:00
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
reset_project(projects[i]);
|
|
|
|
}
|
|
|
|
}
|
2003-05-09 20:33:57 +00:00
|
|
|
|
2003-03-06 00:42:18 +00:00
|
|
|
// Read the global preferences file, if it exists.
|
|
|
|
// Do this after reading the state file so we know our venue
|
|
|
|
//
|
|
|
|
retval = global_prefs.parse_file(host_venue);
|
|
|
|
if (retval) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Using default preferences");
|
2003-03-06 00:42:18 +00:00
|
|
|
}
|
|
|
|
install_global_prefs();
|
2002-12-05 22:50:21 +00:00
|
|
|
|
|
|
|
// Getting host info is very fast, so we can do it anytime
|
2003-03-06 00:42:18 +00:00
|
|
|
//
|
2003-02-20 00:58:55 +00:00
|
|
|
get_host_info(host_info);
|
2002-12-05 22:50:21 +00:00
|
|
|
|
2003-03-06 00:42:18 +00:00
|
|
|
// running CPU benchmarks is slow, so do it infrequently
|
|
|
|
//
|
2003-05-30 17:59:14 +00:00
|
|
|
if (should_run_cpu_benchmarks()) {
|
2003-07-21 12:42:43 +00:00
|
|
|
fork_run_cpu_benchmarks();
|
2002-08-12 23:18:47 +00:00
|
|
|
}
|
2002-12-16 22:34:50 +00:00
|
|
|
|
2003-05-30 17:59:14 +00:00
|
|
|
set_nslots();
|
2002-12-19 22:43:38 +00:00
|
|
|
|
2002-12-17 00:23:45 +00:00
|
|
|
// set up the project and slot directories
|
|
|
|
//
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = make_project_dirs();
|
|
|
|
if (retval) return retval;
|
2002-12-17 00:23:45 +00:00
|
|
|
|
2002-08-12 23:18:47 +00:00
|
|
|
// Restart any tasks that were running when we last quit the client
|
2003-02-20 00:58:55 +00:00
|
|
|
//
|
2003-05-30 17:59:14 +00:00
|
|
|
restart_tasks();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-29 23:26:32 +00:00
|
|
|
void CLIENT_STATE::fork_run_cpu_benchmarks() {
|
2003-07-21 12:42:43 +00:00
|
|
|
cpu_benchmarks_start = time(0);
|
|
|
|
msg_printf(NULL, MSG_INFO, "Running CPU benchmarks");
|
|
|
|
#ifdef _WIN32
|
|
|
|
cpu_benchmarks_handle = CreateThread(
|
|
|
|
NULL, 0, win_cpu_benchmarks, NULL, 0, &cpu_benchmarks_id
|
|
|
|
);
|
|
|
|
#else
|
|
|
|
cpu_benchmarks_id = fork();
|
|
|
|
if (cpu_benchmarks_id == 0) {
|
|
|
|
_exit(cpu_benchmarks());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-05-30 17:59:14 +00:00
|
|
|
int CLIENT_STATE::set_nslots() {
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
// Set nslots to actual # of CPUs (or less, depending on prefs)
|
|
|
|
//
|
|
|
|
if (host_info.p_ncpus > 0) {
|
|
|
|
nslots = host_info.p_ncpus;
|
|
|
|
} else {
|
|
|
|
nslots = 1;
|
|
|
|
}
|
|
|
|
if (nslots > global_prefs.max_cpus) nslots = global_prefs.max_cpus;
|
2002-08-12 23:18:47 +00:00
|
|
|
|
2003-05-30 17:59:14 +00:00
|
|
|
retval = make_slot_dirs();
|
|
|
|
if (retval) return retval;
|
2003-06-11 21:50:54 +00:00
|
|
|
|
2002-06-28 18:32:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-01 03:28:37 +00:00
|
|
|
// Returns true if CPU benchmarks should be run:
|
|
|
|
// flag is set or it's been a month since we last ran
|
2002-06-28 18:32:18 +00:00
|
|
|
//
|
2003-04-01 03:28:37 +00:00
|
|
|
bool CLIENT_STATE::should_run_cpu_benchmarks() {
|
2003-06-11 21:50:54 +00:00
|
|
|
// Note: we if skip_cpu_benchmarks we still should "run" cpu benchmarks
|
|
|
|
// (we'll just use default values in cpu_benchmarks())
|
2003-01-13 23:37:56 +00:00
|
|
|
return (
|
2003-06-11 21:50:54 +00:00
|
|
|
run_cpu_benchmarks ||
|
|
|
|
(difftime(time(0), (time_t)host_info.p_calculated) > BENCHMARK_PERIOD)
|
2003-01-13 23:37:56 +00:00
|
|
|
);
|
2002-06-28 18:32:18 +00:00
|
|
|
}
|
|
|
|
|
2002-12-09 23:51:55 +00:00
|
|
|
#ifdef _WIN32
|
2003-04-01 03:28:37 +00:00
|
|
|
DWORD WINAPI CLIENT_STATE::win_cpu_benchmarks(LPVOID) {
|
2003-06-02 22:13:34 +00:00
|
|
|
return gstate.cpu_benchmarks();
|
2002-12-09 23:51:55 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
// gets info about the host
|
|
|
|
// NOTE: this locks up the process for 10-20 seconds,
|
|
|
|
// so it should be called very seldom
|
2002-06-28 18:32:18 +00:00
|
|
|
//
|
2003-04-01 03:28:37 +00:00
|
|
|
int CLIENT_STATE::cpu_benchmarks() {
|
2003-01-07 01:02:08 +00:00
|
|
|
HOST_INFO host_info;
|
|
|
|
FILE* finfo;
|
2003-03-20 19:16:28 +00:00
|
|
|
double fpop_test_secs = 3.3;
|
|
|
|
double iop_test_secs = 3.3;
|
|
|
|
double mem_test_secs = 3.3;
|
2002-08-30 21:32:31 +00:00
|
|
|
|
2003-07-02 02:02:18 +00:00
|
|
|
ScopeMessages scope_messages(log_messages, ClientMessages::DEBUG_MEASUREMENT);
|
|
|
|
scope_messages.printf("CLIENT_STATE::cpu_benchmarks(): Running CPU benchmarks.\n");
|
|
|
|
|
2003-07-21 12:42:43 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
guiOnBenchmarksBegin();
|
|
|
|
#endif
|
|
|
|
|
2003-01-13 23:37:56 +00:00
|
|
|
clear_host_info(host_info);
|
2003-07-02 02:02:18 +00:00
|
|
|
++log_messages;
|
2003-04-01 03:28:37 +00:00
|
|
|
if (skip_cpu_benchmarks) {
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("CLIENT_STATE::cpu_benchmarks(): Skipping CPU benchmarks.\n");
|
2003-04-01 03:28:37 +00:00
|
|
|
host_info.p_fpops = 1e9;
|
|
|
|
host_info.p_iops = 1e9;
|
|
|
|
host_info.p_membw = 4e9;
|
|
|
|
host_info.m_cache = 1e6;
|
|
|
|
} else {
|
2003-07-29 23:26:32 +00:00
|
|
|
scope_messages.printf(
|
|
|
|
"CLIENT_STATE::cpu_benchmarks(): Running floating point test for about %.1f seconds.\n",
|
|
|
|
fpop_test_secs
|
|
|
|
);
|
2003-07-01 23:16:53 +00:00
|
|
|
host_info.p_fpop_err = run_double_prec_test(fpop_test_secs, host_info.p_fpops);
|
2002-08-30 21:32:31 +00:00
|
|
|
|
2003-07-29 23:26:32 +00:00
|
|
|
scope_messages.printf(
|
|
|
|
"CLIENT_STATE::cpu_benchmarks(): Running integer test for about %.1f seconds.\n",
|
|
|
|
iop_test_secs
|
|
|
|
);
|
2003-07-01 23:16:53 +00:00
|
|
|
host_info.p_iop_err = run_int_test(iop_test_secs, host_info.p_iops);
|
2002-08-30 21:32:31 +00:00
|
|
|
|
2003-07-29 23:26:32 +00:00
|
|
|
scope_messages.printf(
|
|
|
|
"CLIENT_STATE::cpu_benchmarks(): Running memory bandwidth test for about %.1f seconds.\n",
|
|
|
|
mem_test_secs
|
|
|
|
);
|
2003-07-01 23:16:53 +00:00
|
|
|
host_info.p_membw_err = run_mem_bandwidth_test(mem_test_secs, host_info.p_membw);
|
2002-12-09 23:51:55 +00:00
|
|
|
|
2003-03-20 19:16:28 +00:00
|
|
|
// need to check cache!!
|
2003-01-13 23:37:56 +00:00
|
|
|
host_info.m_cache = 1e6;
|
2003-07-21 12:42:43 +00:00
|
|
|
|
2003-08-08 22:51:02 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Benchmark results: FP: %.0f million op/sec%s; Int: %.0f million op/sec%s; Mem BW: %.0f million bytes/sec%s",
|
2003-08-01 08:00:55 +00:00
|
|
|
host_info.p_fpops/1e6, (host_info.p_fpop_err?" [ERROR]":""),
|
|
|
|
host_info.p_iops/1e6, (host_info.p_iop_err?" [ERROR]":""),
|
|
|
|
host_info.p_membw/1e6, (host_info.p_membw_err?" [ERROR]":"")
|
2003-07-29 23:26:32 +00:00
|
|
|
);
|
2003-01-13 23:37:56 +00:00
|
|
|
}
|
2002-08-30 21:32:31 +00:00
|
|
|
|
2002-10-20 22:12:53 +00:00
|
|
|
host_info.p_calculated = (double)time(0);
|
2003-04-01 03:28:37 +00:00
|
|
|
finfo = fopen(CPU_BENCHMARKS_FILE_NAME, "w");
|
2003-01-13 23:37:56 +00:00
|
|
|
if(!finfo) return ERR_FOPEN;
|
2003-04-01 03:28:37 +00:00
|
|
|
host_info.write_cpu_benchmarks(finfo);
|
2003-01-13 23:37:56 +00:00
|
|
|
fclose(finfo);
|
2003-07-21 12:42:43 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
guiOnBenchmarksEnd();
|
|
|
|
#endif
|
2003-07-02 02:02:18 +00:00
|
|
|
--log_messages;
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-01 03:28:37 +00:00
|
|
|
// checks if the CPU benchmarks are running
|
2002-12-19 22:43:38 +00:00
|
|
|
//
|
2003-04-01 03:28:37 +00:00
|
|
|
int CLIENT_STATE::check_cpu_benchmarks() {
|
2003-01-07 01:02:08 +00:00
|
|
|
FILE* finfo;
|
2003-03-08 23:48:05 +00:00
|
|
|
int retval;
|
2003-06-11 21:50:54 +00:00
|
|
|
|
2003-04-01 03:28:37 +00:00
|
|
|
if (cpu_benchmarks_id) {
|
2002-12-09 23:51:55 +00:00
|
|
|
#ifdef _WIN32
|
2003-01-07 01:02:08 +00:00
|
|
|
DWORD exit_code = 0;
|
2003-04-01 03:28:37 +00:00
|
|
|
GetExitCodeThread(cpu_benchmarks_handle, &exit_code);
|
2003-02-03 22:46:09 +00:00
|
|
|
if(exit_code == STILL_ACTIVE) {
|
2003-04-01 03:28:37 +00:00
|
|
|
if(time(NULL) > cpu_benchmarks_start + MAX_CPU_BENCHMARKS_SECONDS) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "CPU benchmarks timed out, using default values");
|
2003-04-01 03:28:37 +00:00
|
|
|
TerminateThread(cpu_benchmarks_handle, 0);
|
|
|
|
CloseHandle(cpu_benchmarks_handle);
|
2003-02-06 19:01:49 +00:00
|
|
|
host_info.p_fpops = 1e9;
|
|
|
|
host_info.p_iops = 1e9;
|
|
|
|
host_info.p_membw = 4e9;
|
|
|
|
host_info.m_cache = 1e6;
|
2003-04-01 03:28:37 +00:00
|
|
|
cpu_benchmarks_id = 0;
|
|
|
|
return CPU_BENCHMARKS_ERROR;
|
2003-02-06 19:01:49 +00:00
|
|
|
}
|
2003-04-01 03:28:37 +00:00
|
|
|
return CPU_BENCHMARKS_RUNNING;
|
2003-02-06 19:01:49 +00:00
|
|
|
}
|
2003-04-01 03:28:37 +00:00
|
|
|
CloseHandle(cpu_benchmarks_handle);
|
2003-07-21 12:42:43 +00:00
|
|
|
guiOnBenchmarksEnd();
|
2002-12-09 23:51:55 +00:00
|
|
|
#else
|
2003-03-08 23:48:05 +00:00
|
|
|
int exit_code = 0;
|
2003-04-01 03:28:37 +00:00
|
|
|
retval = waitpid(cpu_benchmarks_id, &exit_code, WNOHANG);
|
2003-02-03 22:46:09 +00:00
|
|
|
if(retval == 0) {
|
2003-04-01 03:28:37 +00:00
|
|
|
if((unsigned int)time(NULL) > cpu_benchmarks_start + MAX_CPU_BENCHMARKS_SECONDS) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "CPU benchmarks timed out, using default values");
|
2003-04-01 03:28:37 +00:00
|
|
|
kill(cpu_benchmarks_id, SIGKILL);
|
2003-02-06 19:01:49 +00:00
|
|
|
host_info.p_fpops = 1e9;
|
|
|
|
host_info.p_iops = 1e9;
|
|
|
|
host_info.p_membw = 4e9;
|
|
|
|
host_info.m_cache = 1e6;
|
2003-04-01 03:28:37 +00:00
|
|
|
cpu_benchmarks_id = 0;
|
|
|
|
return CPU_BENCHMARKS_ERROR;
|
2003-02-06 19:01:49 +00:00
|
|
|
}
|
2003-04-01 03:28:37 +00:00
|
|
|
return CPU_BENCHMARKS_RUNNING;
|
2003-02-06 19:01:49 +00:00
|
|
|
}
|
2002-12-09 23:51:55 +00:00
|
|
|
#endif
|
2003-04-01 03:28:37 +00:00
|
|
|
cpu_benchmarks_id = 0;
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "CPU benchmarks complete");
|
2003-04-01 03:28:37 +00:00
|
|
|
finfo = fopen(CPU_BENCHMARKS_FILE_NAME, "r");
|
2003-03-06 17:42:49 +00:00
|
|
|
if (!finfo) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "Can't open CPU benchmark file, using default values");
|
2003-02-06 19:01:49 +00:00
|
|
|
host_info.p_fpops = 1e9;
|
|
|
|
host_info.p_iops = 1e9;
|
|
|
|
host_info.p_membw = 4e9;
|
|
|
|
host_info.m_cache = 1e6;
|
2003-04-01 03:28:37 +00:00
|
|
|
return CPU_BENCHMARKS_ERROR;
|
2003-02-06 19:01:49 +00:00
|
|
|
}
|
2003-04-01 03:28:37 +00:00
|
|
|
retval = host_info.parse_cpu_benchmarks(finfo);
|
2003-01-07 01:02:08 +00:00
|
|
|
fclose(finfo);
|
2003-04-01 03:28:37 +00:00
|
|
|
if (retval) return CPU_BENCHMARKS_ERROR;
|
|
|
|
file_delete(CPU_BENCHMARKS_FILE_NAME);
|
|
|
|
return CPU_BENCHMARKS_COMPLETE;
|
2003-01-07 01:02:08 +00:00
|
|
|
}
|
2003-04-01 03:28:37 +00:00
|
|
|
return CPU_BENCHMARKS_NOT_RUNNING;
|
2002-12-09 23:51:55 +00:00
|
|
|
}
|
|
|
|
|
2002-08-07 22:52:10 +00:00
|
|
|
// Return the maximum allowed disk usage as determined by user preferences.
|
2003-05-22 20:47:56 +00:00
|
|
|
// There are three different settings in the prefs;
|
|
|
|
// return the least of the three.
|
2002-12-19 22:43:38 +00:00
|
|
|
//
|
2002-12-06 07:33:45 +00:00
|
|
|
int CLIENT_STATE::allowed_disk_usage(double& size) {
|
2002-08-12 00:51:42 +00:00
|
|
|
double percent_space, min_val;
|
2002-08-07 22:52:10 +00:00
|
|
|
|
2002-12-05 22:50:21 +00:00
|
|
|
percent_space = host_info.d_total*global_prefs.disk_max_used_pct;
|
2002-09-29 00:32:11 +00:00
|
|
|
|
2003-05-29 23:25:15 +00:00
|
|
|
min_val = host_info.d_free - global_prefs.disk_min_free_gb*(1024.*1024.*1024.);
|
2002-08-07 22:52:10 +00:00
|
|
|
|
2003-05-29 23:25:15 +00:00
|
|
|
size = min(min(global_prefs.disk_max_used_gb*(1024.*1024.*1024.), percent_space), min_val);
|
2003-02-27 09:21:22 +00:00
|
|
|
if(size < 0) size = 0;
|
2002-12-06 07:33:45 +00:00
|
|
|
return 0;
|
2002-08-07 22:52:10 +00:00
|
|
|
}
|
|
|
|
|
2002-12-19 00:37:19 +00:00
|
|
|
int CLIENT_STATE::project_disk_usage(PROJECT* p, double& size) {
|
|
|
|
char buf[256],buf2[256];
|
|
|
|
|
|
|
|
escape_project_url(p->master_url, buf);
|
|
|
|
sprintf(buf2, "%s%s%s", PROJECTS_DIR, PATH_SEPARATOR, buf);
|
|
|
|
|
|
|
|
return dir_size(buf2, size);
|
|
|
|
}
|
|
|
|
|
2002-12-06 07:33:45 +00:00
|
|
|
int CLIENT_STATE::current_disk_usage(double& size) {
|
|
|
|
return dir_size(".", size);
|
2002-11-02 00:38:11 +00:00
|
|
|
}
|
|
|
|
|
2003-05-22 20:47:56 +00:00
|
|
|
// estimate how long a WU will take on this host
|
|
|
|
//
|
|
|
|
double CLIENT_STATE::estimate_cpu_time(WORKUNIT& wu) {
|
|
|
|
double x;
|
|
|
|
|
2003-09-04 00:41:51 +00:00
|
|
|
x = wu.rsc_fpops_est/host_info.p_fpops;
|
2003-05-22 20:47:56 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2003-09-04 00:41:51 +00:00
|
|
|
inline double force_fraction(double f) {
|
2003-08-12 20:28:55 +00:00
|
|
|
if (f < 0) return 0;
|
|
|
|
if (f > 1) return 1;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2003-09-04 00:41:51 +00:00
|
|
|
double CLIENT_STATE::get_percent_done(RESULT* result) {
|
2003-08-12 20:28:55 +00:00
|
|
|
ACTIVE_TASK* atp = active_tasks.lookup_result(result);
|
|
|
|
return atp ? force_fraction(atp->fraction_done) : 0.0;
|
|
|
|
}
|
|
|
|
|
2003-07-21 12:42:44 +00:00
|
|
|
// returns true if start_hour == end_hour or start_hour <= now < end_hour
|
2003-09-04 00:41:51 +00:00
|
|
|
//
|
|
|
|
inline bool now_between_two_hours(int start_hour, int end_hour) {
|
2003-07-21 12:42:44 +00:00
|
|
|
if (start_hour == end_hour) {
|
|
|
|
// always work
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t now = time(0);
|
2003-07-29 04:56:28 +00:00
|
|
|
struct tm *tmp = localtime(&now);
|
2003-07-21 12:42:44 +00:00
|
|
|
int hour = tmp->tm_hour;
|
|
|
|
if (start_hour < end_hour) {
|
|
|
|
return (hour >= start_hour && hour < end_hour);
|
|
|
|
} else {
|
|
|
|
return !(hour >= end_hour && hour < start_hour);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-01 20:25:50 +00:00
|
|
|
enum SUSPEND_REASON_t {
|
|
|
|
SUSPEND_REASON_BATTERIES = 1,
|
|
|
|
SUSPEND_REASON_USER_ACTIVE = 2,
|
|
|
|
SUSPEND_REASON_USER_REQ = 4,
|
|
|
|
SUSPEND_REASON_TIME_OF_DAY = 8,
|
|
|
|
SUSPEND_REASON_BENCHMARKS = 16
|
|
|
|
};
|
2003-07-29 23:26:32 +00:00
|
|
|
|
2003-07-30 22:02:54 +00:00
|
|
|
// See if (on the basis of user run request and prefs)
|
|
|
|
// we should suspend activities.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2003-08-01 20:25:50 +00:00
|
|
|
void CLIENT_STATE::check_suspend_activities(int& reason) {
|
2003-07-29 23:26:32 +00:00
|
|
|
reason = 0;
|
|
|
|
|
2003-08-01 21:50:07 +00:00
|
|
|
// Don't work while we're running CPU benchmarks
|
|
|
|
//
|
|
|
|
if (check_cpu_benchmarks() == CPU_BENCHMARKS_RUNNING) {
|
|
|
|
reason |= SUSPEND_REASON_BENCHMARKS;
|
|
|
|
}
|
|
|
|
|
2003-08-01 20:25:50 +00:00
|
|
|
if (user_run_request == USER_RUN_REQUEST_ALWAYS) return;
|
2003-07-30 22:02:54 +00:00
|
|
|
|
|
|
|
if (user_run_request == USER_RUN_REQUEST_NEVER) {
|
2003-08-01 21:50:07 +00:00
|
|
|
reason |= SUSPEND_REASON_USER_REQ;
|
2003-08-01 20:25:50 +00:00
|
|
|
return;
|
2003-07-30 22:02:54 +00:00
|
|
|
}
|
|
|
|
|
2003-02-21 01:38:16 +00:00
|
|
|
if (!global_prefs.run_on_batteries && host_is_running_on_batteries()) {
|
2003-07-29 23:26:32 +00:00
|
|
|
reason |= SUSPEND_REASON_BATTERIES;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-03-03 19:13:16 +00:00
|
|
|
|
2003-07-30 22:02:54 +00:00
|
|
|
// user_idle is set in the Mac/Win GUI code
|
2003-03-25 01:30:13 +00:00
|
|
|
//
|
2003-07-29 04:56:28 +00:00
|
|
|
if (!global_prefs.run_if_user_active && !user_idle) {
|
2003-07-29 23:26:32 +00:00
|
|
|
reason |= SUSPEND_REASON_USER_ACTIVE;
|
2002-11-19 22:57:05 +00:00
|
|
|
}
|
2003-03-25 01:30:13 +00:00
|
|
|
|
2003-07-21 12:42:44 +00:00
|
|
|
if (!now_between_two_hours(global_prefs.start_hour, global_prefs.end_hour)) {
|
2003-07-29 23:26:32 +00:00
|
|
|
reason |= SUSPEND_REASON_TIME_OF_DAY;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-08-01 20:25:50 +00:00
|
|
|
|
|
|
|
return;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2003-05-16 19:22:57 +00:00
|
|
|
// sleep up to x seconds,
|
|
|
|
// but if network I/O becomes possible,
|
|
|
|
// wake up and do as much as limits allow.
|
2003-08-31 22:28:16 +00:00
|
|
|
// If suspended, just sleep x seconds.
|
|
|
|
// This gets called from the Win GUI to allow high network throughput.
|
|
|
|
// NOTE: when a socket is connecting, this gets called repeatedly,
|
|
|
|
// because the NetActivity messages seems to get sent repeatedly.
|
|
|
|
// This is inefficient but not a problem (I guess)
|
2003-05-16 19:22:57 +00:00
|
|
|
//
|
2003-02-18 03:31:47 +00:00
|
|
|
int CLIENT_STATE::net_sleep(double x) {
|
2003-08-31 22:28:16 +00:00
|
|
|
ScopeMessages scope_messages(log_messages, ClientMessages::DEBUG_NET_XFER);
|
|
|
|
scope_messages.printf("CLIENT_STATE::net_sleep(%f)\n", x);
|
2003-03-06 18:58:22 +00:00
|
|
|
if (activities_suspended) {
|
2003-03-11 22:18:01 +00:00
|
|
|
boinc_sleep(x);
|
2003-03-06 18:58:22 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return net_xfers->net_sleep(x);
|
|
|
|
}
|
2003-02-18 03:31:47 +00:00
|
|
|
}
|
|
|
|
|
2003-07-29 23:26:32 +00:00
|
|
|
int CLIENT_STATE::suspend_activities(int reason) {
|
2003-08-01 20:25:50 +00:00
|
|
|
string s_reason;
|
|
|
|
s_reason = "Suspending computation and file transfer";
|
2003-07-29 23:26:32 +00:00
|
|
|
if (reason & SUSPEND_REASON_BATTERIES) {
|
2003-08-01 20:25:50 +00:00
|
|
|
s_reason += " - on batteries";
|
2003-07-29 23:26:32 +00:00
|
|
|
}
|
|
|
|
if (reason & SUSPEND_REASON_USER_ACTIVE) {
|
2003-08-01 20:25:50 +00:00
|
|
|
s_reason += " - user is active";
|
2003-07-29 23:26:32 +00:00
|
|
|
}
|
|
|
|
if (reason & SUSPEND_REASON_USER_REQ) {
|
2003-08-01 20:25:50 +00:00
|
|
|
s_reason += " - user request";
|
2003-07-29 23:26:32 +00:00
|
|
|
}
|
|
|
|
if (reason & SUSPEND_REASON_TIME_OF_DAY) {
|
2003-08-01 20:25:50 +00:00
|
|
|
s_reason += " - time of day";
|
|
|
|
}
|
|
|
|
if (reason & SUSPEND_REASON_BENCHMARKS) {
|
|
|
|
s_reason += " - running CPU benchmarks";
|
2003-07-29 23:26:32 +00:00
|
|
|
}
|
2003-08-01 20:25:50 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, const_cast<char*>(s_reason.c_str()));
|
2003-07-29 23:26:32 +00:00
|
|
|
active_tasks.suspend_all();
|
|
|
|
pers_file_xfers->suspend();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// persistent file xfers will resume of their own accord
|
|
|
|
// since activities_suspended is now true
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::resume_activities() {
|
|
|
|
msg_printf(NULL, MSG_INFO, "Resuming activity");
|
|
|
|
active_tasks.unsuspend_all();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define POLL_ACTION(name, func) \
|
|
|
|
do { if (func()) { \
|
|
|
|
++actions; \
|
2003-08-01 21:50:09 +00:00
|
|
|
scope_messages.printf("CLIENT_STATE::do_something(): active task: " #name "\n"); \
|
2003-07-29 23:26:32 +00:00
|
|
|
} } while(0)
|
|
|
|
|
2003-02-18 03:31:47 +00:00
|
|
|
// do_something polls each of the client's finite-state machine layers,
|
2003-01-07 22:49:42 +00:00
|
|
|
// possibly triggering state transitions.
|
|
|
|
// Returns true if something happened
|
2003-02-18 03:31:47 +00:00
|
|
|
// (in which case should call this again immediately)
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
|
|
|
bool CLIENT_STATE::do_something() {
|
2003-07-29 23:26:32 +00:00
|
|
|
int actions = 0, reason;
|
|
|
|
ScopeMessages scope_messages(log_messages, ClientMessages::DEBUG_POLL);
|
2003-01-07 22:49:42 +00:00
|
|
|
|
2003-07-29 23:26:32 +00:00
|
|
|
check_suspend_activities(reason);
|
|
|
|
if (reason) {
|
|
|
|
if (!activities_suspended) {
|
|
|
|
suspend_activities(reason);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (activities_suspended) {
|
|
|
|
resume_activities();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
previous_activities_suspended = activities_suspended;
|
|
|
|
activities_suspended = (reason != 0);
|
|
|
|
|
2003-08-01 20:25:50 +00:00
|
|
|
// if we're doing CPU benchmarks, don't do anything else
|
|
|
|
//
|
|
|
|
if (reason & SUSPEND_REASON_BENCHMARKS) return false;
|
|
|
|
|
2003-08-01 21:50:09 +00:00
|
|
|
scope_messages.printf("CLIENT_STATE::do_something(): Begin poll:\n");
|
2003-07-02 02:02:18 +00:00
|
|
|
++scope_messages;
|
2003-06-05 23:07:38 +00:00
|
|
|
|
2003-07-29 23:26:32 +00:00
|
|
|
ss_logic.poll();
|
2003-01-07 22:49:42 +00:00
|
|
|
if (activities_suspended) {
|
2003-08-01 21:50:09 +00:00
|
|
|
scope_messages.printf("CLIENT_STATE::do_something(): No active tasks! (suspended)\n");
|
2003-07-29 23:26:32 +00:00
|
|
|
POLL_ACTION(net_xfers , net_xfers->poll );
|
|
|
|
POLL_ACTION(http_ops , http_ops->poll );
|
|
|
|
POLL_ACTION(scheduler_rpc , scheduler_rpc_poll );
|
2003-08-01 22:58:40 +00:00
|
|
|
POLL_ACTION(garbage_collect , garbage_collect );
|
|
|
|
POLL_ACTION(update_results , update_results );
|
2003-01-07 22:49:42 +00:00
|
|
|
} else {
|
2003-07-29 23:26:32 +00:00
|
|
|
net_stats.poll(*net_xfers);
|
2002-08-28 21:50:51 +00:00
|
|
|
// Call these functions in bottom to top order with
|
|
|
|
// respect to the FSM hierarchy
|
2003-07-29 23:26:32 +00:00
|
|
|
//
|
2003-07-02 02:02:18 +00:00
|
|
|
POLL_ACTION(net_xfers , net_xfers->poll );
|
|
|
|
POLL_ACTION(http_ops , http_ops->poll );
|
|
|
|
POLL_ACTION(file_xfers , file_xfers->poll );
|
|
|
|
POLL_ACTION(active_tasks , active_tasks.poll );
|
|
|
|
POLL_ACTION(scheduler_rpc , scheduler_rpc_poll );
|
|
|
|
POLL_ACTION(start_apps , start_apps );
|
2003-07-29 23:26:32 +00:00
|
|
|
POLL_ACTION(pers_file_xfers , pers_file_xfers->poll );
|
2003-07-02 02:02:18 +00:00
|
|
|
POLL_ACTION(handle_finished_apps , handle_finished_apps );
|
|
|
|
POLL_ACTION(handle_pers_file_xfers , handle_pers_file_xfers );
|
|
|
|
POLL_ACTION(garbage_collect , garbage_collect );
|
|
|
|
POLL_ACTION(update_results , update_results );
|
2003-07-29 23:26:32 +00:00
|
|
|
}
|
2002-08-28 21:50:51 +00:00
|
|
|
|
2003-07-29 23:26:32 +00:00
|
|
|
if (write_state_file_if_needed()) {
|
|
|
|
msg_printf(NULL, MSG_ERROR, "Couldn't write state file");
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-07-02 02:02:18 +00:00
|
|
|
--log_messages;
|
2003-07-29 23:26:32 +00:00
|
|
|
scope_messages.printf(
|
2003-08-01 21:50:09 +00:00
|
|
|
"CLIENT_STATE::do_something(): End poll: %d tasks active\n", actions
|
2003-07-29 23:26:32 +00:00
|
|
|
);
|
2003-07-02 02:02:18 +00:00
|
|
|
if (actions > 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2002-11-04 21:09:31 +00:00
|
|
|
time_stats.update(true, !activities_suspended);
|
2003-07-02 02:02:18 +00:00
|
|
|
return false;
|
2002-11-04 21:09:31 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Parse the client_state.xml file
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int CLIENT_STATE::parse_state_file() {
|
2003-06-03 22:47:15 +00:00
|
|
|
char buf[256];
|
2002-04-30 22:22:54 +00:00
|
|
|
FILE* f = fopen(STATE_FILE_NAME, "r");
|
2003-06-11 18:38:08 +00:00
|
|
|
PROJECT temp_project, *project=NULL;
|
2002-08-29 05:15:54 +00:00
|
|
|
int retval=0;
|
2002-12-05 21:35:51 +00:00
|
|
|
int failnum;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-07-02 02:02:18 +00:00
|
|
|
ScopeMessages scope_messages(log_messages, ClientMessages::DEBUG_STATE);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!f) {
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("CLIENT_STATE::parse_state_file(): No state file; will create one\n");
|
2003-05-20 22:32:03 +00:00
|
|
|
|
|
|
|
// avoid warning messages about version
|
|
|
|
//
|
|
|
|
old_major_version = MAJOR_VERSION;
|
|
|
|
old_minor_version = MINOR_VERSION;
|
2002-04-30 22:22:54 +00:00
|
|
|
return ERR_FOPEN;
|
|
|
|
}
|
|
|
|
fgets(buf, 256, f);
|
2002-08-29 05:15:54 +00:00
|
|
|
if (!match_tag(buf, "<client_state>")) {
|
|
|
|
retval = ERR_XML_PARSE;
|
|
|
|
goto done;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
while (fgets(buf, 256, f)) {
|
|
|
|
if (match_tag(buf, "</client_state>")) {
|
2002-08-29 05:15:54 +00:00
|
|
|
retval = 0;
|
|
|
|
break;
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (match_tag(buf, "<project>")) {
|
2002-07-31 19:05:15 +00:00
|
|
|
temp_project.parse_state(f);
|
|
|
|
project = lookup_project(temp_project.master_url);
|
|
|
|
if (project) {
|
|
|
|
project->copy_state_fields(temp_project);
|
2002-06-21 06:52:47 +00:00
|
|
|
} else {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "Project %s found in state file but not prefs.\n",
|
|
|
|
temp_project.master_url);
|
2002-06-21 06:52:47 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (match_tag(buf, "<app>")) {
|
|
|
|
APP* app = new APP;
|
|
|
|
app->parse(f);
|
2002-06-21 06:52:47 +00:00
|
|
|
if (project) {
|
|
|
|
retval = link_app(project, app);
|
|
|
|
if (!retval) apps.push_back(app);
|
|
|
|
} else {
|
|
|
|
delete app;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (match_tag(buf, "<file_info>")) {
|
|
|
|
FILE_INFO* fip = new FILE_INFO;
|
2002-07-05 05:33:40 +00:00
|
|
|
fip->parse(f, false);
|
2002-06-21 06:52:47 +00:00
|
|
|
if (project) {
|
|
|
|
retval = link_file_info(project, fip);
|
|
|
|
if (!retval) file_infos.push_back(fip);
|
2002-08-12 21:54:19 +00:00
|
|
|
// If the file had a failure before, there's no reason
|
|
|
|
// to start another file transfer
|
2002-12-05 21:35:51 +00:00
|
|
|
if (fip->had_failure(failnum)) {
|
2002-08-12 21:54:19 +00:00
|
|
|
if (fip->pers_file_xfer) delete fip->pers_file_xfer;
|
|
|
|
fip->pers_file_xfer = NULL;
|
|
|
|
}
|
2002-08-07 22:52:10 +00:00
|
|
|
// Init PERS_FILE_XFER and push it onto pers_file_xfer stack
|
|
|
|
if (fip->pers_file_xfer) {
|
2002-08-26 22:57:17 +00:00
|
|
|
fip->pers_file_xfer->init(fip, fip->upload_when_present);
|
2003-07-29 23:26:32 +00:00
|
|
|
retval = pers_file_xfers->insert( fip->pers_file_xfer );
|
2002-08-07 22:52:10 +00:00
|
|
|
}
|
2002-06-21 06:52:47 +00:00
|
|
|
} else {
|
|
|
|
delete fip;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (match_tag(buf, "<app_version>")) {
|
|
|
|
APP_VERSION* avp = new APP_VERSION;
|
|
|
|
avp->parse(f);
|
2002-06-21 06:52:47 +00:00
|
|
|
if (project) {
|
|
|
|
retval = link_app_version(project, avp);
|
|
|
|
if (!retval) app_versions.push_back(avp);
|
|
|
|
} else {
|
|
|
|
delete avp;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (match_tag(buf, "<workunit>")) {
|
|
|
|
WORKUNIT* wup = new WORKUNIT;
|
|
|
|
wup->parse(f);
|
2002-06-21 06:52:47 +00:00
|
|
|
if (project) {
|
|
|
|
retval = link_workunit(project, wup);
|
|
|
|
if (!retval) workunits.push_back(wup);
|
|
|
|
} else {
|
|
|
|
delete wup;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (match_tag(buf, "<result>")) {
|
|
|
|
RESULT* rp = new RESULT;
|
2002-07-05 05:33:40 +00:00
|
|
|
rp->parse_state(f);
|
2002-06-21 06:52:47 +00:00
|
|
|
if (project) {
|
|
|
|
retval = link_result(project, rp);
|
|
|
|
if (!retval) results.push_back(rp);
|
|
|
|
} else {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR,
|
|
|
|
"<result> found before any project\n"
|
2003-05-20 22:32:03 +00:00
|
|
|
);
|
2002-06-21 06:52:47 +00:00
|
|
|
delete rp;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (match_tag(buf, "<host_info>")) {
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = host_info.parse(f);
|
|
|
|
if (retval) goto done;
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (match_tag(buf, "<time_stats>")) {
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = time_stats.parse(f);
|
|
|
|
if (retval) goto done;
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (match_tag(buf, "<net_stats>")) {
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = net_stats.parse(f);
|
|
|
|
if (retval) goto done;
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (match_tag(buf, "<active_task_set>")) {
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = active_tasks.parse(f, this);
|
|
|
|
if (retval) goto done;
|
2002-05-17 22:33:57 +00:00
|
|
|
} else if (match_tag(buf, "<platform_name>")) {
|
2003-02-24 21:25:16 +00:00
|
|
|
// should match our current platform name
|
2002-05-17 22:33:57 +00:00
|
|
|
} else if (match_tag(buf, "<version>")) {
|
|
|
|
// could put logic here to detect incompatible state files
|
|
|
|
// after core client update
|
2003-05-15 17:10:26 +00:00
|
|
|
} else if (parse_int(buf, "<core_client_major_version>", old_major_version)) {
|
|
|
|
} else if (parse_int(buf, "<core_client_minor_version>", old_minor_version)) {
|
2002-12-18 20:18:06 +00:00
|
|
|
} else if (match_tag(buf, "<use_http_proxy/>")) {
|
2003-01-02 23:12:05 +00:00
|
|
|
use_http_proxy = true;
|
2003-06-05 22:14:44 +00:00
|
|
|
} else if (match_tag(buf, "<use_socks_proxy/>")) {
|
|
|
|
use_socks_proxy = true;
|
2003-01-02 23:12:05 +00:00
|
|
|
} else if (parse_str(buf, "<proxy_server_name>", proxy_server_name, sizeof(proxy_server_name))) {
|
|
|
|
} else if (parse_int(buf, "<proxy_server_port>", proxy_server_port)) {
|
2003-01-21 19:02:49 +00:00
|
|
|
} else if (parse_str(buf, "<socks_user_name>", socks_user_name, sizeof(socks_user_name))) {
|
|
|
|
} else if (parse_str(buf, "<socks_user_passwd>", socks_user_passwd, sizeof(socks_user_passwd))) {
|
2003-07-30 22:02:54 +00:00
|
|
|
// } else if (parse_int(buf, "<user_run_request/>")) {
|
2003-03-06 00:42:18 +00:00
|
|
|
} else if (parse_str(buf, "<host_venue>", host_venue, sizeof(host_venue))) {
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "CLIENT_STATE::parse_state_file: unrecognized: %s\n", buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-29 05:15:54 +00:00
|
|
|
done:
|
|
|
|
fclose(f);
|
2003-03-25 23:04:17 +00:00
|
|
|
|
2002-08-29 05:15:54 +00:00
|
|
|
return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
// Write the client_state.xml file
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int CLIENT_STATE::write_state_file() {
|
|
|
|
unsigned int i, j;
|
2002-08-19 18:43:10 +00:00
|
|
|
FILE* f = fopen(STATE_FILE_TEMP, "w");
|
2002-04-30 22:22:54 +00:00
|
|
|
int retval;
|
|
|
|
|
2003-07-02 02:02:18 +00:00
|
|
|
ScopeMessages scope_messages(log_messages, ClientMessages::DEBUG_STATE);
|
|
|
|
scope_messages.printf("CLIENT_STATE::write_state_file(): Writing state file\n");
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!f) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(0, MSG_ERROR, "Can't open temp state file: %s\n", STATE_FILE_TEMP);
|
2002-04-30 22:22:54 +00:00
|
|
|
return ERR_FOPEN;
|
|
|
|
}
|
|
|
|
fprintf(f, "<client_state>\n");
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = host_info.write(f);
|
|
|
|
if (retval) return retval;
|
|
|
|
retval = time_stats.write(f, false);
|
|
|
|
if (retval) return retval;
|
|
|
|
retval = net_stats.write(f, false);
|
|
|
|
if (retval) return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
for (j=0; j<projects.size(); j++) {
|
|
|
|
PROJECT* p = projects[j];
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = p->write_state(f);
|
|
|
|
if (retval) return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<apps.size(); i++) {
|
2003-03-08 23:48:05 +00:00
|
|
|
if (apps[i]->project == p) {
|
|
|
|
retval = apps[i]->write(f);
|
|
|
|
if (retval) return retval;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
|
|
|
if (file_infos[i]->project == p) {
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = file_infos[i]->write(f, false);
|
|
|
|
if (retval) return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
if (app_versions[i]->project == p) app_versions[i]->write(f);
|
|
|
|
}
|
|
|
|
for (i=0; i<workunits.size(); i++) {
|
|
|
|
if (workunits[i]->project == p) workunits[i]->write(f);
|
|
|
|
}
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
if (results[i]->project == p) results[i]->write(f, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
active_tasks.write(f);
|
2002-05-17 22:33:57 +00:00
|
|
|
fprintf(f,
|
|
|
|
"<platform_name>%s</platform_name>\n"
|
2002-12-01 06:14:28 +00:00
|
|
|
"<core_client_major_version>%d</core_client_major_version>\n"
|
|
|
|
"<core_client_minor_version>%d</core_client_minor_version>\n",
|
2002-05-17 22:33:57 +00:00
|
|
|
platform_name,
|
2002-12-01 06:14:28 +00:00
|
|
|
core_client_major_version,
|
|
|
|
core_client_minor_version
|
2002-12-10 01:10:56 +00:00
|
|
|
);
|
2003-01-02 23:12:05 +00:00
|
|
|
|
2003-03-06 00:42:18 +00:00
|
|
|
// save proxy info
|
2003-01-02 23:12:05 +00:00
|
|
|
//
|
2002-12-10 01:10:56 +00:00
|
|
|
fprintf(f,
|
|
|
|
"%s"
|
2002-12-19 00:00:43 +00:00
|
|
|
"%s"
|
|
|
|
"<proxy_server_name>%s</proxy_server_name>\n"
|
|
|
|
"<proxy_server_port>%d</proxy_server_port>\n"
|
|
|
|
"<socks_user_name>%s</socks_user_name>\n"
|
|
|
|
"<socks_user_passwd>%s</socks_user_passwd>\n",
|
|
|
|
use_http_proxy?"<use_http_proxy/>\n":"",
|
|
|
|
use_socks_proxy?"<use_socks_proxy/>\n":"",
|
2002-12-10 01:10:56 +00:00
|
|
|
proxy_server_name,
|
2002-12-19 00:00:43 +00:00
|
|
|
proxy_server_port,
|
|
|
|
socks_user_name,
|
|
|
|
socks_user_passwd
|
2002-05-17 22:33:57 +00:00
|
|
|
);
|
2003-07-30 22:02:54 +00:00
|
|
|
#if 0
|
|
|
|
fprintf(f, "<user_run_request>%d</user_run_request>\n", user_run_request);
|
|
|
|
#endif
|
2003-03-06 00:42:18 +00:00
|
|
|
if (strlen(host_venue)) {
|
|
|
|
fprintf(f, "<host_venue>%s</host_venue>\n", host_venue);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
fprintf(f, "</client_state>\n");
|
|
|
|
fclose(f);
|
2002-08-22 21:44:00 +00:00
|
|
|
retval = boinc_rename(STATE_FILE_TEMP, STATE_FILE_NAME);
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("CLIENT_STATE::write_state_file(): Done writing state file\n");
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) return ERR_RENAME;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-22 21:29:58 +00:00
|
|
|
// Write the client_state.xml file if necessary
|
2003-03-02 19:24:09 +00:00
|
|
|
// TODO: write no more often than X seconds
|
2002-08-22 21:29:58 +00:00
|
|
|
//
|
|
|
|
int CLIENT_STATE::write_state_file_if_needed() {
|
|
|
|
int retval;
|
2003-08-01 22:18:37 +00:00
|
|
|
if (client_state_dirty) {
|
2002-08-22 21:44:00 +00:00
|
|
|
client_state_dirty = false;
|
2002-08-22 21:29:58 +00:00
|
|
|
retval = write_state_file();
|
|
|
|
if (retval) return retval;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// See if the project specified by master_url already exists
|
2003-05-22 22:55:11 +00:00
|
|
|
// in the client state record. Ignore any trailing "/" characters
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-06-21 06:52:47 +00:00
|
|
|
PROJECT* CLIENT_STATE::lookup_project(char* master_url) {
|
2003-05-22 22:55:11 +00:00
|
|
|
int len1, len2;
|
|
|
|
char *mu;
|
|
|
|
|
|
|
|
len1 = strlen(master_url);
|
|
|
|
if (master_url[strlen(master_url)-1] == '/') len1--;
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
for (unsigned int i=0; i<projects.size(); i++) {
|
2003-05-22 22:55:11 +00:00
|
|
|
mu = projects[i]->master_url;
|
|
|
|
len2 = strlen(mu);
|
|
|
|
if (mu[strlen(mu)-1] == '/') len2--;
|
|
|
|
if (!strncmp(master_url, projects[i]->master_url, max(len1,len2))) {
|
2002-04-30 22:22:54 +00:00
|
|
|
return projects[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
APP* CLIENT_STATE::lookup_app(PROJECT* p, 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, 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, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
APP_VERSION* CLIENT_STATE::lookup_app_version(APP* app, int version_num) {
|
|
|
|
for (unsigned int i=0; i<app_versions.size(); i++) {
|
|
|
|
APP_VERSION* avp = app_versions[i];
|
|
|
|
if (avp->app == app && version_num==avp->version_num) {
|
|
|
|
return avp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE_INFO* CLIENT_STATE::lookup_file_info(PROJECT* p, 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;
|
|
|
|
}
|
|
|
|
|
2003-05-14 21:17:58 +00:00
|
|
|
// Find the active task for a given result
|
2002-11-09 01:15:38 +00:00
|
|
|
//
|
2003-05-14 21:17:58 +00:00
|
|
|
ACTIVE_TASK* CLIENT_STATE::lookup_active_task_by_result(RESULT* rep) {
|
|
|
|
for (unsigned int i = 0; i < active_tasks.active_tasks.size(); i ++) {
|
|
|
|
if (active_tasks.active_tasks[i]->result == rep) {
|
|
|
|
return active_tasks.active_tasks[i];
|
|
|
|
}
|
2002-11-16 00:40:25 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
2002-11-09 01:15:38 +00:00
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
// functions to create links between state objects
|
2002-05-17 22:33:57 +00:00
|
|
|
// (which, in their XML form, reference one another by name)
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
|
|
|
int CLIENT_STATE::link_app(PROJECT* p, APP* app) {
|
|
|
|
app->project = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::link_file_info(PROJECT* p, FILE_INFO* fip) {
|
|
|
|
fip->project = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::link_app_version(PROJECT* p, APP_VERSION* avp) {
|
|
|
|
APP* app;
|
|
|
|
FILE_INFO* fip;
|
2002-05-17 22:33:57 +00:00
|
|
|
FILE_REF file_ref;
|
|
|
|
unsigned int i;
|
2002-07-29 00:39:45 +00:00
|
|
|
|
2002-05-17 22:33:57 +00:00
|
|
|
avp->project = p;
|
2002-04-30 22:22:54 +00:00
|
|
|
app = lookup_app(p, avp->app_name);
|
|
|
|
if (!app) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(0, MSG_ERROR, "app_version refers to nonexistent app: %s\n", avp->app_name);
|
2002-04-30 22:22:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
avp->app = app;
|
2002-05-17 22:33:57 +00:00
|
|
|
|
|
|
|
for (i=0; i<avp->app_files.size(); i++) {
|
|
|
|
file_ref = avp->app_files[i];
|
|
|
|
fip = lookup_file_info(p, file_ref.file_name);
|
|
|
|
if (!fip) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(0, MSG_ERROR, "app_version refers to nonexistent file: %s\n",
|
|
|
|
file_ref.file_name);
|
2002-05-17 22:33:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
|
2003-05-20 00:03:39 +00:00
|
|
|
// any executable file associated with an app version must be signed
|
2002-07-07 20:39:24 +00:00
|
|
|
//
|
2003-05-20 00:03:39 +00:00
|
|
|
if (fip->executable) {
|
|
|
|
fip->signature_required = true;
|
|
|
|
}
|
2002-05-17 22:33:57 +00:00
|
|
|
avp->app_files[i].file_info = fip;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-05-17 22:33:57 +00:00
|
|
|
int CLIENT_STATE::link_file_ref(PROJECT* p, FILE_REF* file_refp) {
|
2002-04-30 22:22:54 +00:00
|
|
|
FILE_INFO* fip;
|
2002-07-29 00:39:45 +00:00
|
|
|
|
2002-05-17 22:33:57 +00:00
|
|
|
fip = lookup_file_info(p, file_refp->file_name);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!fip) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(0, MSG_ERROR, "File ref refers to nonexistent file: %s\n", file_refp->file_name);
|
2002-04-30 22:22:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-05-17 22:33:57 +00:00
|
|
|
file_refp->file_info = fip;
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::link_workunit(PROJECT* p, WORKUNIT* wup) {
|
|
|
|
APP* app;
|
|
|
|
APP_VERSION* avp;
|
|
|
|
unsigned int i;
|
|
|
|
int retval;
|
2002-07-29 00:39:45 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
app = lookup_app(p, wup->app_name);
|
|
|
|
if (!app) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(0, MSG_ERROR, "WU refers to nonexistent app: %s\n", wup->app_name);
|
2002-04-30 22:22:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-07-29 00:39:45 +00:00
|
|
|
avp = lookup_app_version(app, wup->version_num);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!avp) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(0, MSG_ERROR, "WU refers to nonexistent app_version: %s %d\n",
|
|
|
|
wup->app_name, wup->version_num);
|
2002-04-30 22:22:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
wup->project = p;
|
|
|
|
wup->app = app;
|
|
|
|
wup->avp = avp;
|
|
|
|
for (i=0; i<wup->input_files.size(); i++) {
|
2002-05-17 22:33:57 +00:00
|
|
|
retval = link_file_ref(p, &wup->input_files[i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2002-07-29 00:39:45 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
int CLIENT_STATE::link_result(PROJECT* p, RESULT* rp) {
|
|
|
|
WORKUNIT* wup;
|
|
|
|
unsigned int i;
|
|
|
|
int retval;
|
2002-07-29 00:39:45 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
wup = lookup_workunit(p, rp->wu_name);
|
|
|
|
if (!wup) {
|
|
|
|
fprintf(stderr, "result refers to nonexistent WU: %s\n", rp->wu_name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
rp->project = p;
|
|
|
|
rp->wup = wup;
|
|
|
|
rp->app = wup->app;
|
|
|
|
for (i=0; i<rp->output_files.size(); i++) {
|
2002-05-17 22:33:57 +00:00
|
|
|
retval = link_file_ref(p, &rp->output_files[i]);
|
2002-07-31 19:05:15 +00:00
|
|
|
if (retval) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(0, MSG_ERROR, "link_result: link_file_ref failed\n");
|
2002-08-27 04:59:55 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
int CLIENT_STATE::latest_version_num(char* app_name) {
|
|
|
|
unsigned int i;
|
|
|
|
int best = -1;
|
|
|
|
APP_VERSION* avp;
|
|
|
|
|
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
avp = app_versions[i];
|
|
|
|
if (strcmp(avp->app_name, app_name)) continue;
|
|
|
|
if (avp->version_num < best) continue;
|
|
|
|
best = avp->version_num;
|
|
|
|
}
|
2003-01-07 22:49:42 +00:00
|
|
|
if (best < 0) {
|
2003-06-03 22:47:15 +00:00
|
|
|
msg_printf(0, MSG_ERROR, "CLIENT_STATE::latest_version_num: no version\n");
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
2002-07-29 00:39:45 +00:00
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Print debugging information about how many projects/files/etc
|
|
|
|
// are currently in the client state record
|
|
|
|
//
|
2003-01-07 22:49:42 +00:00
|
|
|
void CLIENT_STATE::print_summary() {
|
|
|
|
unsigned int i;
|
2003-01-09 07:24:27 +00:00
|
|
|
int t;
|
2003-01-07 22:49:42 +00:00
|
|
|
if (!log_flags.state_debug) return;
|
|
|
|
|
2003-07-02 02:02:18 +00:00
|
|
|
ScopeMessages scope_messages(log_messages, ClientMessages::DEBUG_STATE);
|
|
|
|
scope_messages.printf("CLIENT_STATE::print_summary(): Client state summary:\n");
|
|
|
|
++log_messages;
|
|
|
|
scope_messages.printf("%d projects:\n", (int)projects.size());
|
2003-01-07 22:49:42 +00:00
|
|
|
for (i=0; i<projects.size(); i++) {
|
2003-01-13 23:37:56 +00:00
|
|
|
t = projects[i]->min_rpc_time;
|
2003-01-09 07:24:27 +00:00
|
|
|
if (t) {
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf(" %s min RPC %d seconds from now\n", projects[i]->master_url, (int)(t-time(0)));
|
|
|
|
} else {
|
|
|
|
scope_messages.printf(" %s\n", projects[i]->master_url);
|
2003-01-09 07:24:27 +00:00
|
|
|
}
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("%d file_infos:\n", (int)file_infos.size());
|
2003-01-07 22:49:42 +00:00
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf(" %s status:%d %s\n", file_infos[i]->name, file_infos[i]->status, file_infos[i]->pers_file_xfer?"active":"inactive");
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("%d app_versions\n", (int)app_versions.size());
|
2003-01-07 22:49:42 +00:00
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf(" %s %d\n", app_versions[i]->app_name, app_versions[i]->version_num);
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("%d workunits\n", (int)workunits.size());
|
2003-01-07 22:49:42 +00:00
|
|
|
for (i=0; i<workunits.size(); i++) {
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf(" %s\n", workunits[i]->name);
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("%d results\n", (int)results.size());
|
2003-01-07 22:49:42 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf(" %s state:%d\n", results[i]->name, results[i]->state);
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
2003-07-29 23:26:32 +00:00
|
|
|
scope_messages.printf("%d persistent file xfers\n", (int)pers_file_xfers->pers_file_xfers.size());
|
|
|
|
for (i=0; i<pers_file_xfers->pers_file_xfers.size(); i++) {
|
|
|
|
scope_messages.printf(" %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));
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("%d active tasks\n", (int)active_tasks.active_tasks.size());
|
2003-01-07 22:49:42 +00:00
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf(" %s\n", active_tasks.active_tasks[i]->result->name);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-07-02 02:02:18 +00:00
|
|
|
--log_messages;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// delete unneeded records and files
|
|
|
|
//
|
|
|
|
bool CLIENT_STATE::garbage_collect() {
|
2003-03-02 19:24:09 +00:00
|
|
|
unsigned int i, j;
|
2002-12-05 21:35:51 +00:00
|
|
|
int failnum;
|
2002-04-30 22:22:54 +00:00
|
|
|
FILE_INFO* fip;
|
|
|
|
RESULT* rp;
|
|
|
|
WORKUNIT* wup;
|
2003-03-02 19:24:09 +00:00
|
|
|
APP_VERSION* avp, *avp2;
|
2002-04-30 22:22:54 +00:00
|
|
|
vector<RESULT*>::iterator result_iter;
|
|
|
|
vector<WORKUNIT*>::iterator wu_iter;
|
|
|
|
vector<FILE_INFO*>::iterator fi_iter;
|
2003-03-02 19:24:09 +00:00
|
|
|
vector<APP_VERSION*>::iterator avp_iter;
|
|
|
|
bool action = false, found;
|
2003-09-01 17:11:14 +00:00
|
|
|
string error_msgs;
|
2003-06-11 21:50:54 +00:00
|
|
|
|
2003-07-02 02:02:18 +00:00
|
|
|
ScopeMessages scope_messages(log_messages, ClientMessages::DEBUG_STATE);
|
|
|
|
|
2003-03-02 19:24:09 +00:00
|
|
|
// zero references counts on WUs, FILE_INFOs and APP_VERSIONs
|
2002-04-30 22:22:54 +00:00
|
|
|
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;
|
|
|
|
}
|
2003-03-02 19:24:09 +00:00
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
avp = app_versions[i];
|
|
|
|
avp->ref_cnt = 0;
|
|
|
|
}
|
2003-06-11 21:50:54 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
// delete RESULTs that have been finished and reported;
|
|
|
|
// reference-count files referred to by other results
|
|
|
|
//
|
|
|
|
result_iter = results.begin();
|
|
|
|
while (result_iter != results.end()) {
|
|
|
|
rp = *result_iter;
|
2003-02-06 01:02:56 +00:00
|
|
|
if (rp->server_ack) {
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("CLIENT_STATE::garbage_collect(): deleting result %s\n", rp->name);
|
2002-04-30 22:22:54 +00:00
|
|
|
delete rp;
|
|
|
|
result_iter = results.erase(result_iter);
|
|
|
|
action = true;
|
|
|
|
} else {
|
2002-10-14 21:12:05 +00:00
|
|
|
// See if the files for this result's workunit had
|
|
|
|
// any errors (MD5, RSA, etc)
|
2003-01-02 23:12:05 +00:00
|
|
|
//
|
2003-03-13 21:49:52 +00:00
|
|
|
if (rp->wup->had_failure(failnum)) {
|
2002-12-05 21:56:33 +00:00
|
|
|
// If we don't already have an error for this file
|
2003-02-06 01:02:56 +00:00
|
|
|
if (!rp->ready_to_ack) {
|
2003-01-02 23:12:05 +00:00
|
|
|
// the wu corresponding to this result
|
|
|
|
// had an error downloading some input file(s).
|
|
|
|
//
|
2003-09-01 17:11:14 +00:00
|
|
|
rp->wup->get_file_errors(error_msgs);
|
|
|
|
report_result_error(*rp, 0, error_msgs.c_str());
|
2002-12-05 21:56:33 +00:00
|
|
|
}
|
2002-10-10 22:36:21 +00:00
|
|
|
}
|
2003-04-07 23:43:42 +00:00
|
|
|
rp->wup->ref_cnt++;
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<rp->output_files.size(); i++) {
|
2002-08-23 00:53:00 +00:00
|
|
|
// If one of the file infos had a failure,
|
2002-08-27 04:59:55 +00:00
|
|
|
// mark the result as done and report the error.
|
|
|
|
// The result, workunits, and file infos
|
|
|
|
// will be cleaned up after the server is notified
|
|
|
|
//
|
2002-12-05 21:56:33 +00:00
|
|
|
if(rp->output_files[i].file_info->had_failure(failnum)) {
|
2003-02-06 01:02:56 +00:00
|
|
|
if (!rp->ready_to_ack) {
|
2003-01-02 23:12:05 +00:00
|
|
|
// had an error uploading a file for this result
|
|
|
|
//
|
2003-06-25 20:12:51 +00:00
|
|
|
switch(failnum) {
|
|
|
|
case ERR_FILE_TOO_BIG:
|
|
|
|
report_result_error(*rp, 0, "Output file exceeded size limit");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
report_result_error(*rp, 0, "Couldn't upload files or other output file error");
|
|
|
|
}
|
2002-12-05 21:56:33 +00:00
|
|
|
}
|
2002-08-12 21:54:19 +00:00
|
|
|
}
|
2003-04-07 23:43:42 +00:00
|
|
|
rp->output_files[i].file_info->ref_cnt++;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
result_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete WORKUNITs not referenced by any result;
|
2003-03-02 19:24:09 +00:00
|
|
|
// reference-count files and APP_VERSIONs referred to by other WUs
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
|
|
|
wu_iter = workunits.begin();
|
|
|
|
while (wu_iter != workunits.end()) {
|
|
|
|
wup = *wu_iter;
|
|
|
|
if (wup->ref_cnt == 0) {
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("CLIENT_STATE::garbage_collect(): deleting workunit %s\n", wup->name);
|
2002-04-30 22:22:54 +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++;
|
|
|
|
}
|
2003-03-02 19:24:09 +00:00
|
|
|
wup->avp->ref_cnt++;
|
2002-04-30 22:22:54 +00:00
|
|
|
wu_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-02 19:24:09 +00:00
|
|
|
// go through APP_VERSIONs;
|
|
|
|
// delete any not referenced by any WORKUNIT
|
|
|
|
// and having 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++) {
|
2003-03-29 07:25:48 +00:00
|
|
|
avp->app_files[j].file_info->ref_cnt++;
|
2003-03-02 19:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete FILE_INFOs (and corresponding files) that are not sticky
|
|
|
|
// and are not referenced by any WORKUNIT, RESULT or APP_VERSION
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
|
|
|
fi_iter = file_infos.begin();
|
|
|
|
while (fi_iter != file_infos.end()) {
|
|
|
|
fip = *fi_iter;
|
2003-07-21 12:42:40 +00:00
|
|
|
if (fip->ref_cnt==0 && fip->pers_file_xfer==NULL && !fip->sticky) {
|
2002-04-30 22:22:54 +00:00
|
|
|
fip->delete_file();
|
2003-07-02 02:02:18 +00:00
|
|
|
scope_messages.printf("CLIENT_STATE::garbage_collect(): deleting file %s\n", fip->name);
|
2002-04-30 22:22:54 +00:00
|
|
|
delete fip;
|
|
|
|
fi_iter = file_infos.erase(fi_iter);
|
|
|
|
action = true;
|
|
|
|
} else {
|
|
|
|
fi_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-02 02:02:18 +00:00
|
|
|
if (action) {
|
2003-01-07 22:49:42 +00:00
|
|
|
print_summary();
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2002-08-12 21:54:19 +00:00
|
|
|
// update the state of results
|
|
|
|
//
|
|
|
|
bool CLIENT_STATE::update_results() {
|
|
|
|
RESULT* rp;
|
|
|
|
vector<RESULT*>::iterator result_iter;
|
|
|
|
bool action = false;
|
2003-06-11 21:50:54 +00:00
|
|
|
|
2002-08-12 21:54:19 +00:00
|
|
|
// delete RESULTs that have been finished and reported;
|
|
|
|
// reference-count files referred to by other results
|
|
|
|
//
|
|
|
|
result_iter = results.begin();
|
|
|
|
while (result_iter != results.end()) {
|
|
|
|
rp = *result_iter;
|
2003-02-06 19:01:49 +00:00
|
|
|
// The result has been received by the scheduling
|
|
|
|
// server. It will be deleted on the next
|
|
|
|
// garbage collection, which we trigger by
|
|
|
|
// setting action to true
|
2003-05-21 23:23:42 +00:00
|
|
|
if (rp->server_ack)
|
2003-02-06 19:01:49 +00:00
|
|
|
action = true;
|
2003-06-11 21:50:54 +00:00
|
|
|
|
2002-08-12 21:54:19 +00:00
|
|
|
switch (rp->state) {
|
2003-02-06 19:01:49 +00:00
|
|
|
case RESULT_NEW:
|
2003-06-05 20:58:31 +00:00
|
|
|
rp->state = RESULT_FILES_DOWNLOADING;
|
|
|
|
action = true;
|
|
|
|
break;
|
|
|
|
case RESULT_FILES_DOWNLOADING:
|
2003-06-06 18:57:25 +00:00
|
|
|
if (input_files_available(rp)) {
|
2003-02-06 19:01:49 +00:00
|
|
|
rp->state = RESULT_FILES_DOWNLOADED;
|
2003-06-06 18:57:25 +00:00
|
|
|
action = true;
|
|
|
|
}
|
2003-02-06 19:01:49 +00:00
|
|
|
break;
|
2003-06-26 23:53:37 +00:00
|
|
|
|
|
|
|
// app_finished() transitions to either RESULT_COMPUTE_DONE or
|
|
|
|
// RESULT_FILES_UPLOADING. RESULT_COMPUTE_DONE is a dead-end state
|
|
|
|
// indicating we had an error at the end of computation.
|
|
|
|
|
|
|
|
// case RESULT_FILES_DOWNLOADED:
|
|
|
|
// break;
|
|
|
|
// case RESULT_COMPUTE_DONE:
|
|
|
|
// rp->state = RESULT_FILES_UPLOADING;
|
|
|
|
// action = true;
|
|
|
|
// break;
|
2003-06-05 20:58:31 +00:00
|
|
|
case RESULT_FILES_UPLOADING:
|
2003-06-26 23:53:37 +00:00
|
|
|
// Once the computation has been done, check that the necessary
|
|
|
|
// files have been uploaded before moving on
|
2003-02-06 19:01:49 +00:00
|
|
|
if (rp->is_upload_done()) {
|
|
|
|
rp->ready_to_ack = true;
|
|
|
|
rp->state = RESULT_FILES_UPLOADED;
|
2003-06-06 18:59:10 +00:00
|
|
|
action = true;
|
2003-06-05 20:58:31 +00:00
|
|
|
}
|
2003-02-06 19:01:49 +00:00
|
|
|
break;
|
|
|
|
case RESULT_FILES_UPLOADED:
|
|
|
|
break;
|
2002-08-12 21:54:19 +00:00
|
|
|
}
|
|
|
|
result_iter++;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2003-09-02 03:38:04 +00:00
|
|
|
static void print_options(char* prog) {
|
|
|
|
printf(
|
|
|
|
"Usage: %s [options]\n"
|
|
|
|
" -version show version info\n"
|
|
|
|
" -show_projects show attached projects\n"
|
|
|
|
" -detach_project URL detach from a project\n"
|
|
|
|
" -reset_project URL reset (clear) a project\n"
|
|
|
|
" -attach_project attach to a project (will prompt for URL, account key)\n"
|
|
|
|
" -update_prefs contact all projects to update preferences\n"
|
|
|
|
" -run_cpu_benchmarks run the CPU benchmarks\n",
|
|
|
|
prog
|
|
|
|
);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
// Parse the command line arguments passed to the client
|
2003-02-20 00:58:55 +00:00
|
|
|
// NOTE: init() has not been called at this point
|
|
|
|
// (i.e. client_state.xml has not been parsed)
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
void CLIENT_STATE::parse_cmdline(int argc, char** argv) {
|
|
|
|
int i;
|
2003-09-02 03:38:04 +00:00
|
|
|
bool show_options = false;
|
2002-07-29 00:39:45 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=1; i<argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "-exit_when_idle")) {
|
|
|
|
exit_when_idle = true;
|
2003-08-14 00:02:15 +00:00
|
|
|
} else if (!strcmp(argv[i], "-return_results_immediately")) {
|
|
|
|
return_results_immediately = true;
|
2003-04-01 03:28:37 +00:00
|
|
|
} else if (!strcmp(argv[i], "-skip_cpu_benchmarks")) {
|
|
|
|
skip_cpu_benchmarks = true;
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-exit_after_app_start")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else exit_after_app_start_secs = atoi(argv[++i]);
|
2003-03-16 21:59:11 +00:00
|
|
|
} else if (!strcmp(argv[i], "-file_xfer_giveup_period")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else file_xfer_giveup_period = atoi(argv[++i]);
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-min")) {
|
2003-02-06 19:01:49 +00:00
|
|
|
global_prefs.run_minimized = true;
|
2003-08-01 21:50:09 +00:00
|
|
|
} else if (!strcmp(argv[i], "-suspend")) {
|
|
|
|
user_run_request = USER_RUN_REQUEST_NEVER;
|
2003-02-28 18:56:20 +00:00
|
|
|
} else if (!strcmp(argv[i], "-saver")) {
|
2003-03-03 19:13:16 +00:00
|
|
|
start_saver = true;
|
2003-06-10 17:53:18 +00:00
|
|
|
} else if (!strncmp(argv[i], "-psn_", strlen("-psn_"))) {
|
|
|
|
// ignore -psn argument on Mac OS X
|
2003-03-31 23:18:55 +00:00
|
|
|
} else if (!strcmp(argv[i], "-exit_before_upload")) {
|
|
|
|
exit_before_upload = true;
|
2003-06-11 22:15:25 +00:00
|
|
|
// The following are only used for testing to alter scheduler/file transfer
|
|
|
|
// backoff rates
|
|
|
|
} else if (!strcmp(argv[i], "-master_fetch_period")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else master_fetch_period = atoi(argv[++i]);
|
2003-06-11 22:15:25 +00:00
|
|
|
} else if (!strcmp(argv[i], "-retry_base_period")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else retry_base_period = atoi(argv[++i]);
|
2003-06-11 22:15:25 +00:00
|
|
|
} else if (!strcmp(argv[i], "-retry_cap")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else retry_cap = atoi(argv[++i]);
|
2003-06-11 22:15:25 +00:00
|
|
|
} else if (!strcmp(argv[i], "-master_fetch_retry_cap")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else master_fetch_retry_cap = atoi(argv[++i]);
|
2003-06-11 22:15:25 +00:00
|
|
|
} else if (!strcmp(argv[i], "-master_fetch_interval")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else master_fetch_interval = atoi(argv[++i]);
|
2003-06-11 22:15:25 +00:00
|
|
|
} else if (!strcmp(argv[i], "-sched_retry_delay_min")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else sched_retry_delay_min = atoi(argv[++i]);
|
2003-06-11 22:15:25 +00:00
|
|
|
} else if (!strcmp(argv[i], "-sched_retry_delay_max")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else sched_retry_delay_max = atoi(argv[++i]);
|
2003-06-11 22:15:25 +00:00
|
|
|
} else if (!strcmp(argv[i], "-pers_retry_delay_min")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else pers_retry_delay_min = atoi(argv[++i]);
|
2003-06-11 22:15:25 +00:00
|
|
|
} else if (!strcmp(argv[i], "-pers_retry_delay_max")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else pers_retry_delay_max = atoi(argv[++i]);
|
2003-06-11 22:15:25 +00:00
|
|
|
} else if (!strcmp(argv[i], "-pers_giveup")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else pers_giveup = atoi(argv[++i]);
|
2003-06-28 00:15:42 +00:00
|
|
|
} else if (!strcmp(argv[i], "-debug_fake_exponential_backoff")) {
|
|
|
|
debug_fake_exponential_backoff = true;
|
2003-02-26 00:47:57 +00:00
|
|
|
|
2002-12-19 22:43:38 +00:00
|
|
|
// the above options are private (i.e. not shown by -help)
|
2003-09-02 03:38:04 +00:00
|
|
|
// Public options follow.
|
|
|
|
// NOTE: if you change or add anything, make the same chane
|
|
|
|
// in show_options() (above) and in doc/client.php
|
2002-12-19 22:43:38 +00:00
|
|
|
|
2003-05-15 17:10:26 +00:00
|
|
|
} else if (!strcmp(argv[i], "-show_projects")) {
|
|
|
|
show_projects = true;
|
|
|
|
} else if (!strcmp(argv[i], "-detach_project")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else strcpy(detach_project_url, argv[++i]);
|
2003-05-15 17:10:26 +00:00
|
|
|
} else if (!strcmp(argv[i], "-reset_project")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else strcpy(reset_project_url, argv[++i]);
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-update_prefs")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
if (i == argc-1) show_options = true;
|
|
|
|
else strcpy(update_prefs_url, argv[++i]);
|
2003-04-01 03:28:37 +00:00
|
|
|
} else if (!strcmp(argv[i], "-run_cpu_benchmarks")) {
|
|
|
|
run_cpu_benchmarks = true;
|
2003-05-16 19:22:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-attach_project")) {
|
|
|
|
add_new_project();
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-version")) {
|
2003-06-23 23:22:57 +00:00
|
|
|
printf( "%.2f %s\n", MAJOR_VERSION+(MINOR_VERSION/100.0), HOSTTYPE );
|
2003-01-07 01:02:08 +00:00
|
|
|
exit(0);
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-help")) {
|
2003-09-02 03:38:04 +00:00
|
|
|
print_options(argv[0]);
|
2003-01-07 01:02:08 +00:00
|
|
|
exit(0);
|
2003-02-26 00:47:57 +00:00
|
|
|
} else {
|
|
|
|
printf("Unknown option: %s\n", argv[i]);
|
2003-09-02 03:38:04 +00:00
|
|
|
show_options = true;
|
2002-12-18 21:05:18 +00:00
|
|
|
}
|
2002-12-09 03:07:36 +00:00
|
|
|
}
|
2003-09-02 03:38:04 +00:00
|
|
|
if (show_options) {
|
|
|
|
print_options(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-12-19 00:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::parse_env_vars() {
|
|
|
|
char *p, temp[256];
|
2002-12-09 03:07:36 +00:00
|
|
|
|
|
|
|
if ((p = getenv("HTTP_PROXY"))) {
|
2002-12-09 09:36:40 +00:00
|
|
|
if (strlen(p) > 0) {
|
2002-12-19 00:00:43 +00:00
|
|
|
use_http_proxy = true;
|
|
|
|
parse_url(p, proxy_server_name, proxy_server_port, temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((p = getenv("SOCKS_SERVER"))) {
|
|
|
|
if (strlen(p) > 0) {
|
|
|
|
use_socks_proxy = true;
|
2002-12-09 09:36:40 +00:00
|
|
|
parse_url(p, proxy_server_name, proxy_server_port, temp);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-12-19 00:00:43 +00:00
|
|
|
|
|
|
|
if ((p = getenv("SOCKS_USER"))) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(socks_user_name, p);
|
2002-12-19 00:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((p = getenv("SOCKS_PASSWD"))) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcpy(socks_user_passwd, p);
|
2002-12-19 00:00:43 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2003-02-12 19:53:46 +00:00
|
|
|
// Returns true if client should exit because of debugging criteria
|
|
|
|
// (timeout or idle)
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
bool CLIENT_STATE::time_to_exit() {
|
2003-02-12 19:53:46 +00:00
|
|
|
if (!exit_when_idle && !exit_after_app_start_secs) return false;
|
|
|
|
if (exit_after_app_start_secs
|
|
|
|
&& app_started
|
|
|
|
&& (difftime(time(0), app_started) >= exit_after_app_start_secs)
|
|
|
|
) {
|
|
|
|
printf("exiting because time is up: %d\n", exit_after_app_start_secs);
|
2002-09-26 05:57:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
2002-07-31 19:05:15 +00:00
|
|
|
if (exit_when_idle && (results.size() == 0) && contacted_sched_server) {
|
2002-09-26 05:57:10 +00:00
|
|
|
printf("exiting because no more results\n");
|
2002-08-27 04:59:55 +00:00
|
|
|
return true;
|
2002-07-31 19:05:15 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-08-22 21:04:42 +00:00
|
|
|
|
2002-08-22 21:29:58 +00:00
|
|
|
void CLIENT_STATE::set_client_state_dirty(char* source) {
|
2003-07-02 02:02:18 +00:00
|
|
|
log_messages.printf(ClientMessages::DEBUG_STATE, "set dirty: %s\n", source);
|
2002-08-22 21:04:42 +00:00
|
|
|
client_state_dirty = true;
|
|
|
|
}
|
2002-10-18 20:43:49 +00:00
|
|
|
|
2003-02-20 00:58:55 +00:00
|
|
|
// Call this when a result has a nonrecoverable error.
|
2003-03-13 21:49:52 +00:00
|
|
|
// Append a description of the error to the stderr_out field of the result.
|
2002-12-19 22:43:38 +00:00
|
|
|
//
|
2003-03-13 21:49:52 +00:00
|
|
|
// Go through the input and output files for this result
|
2003-02-20 00:58:55 +00:00
|
|
|
// and generates error messages for upload/download failures.
|
2002-12-19 22:43:38 +00:00
|
|
|
//
|
|
|
|
// This function is called in the following situations:
|
2003-02-20 00:58:55 +00:00
|
|
|
// 1. When the active_task could not start or restart,
|
2003-03-13 21:49:52 +00:00
|
|
|
// in which case err_num is set to an OS-specific error_code.
|
2003-02-20 00:58:55 +00:00
|
|
|
// and err_msg has an OS-supplied string.
|
|
|
|
// 2. when we fail in downloading an input file or uploading an output file,
|
|
|
|
// in which case err_num and err_msg are zero.
|
2002-12-19 22:43:38 +00:00
|
|
|
// 3. When the active_task exits with a non_zero error code
|
2003-03-13 21:49:52 +00:00
|
|
|
// or it gets signaled.
|
2002-12-19 22:43:38 +00:00
|
|
|
//
|
2003-03-13 21:49:52 +00:00
|
|
|
int CLIENT_STATE::report_result_error(
|
2003-09-01 17:11:14 +00:00
|
|
|
RESULT& res, int err_num, const char *err_msg
|
2003-02-20 00:58:55 +00:00
|
|
|
) {
|
2003-03-13 21:49:52 +00:00
|
|
|
char buf[MAX_BLOB_LEN];
|
2002-12-07 00:56:51 +00:00
|
|
|
unsigned int i;
|
2002-12-09 22:36:46 +00:00
|
|
|
int failnum;
|
2003-06-11 21:50:54 +00:00
|
|
|
|
2003-03-13 21:49:52 +00:00
|
|
|
// only do this once per result
|
|
|
|
//
|
2003-02-06 01:02:56 +00:00
|
|
|
if (res.ready_to_ack) {
|
2002-12-19 22:43:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-06-11 21:50:54 +00:00
|
|
|
|
2003-02-06 01:02:56 +00:00
|
|
|
res.ready_to_ack = true;
|
2003-01-07 01:02:08 +00:00
|
|
|
|
2003-08-01 01:20:24 +00:00
|
|
|
sprintf(buf, "Unrecoverable error for result %s (%s)", res.name, err_msg);
|
2003-05-16 19:22:57 +00:00
|
|
|
scheduler_op->backoff(res.project, buf);
|
2002-12-09 22:36:46 +00:00
|
|
|
|
2003-02-20 00:58:55 +00:00
|
|
|
sprintf(
|
2003-06-11 21:50:54 +00:00
|
|
|
buf,
|
2003-08-02 00:02:11 +00:00
|
|
|
"<message>%s\n</message>\n"
|
2002-12-19 22:43:38 +00:00
|
|
|
"<active_task_state>%d</active_task_state>\n"
|
|
|
|
"<exit_status>%d</exit_status>\n"
|
|
|
|
"<signal>%d</signal>\n",
|
|
|
|
err_msg,
|
|
|
|
res.active_task_state,
|
|
|
|
res.exit_status,
|
|
|
|
res.signal
|
|
|
|
);
|
2003-06-27 23:13:15 +00:00
|
|
|
res.stderr_out.append(buf);
|
2003-06-11 21:50:54 +00:00
|
|
|
|
|
|
|
if ((res.state == RESULT_FILES_DOWNLOADED) && err_num) {
|
2003-03-13 21:49:52 +00:00
|
|
|
sprintf(buf,"<couldnt_start>%d</couldnt_start>\n", err_num);
|
2003-06-27 23:13:15 +00:00
|
|
|
res.stderr_out.append(buf);
|
2002-12-19 22:43:38 +00:00
|
|
|
}
|
|
|
|
|
2003-02-06 01:02:56 +00:00
|
|
|
if (res.state == RESULT_NEW) {
|
2002-12-19 22:43:38 +00:00
|
|
|
for (i=0;i<res.wup->input_files.size();i++) {
|
|
|
|
if (res.wup->input_files[i].file_info->had_failure(failnum)) {
|
2003-03-13 21:49:52 +00:00
|
|
|
sprintf(buf,
|
2002-12-19 22:43:38 +00:00
|
|
|
"<download_error>\n"
|
|
|
|
" <file_name>%s</file_name>\n"
|
|
|
|
" <error_code>%d</error_code>\n"
|
|
|
|
"</download_error>\n",
|
|
|
|
res.wup->input_files[i].file_info->name, failnum
|
|
|
|
);
|
2003-06-27 23:13:15 +00:00
|
|
|
res.stderr_out.append(buf);
|
2002-12-19 22:43:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-06 01:02:56 +00:00
|
|
|
if (res.state == RESULT_COMPUTE_DONE) {
|
2002-12-19 22:43:38 +00:00
|
|
|
for (i=0; i<res.output_files.size(); i++) {
|
|
|
|
if (res.output_files[i].file_info->had_failure(failnum)) {
|
2003-03-13 21:49:52 +00:00
|
|
|
sprintf(buf,
|
2002-12-19 22:43:38 +00:00
|
|
|
"<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
|
|
|
|
);
|
2003-06-27 23:13:15 +00:00
|
|
|
res.stderr_out.append(buf);
|
2002-12-19 22:43:38 +00:00
|
|
|
}
|
|
|
|
}
|
2002-10-18 20:43:49 +00:00
|
|
|
}
|
2003-07-02 02:02:18 +00:00
|
|
|
|
2003-06-27 23:13:15 +00:00
|
|
|
res.stderr_out = res.stderr_out.substr(0,MAX_BLOB_LEN-1);
|
2002-10-18 20:43:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-05-14 21:17:58 +00:00
|
|
|
|
|
|
|
// "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
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::reset_project(PROJECT* project) {
|
|
|
|
unsigned int i;
|
|
|
|
APP_VERSION* avp;
|
|
|
|
APP* app;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
vector<APP*>::iterator app_iter;
|
|
|
|
vector<APP_VERSION*>::iterator avp_iter;
|
|
|
|
RESULT* rp;
|
|
|
|
PERS_FILE_XFER* pxp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks.active_tasks[i];
|
|
|
|
if (atp->result->project == project) {
|
|
|
|
atp->abort();
|
|
|
|
active_tasks.remove(atp);
|
2003-05-23 18:49:19 +00:00
|
|
|
i--;
|
2003-05-14 21:17:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-29 23:26:32 +00:00
|
|
|
for (i=0; i<pers_file_xfers->pers_file_xfers.size(); i++) {
|
|
|
|
pxp = pers_file_xfers->pers_file_xfers[i];
|
2003-05-14 21:17:58 +00:00
|
|
|
if (pxp->fip->project == project) {
|
|
|
|
if (pxp->fxp) {
|
|
|
|
file_xfers->remove(pxp->fxp);
|
|
|
|
}
|
2003-07-29 23:26:32 +00:00
|
|
|
pers_file_xfers->remove(pxp);
|
2003-05-23 18:49:19 +00:00
|
|
|
i--;
|
2003-05-14 21:17:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scheduler_op->state != SCHEDULER_OP_STATE_IDLE
|
|
|
|
&& scheduler_op->project == project
|
|
|
|
) {
|
|
|
|
http_ops->remove(&scheduler_op->http_op);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
rp = results[i];
|
2003-05-20 22:32:03 +00:00
|
|
|
if (rp->project == project) {
|
|
|
|
rp->server_ack = true;
|
|
|
|
}
|
2003-05-14 21:17:58 +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);
|
|
|
|
} 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);
|
|
|
|
} else {
|
|
|
|
app_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
garbage_collect();
|
2003-05-15 17:10:26 +00:00
|
|
|
write_state_file();
|
2003-05-14 21:17:58 +00:00
|
|
|
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 iter;
|
|
|
|
PROJECT* p;
|
|
|
|
char path[256];
|
|
|
|
int retval;
|
|
|
|
|
2003-05-23 18:49:19 +00:00
|
|
|
reset_project(project);
|
|
|
|
|
2003-05-14 21:17:58 +00:00
|
|
|
// find project and remove it from the vector
|
|
|
|
//
|
|
|
|
for (iter = projects.begin(); iter != projects.end(); iter++) {
|
|
|
|
p = *iter;
|
|
|
|
if (p == project) {
|
|
|
|
projects.erase(iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete account file
|
|
|
|
//
|
|
|
|
get_account_filename(project->master_url, path);
|
|
|
|
retval = file_delete(path);
|
|
|
|
|
|
|
|
// remove project directory and its contents
|
|
|
|
//
|
|
|
|
remove_project_dir(*project);
|
|
|
|
delete project;
|
2003-05-15 17:10:26 +00:00
|
|
|
write_state_file();
|
2003-05-14 21:17:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2003-07-21 12:42:41 +00:00
|
|
|
|
|
|
|
void CLIENT_STATE::check_project_pointer(PROJECT* p) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
if (p == projects[i]) return;
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
void CLIENT_STATE::check_app_pointer(APP* p) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<apps.size(); i++) {
|
|
|
|
if (p == apps[i]) return;
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
void CLIENT_STATE::check_file_info_pointer(FILE_INFO* p) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
|
|
|
if (p == file_infos[i]) return;
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
void CLIENT_STATE::check_app_version_pointer(APP_VERSION* p) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
if (p == app_versions[i]) return;
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
void CLIENT_STATE::check_workunit_pointer(WORKUNIT* p) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<workunits.size(); i++) {
|
|
|
|
if (p == workunits[i]) return;
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
void CLIENT_STATE::check_result_pointer(RESULT* p) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
if (p == results[i]) return;
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_pers_file_xfer_pointer(PERS_FILE_XFER* p) {
|
|
|
|
unsigned int i;
|
2003-07-29 23:26:32 +00:00
|
|
|
for (i=0; i<pers_file_xfers->pers_file_xfers.size(); i++) {
|
|
|
|
if (p == pers_file_xfers->pers_file_xfers[i]) return;
|
2003-07-21 12:42:41 +00:00
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
void CLIENT_STATE::check_file_xfer_pointer(FILE_XFER* p) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<file_xfers->file_xfers.size(); i++) {
|
|
|
|
if (p == file_xfers->file_xfers[i]) return;
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_app(APP& p) {
|
|
|
|
check_project_pointer(p.project);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_file_info(FILE_INFO& p) {
|
|
|
|
if (p.pers_file_xfer) check_pers_file_xfer_pointer(p.pers_file_xfer);
|
|
|
|
if (p.result) check_result_pointer(p.result);
|
|
|
|
check_project_pointer(p.project);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_file_ref(FILE_REF& p) {
|
|
|
|
check_file_info_pointer(p.file_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_app_version(APP_VERSION& p) {
|
|
|
|
unsigned int i;
|
|
|
|
check_app_pointer(p.app);
|
|
|
|
check_project_pointer(p.project);
|
|
|
|
for (i=0; i<p.app_files.size(); i++) {
|
|
|
|
check_file_ref(p.app_files[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_workunit(WORKUNIT& p) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<p.input_files.size(); i++) {
|
|
|
|
check_file_ref(p.input_files[i]);
|
|
|
|
}
|
|
|
|
check_project_pointer(p.project);
|
|
|
|
check_app_pointer(p.app);
|
|
|
|
check_app_version_pointer(p.avp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_result(RESULT& p) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<p.output_files.size(); i++) {
|
|
|
|
check_file_ref(p.output_files[i]);
|
|
|
|
}
|
|
|
|
check_app_pointer(p.app);
|
|
|
|
check_workunit_pointer(p.wup);
|
|
|
|
check_project_pointer(p.project);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_active_task(ACTIVE_TASK& p) {
|
|
|
|
check_result_pointer(p.result);
|
|
|
|
check_workunit_pointer(p.wup);
|
|
|
|
check_app_version_pointer(p.app_version);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_pers_file_xfer(PERS_FILE_XFER& p) {
|
|
|
|
check_file_xfer_pointer(p.fxp);
|
|
|
|
check_file_info_pointer(p.fip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_file_xfer(FILE_XFER& p) {
|
|
|
|
check_file_info_pointer(p.fip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::check_all() {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<apps.size(); i++) {
|
|
|
|
check_app(*apps[i]);
|
|
|
|
}
|
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
|
|
|
check_file_info(*file_infos[i]);
|
|
|
|
}
|
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
check_app_version(*app_versions[i]);
|
|
|
|
}
|
|
|
|
for (i=0; i<workunits.size(); i++) {
|
|
|
|
check_workunit(*workunits[i]);
|
|
|
|
}
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
check_result(*results[i]);
|
|
|
|
}
|
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
|
|
|
check_active_task(*active_tasks.active_tasks[i]);
|
|
|
|
}
|
2003-07-29 23:26:32 +00:00
|
|
|
for (i=0; i<pers_file_xfers->pers_file_xfers.size(); i++) {
|
|
|
|
check_pers_file_xfer(*pers_file_xfers->pers_file_xfers[i]);
|
2003-07-21 12:42:41 +00:00
|
|
|
}
|
|
|
|
for (i=0; i<file_xfers->file_xfers.size(); i++) {
|
|
|
|
check_file_xfer(*file_xfers->file_xfers[i]);
|
|
|
|
}
|
|
|
|
}
|