2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// 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
|
2002-12-19 22:43:38 +00:00
|
|
|
// http://www.mozilla.org/MPL/
|
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
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-06-06 18:42:01 +00:00
|
|
|
#include "windows_cpp.h"
|
2002-07-11 01:09:53 +00:00
|
|
|
#include "error_numbers.h"
|
2002-06-06 18:42:01 +00:00
|
|
|
|
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
|
|
|
|
|
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>
|
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-04-30 22:22:54 +00:00
|
|
|
#include "log_flags.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-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);
|
2002-08-07 22:52:10 +00:00
|
|
|
pers_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-02-20 00:58:55 +00:00
|
|
|
update_prefs = false;
|
2002-06-28 18:32:18 +00:00
|
|
|
run_time_test = true;
|
2002-08-07 22:52:10 +00:00
|
|
|
giveup_after = PERS_GIVEUP;
|
2002-04-30 22:22:54 +00:00
|
|
|
contacted_sched_server = false;
|
|
|
|
activities_suspended = false;
|
2002-12-01 06:14:28 +00:00
|
|
|
core_client_major_version = MAJOR_VERSION;
|
|
|
|
core_client_minor_version = MINOR_VERSION;
|
2002-05-17 22:33:57 +00:00
|
|
|
platform_name = HOST;
|
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;
|
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;
|
|
|
|
strcpy(proxy_server_name,"");
|
2002-12-18 21:05:18 +00:00
|
|
|
proxy_server_port = 80;
|
2002-12-19 00:00:43 +00:00
|
|
|
strcpy(socks_user_name,"");
|
|
|
|
strcpy(socks_user_passwd,"");
|
2002-12-05 21:56:33 +00:00
|
|
|
suspend_requested = false;
|
2002-12-09 23:51:55 +00:00
|
|
|
#ifdef _WIN32
|
2002-12-18 21:05:18 +00:00
|
|
|
time_tests_handle = NULL;
|
2002-12-09 23:51:55 +00:00
|
|
|
#endif
|
2002-12-18 21:05:18 +00:00
|
|
|
time_tests_id = 0;
|
2002-04-30 22:22:54 +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
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// Read the global preferences file, if it exists.
|
2002-08-12 23:18:47 +00:00
|
|
|
//
|
2002-09-29 00:32:11 +00:00
|
|
|
retval = global_prefs.parse_file();
|
2002-08-12 23:18:47 +00:00
|
|
|
if (retval) {
|
2002-09-29 00:32:11 +00:00
|
|
|
printf("No global preferences file; will use defaults.\n");
|
2002-07-11 01:09:53 +00:00
|
|
|
}
|
2003-02-26 00:47:57 +00:00
|
|
|
install_global_prefs();
|
2002-04-30 22:22:54 +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
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
if (log_flags.state_debug) {
|
2003-01-07 22:49:42 +00:00
|
|
|
print_summary();
|
2002-06-21 06:52:47 +00:00
|
|
|
}
|
2002-12-19 22:43:38 +00:00
|
|
|
|
2002-08-12 23:18:47 +00:00
|
|
|
// Run the time tests and host information check if needed
|
2002-12-05 22:50:21 +00:00
|
|
|
|
|
|
|
// Getting host info is very fast, so we can do it anytime
|
2003-02-20 00:58:55 +00:00
|
|
|
get_host_info(host_info);
|
2002-12-05 22:50:21 +00:00
|
|
|
|
2003-01-13 23:37:56 +00:00
|
|
|
if (gstate.should_run_time_tests()) {
|
2003-02-06 19:01:49 +00:00
|
|
|
time_tests_start = time(NULL);
|
2003-02-21 01:05:43 +00:00
|
|
|
show_message(NULL, "Running time tests", "low");
|
2002-12-09 23:51:55 +00:00
|
|
|
#ifdef _WIN32
|
2003-01-13 23:37:56 +00:00
|
|
|
time_tests_handle = CreateThread(
|
|
|
|
NULL, 0, win_time_tests, NULL, 0, &time_tests_id
|
|
|
|
);
|
2002-12-09 23:51:55 +00:00
|
|
|
#else
|
2003-01-07 01:02:08 +00:00
|
|
|
time_tests_id = fork();
|
2003-01-13 23:37:56 +00:00
|
|
|
if (time_tests_id == 0) {
|
2003-01-07 01:02:08 +00:00
|
|
|
_exit(time_tests());
|
|
|
|
}
|
2002-12-19 22:43:38 +00:00
|
|
|
#endif
|
2002-08-12 23:18:47 +00:00
|
|
|
}
|
2002-12-16 22:34:50 +00:00
|
|
|
|
|
|
|
// Set nslots to actual # of CPUs (or less, depending on prefs?)
|
|
|
|
//
|
2002-12-19 22:43:38 +00:00
|
|
|
if (gstate.host_info.p_ncpus > 0) {
|
2002-12-17 00:23:45 +00:00
|
|
|
nslots = gstate.host_info.p_ncpus;
|
2002-12-19 22:43:38 +00:00
|
|
|
} else {
|
2002-12-17 00:23:45 +00:00
|
|
|
nslots = 1;
|
2002-12-19 22:43:38 +00:00
|
|
|
}
|
|
|
|
|
2002-12-17 00:23:45 +00:00
|
|
|
// set up the project and slot directories
|
|
|
|
//
|
|
|
|
make_project_dirs();
|
|
|
|
make_slot_dirs();
|
|
|
|
|
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
|
|
|
//
|
2002-08-12 23:18:47 +00:00
|
|
|
gstate.restart_tasks();
|
|
|
|
|
2003-02-20 00:58:55 +00:00
|
|
|
// If we're supposed to update prefs, arrange to contact all projects
|
|
|
|
//
|
|
|
|
if (update_prefs) {
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
projects[i]->sched_rpc_pending = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-28 18:32:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if time tests should be run
|
2002-07-15 23:21:20 +00:00
|
|
|
// flag or if it's been a month since we last checked time stats
|
2002-06-28 18:32:18 +00:00
|
|
|
//
|
2003-01-13 23:37:56 +00:00
|
|
|
bool CLIENT_STATE::should_run_time_tests() {
|
|
|
|
return (
|
2003-02-24 21:25:16 +00:00
|
|
|
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
|
|
|
|
DWORD WINAPI CLIENT_STATE::win_time_tests(LPVOID) {
|
2003-01-07 01:02:08 +00:00
|
|
|
return gstate.time_tests();
|
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
|
|
|
//
|
|
|
|
int CLIENT_STATE::time_tests() {
|
2003-01-07 01:02:08 +00:00
|
|
|
HOST_INFO host_info;
|
|
|
|
FILE* finfo;
|
2002-08-30 21:32:31 +00:00
|
|
|
double fpop_test_secs = 2.0;
|
|
|
|
double iop_test_secs = 2.0;
|
|
|
|
double mem_test_secs = 2.0;
|
|
|
|
|
2003-01-13 23:37:56 +00:00
|
|
|
clear_host_info(host_info);
|
2002-08-30 21:32:31 +00:00
|
|
|
if (log_flags.measurement_debug) {
|
2003-01-13 23:37:56 +00:00
|
|
|
printf("Running time tests.\n");
|
2002-08-30 21:32:31 +00:00
|
|
|
}
|
2003-01-13 23:37:56 +00:00
|
|
|
if (run_time_test) {
|
|
|
|
if (log_flags.measurement_debug) {
|
|
|
|
printf(
|
|
|
|
"Running floating point test for about %.1f seconds.\n",
|
|
|
|
fpop_test_secs
|
|
|
|
);
|
|
|
|
}
|
|
|
|
host_info.p_fpops = run_double_prec_test(fpop_test_secs); //these are not
|
2002-08-30 21:32:31 +00:00
|
|
|
|
2003-01-13 23:37:56 +00:00
|
|
|
if (log_flags.measurement_debug) {
|
|
|
|
printf(
|
|
|
|
"Running integer test for about %.1f seconds.\n",
|
|
|
|
iop_test_secs
|
|
|
|
);
|
|
|
|
}
|
|
|
|
host_info.p_iops = run_int_test(iop_test_secs);
|
2002-08-30 21:32:31 +00:00
|
|
|
|
2003-01-13 23:37:56 +00:00
|
|
|
if (log_flags.measurement_debug) {
|
|
|
|
printf(
|
|
|
|
"Running memory bandwidth test for about %.1f seconds.\n",
|
|
|
|
mem_test_secs
|
|
|
|
);
|
|
|
|
}
|
|
|
|
host_info.p_membw = run_mem_bandwidth_test(mem_test_secs);
|
2002-12-09 23:51:55 +00:00
|
|
|
|
2003-01-13 23:37:56 +00:00
|
|
|
// need to check check cache!!
|
|
|
|
host_info.m_cache = 1e6;
|
|
|
|
} else {
|
|
|
|
if (log_flags.measurement_debug) {
|
|
|
|
printf("Using fake performance numbers\n");
|
|
|
|
}
|
|
|
|
host_info.p_fpops = 1e9;
|
|
|
|
host_info.p_iops = 1e9;
|
|
|
|
host_info.p_membw = 4e9;
|
|
|
|
host_info.m_cache = 1e6;
|
|
|
|
}
|
2002-08-30 21:32:31 +00:00
|
|
|
|
2002-10-20 22:12:53 +00:00
|
|
|
host_info.p_calculated = (double)time(0);
|
2003-01-13 23:37:56 +00:00
|
|
|
finfo = fopen(TIME_TESTS_FILE_NAME, "w");
|
|
|
|
if(!finfo) return ERR_FOPEN;
|
|
|
|
host_info.write_time_tests(finfo);
|
|
|
|
fclose(finfo);
|
2003-02-03 22:46:09 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-19 22:43:38 +00:00
|
|
|
// checks if the time tests are running
|
|
|
|
//
|
2002-12-09 23:51:55 +00:00
|
|
|
int CLIENT_STATE::check_time_tests() {
|
2003-01-07 01:02:08 +00:00
|
|
|
FILE* finfo;
|
|
|
|
if (time_tests_id) {
|
2002-12-09 23:51:55 +00:00
|
|
|
#ifdef _WIN32
|
2003-01-07 01:02:08 +00:00
|
|
|
DWORD exit_code = 0;
|
|
|
|
GetExitCodeThread(time_tests_handle, &exit_code);
|
2003-02-03 22:46:09 +00:00
|
|
|
if(exit_code == STILL_ACTIVE) {
|
2003-02-06 19:01:49 +00:00
|
|
|
if(time(NULL) > time_tests_start + MAX_TIME_TESTS_SECONDS) {
|
2003-02-21 01:05:43 +00:00
|
|
|
show_message(NULL, "Time tests timed out, using default values", "low");
|
2003-02-06 19:01:49 +00:00
|
|
|
TerminateThread(time_tests_handle, 0);
|
|
|
|
CloseHandle(time_tests_handle);
|
|
|
|
host_info.p_fpops = 1e9;
|
|
|
|
host_info.p_iops = 1e9;
|
|
|
|
host_info.p_membw = 4e9;
|
|
|
|
host_info.m_cache = 1e6;
|
|
|
|
time_tests_id = 0;
|
|
|
|
return TIME_TESTS_ERROR;
|
|
|
|
}
|
|
|
|
return TIME_TESTS_RUNNING;
|
|
|
|
}
|
2003-01-07 01:02:08 +00:00
|
|
|
CloseHandle(time_tests_handle);
|
2002-12-09 23:51:55 +00:00
|
|
|
#else
|
2003-01-07 01:02:08 +00:00
|
|
|
int retval, exit_code = 0;
|
|
|
|
retval = waitpid(time_tests_id, &exit_code, WNOHANG);
|
2003-02-03 22:46:09 +00:00
|
|
|
if(retval == 0) {
|
2003-02-06 19:01:49 +00:00
|
|
|
if((unsigned int)time(NULL) > time_tests_start + MAX_TIME_TESTS_SECONDS) {
|
2003-02-21 01:05:43 +00:00
|
|
|
show_message(NULL, "Time tests timed out, using default values", "low");
|
2003-02-06 19:01:49 +00:00
|
|
|
kill(time_tests_id, SIGKILL);
|
|
|
|
host_info.p_fpops = 1e9;
|
|
|
|
host_info.p_iops = 1e9;
|
|
|
|
host_info.p_membw = 4e9;
|
|
|
|
host_info.m_cache = 1e6;
|
|
|
|
time_tests_id = 0;
|
|
|
|
return TIME_TESTS_ERROR;
|
|
|
|
}
|
|
|
|
return TIME_TESTS_RUNNING;
|
|
|
|
}
|
2002-12-09 23:51:55 +00:00
|
|
|
#endif
|
2003-01-07 01:02:08 +00:00
|
|
|
time_tests_id = 0;
|
2003-02-21 01:05:43 +00:00
|
|
|
show_message(NULL, "Time tests complete", "low");
|
2003-01-07 01:02:08 +00:00
|
|
|
finfo = fopen(TIME_TESTS_FILE_NAME, "r");
|
2003-02-03 22:46:09 +00:00
|
|
|
if(!finfo) {
|
2003-02-21 01:05:43 +00:00
|
|
|
show_message(NULL, "Error in time tests file, using default values", "low");
|
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;
|
|
|
|
return TIME_TESTS_ERROR;
|
|
|
|
}
|
2003-01-07 01:02:08 +00:00
|
|
|
host_info.parse_time_tests(finfo);
|
|
|
|
fclose(finfo);
|
|
|
|
file_delete(TIME_TESTS_FILE_NAME);
|
|
|
|
return TIME_TESTS_COMPLETE;
|
|
|
|
}
|
|
|
|
return TIME_TESTS_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.
|
|
|
|
// Since there are three different settings in the prefs, it returns 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
|
|
|
|
|
|
|
// Calculate allowed disk usage based on % pref
|
2002-09-29 00:32:11 +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
|
|
|
|
|
|
|
min_val = host_info.d_free - global_prefs.disk_min_free_gb*1e9;
|
2002-08-07 22:52:10 +00:00
|
|
|
|
|
|
|
// Return the minimum of the three
|
2002-09-29 00:32:11 +00:00
|
|
|
//
|
2002-12-06 07:33:45 +00:00
|
|
|
size = min(min(global_prefs.disk_max_used_gb*1e9, percent_space), min_val);
|
2003-02-25 07:56:49 +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
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
// See if (on the basis of user prefs) we should suspend activities.
|
|
|
|
// If so, suspend tasks
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::check_suspend_activities() {
|
|
|
|
bool should_suspend = false;
|
2003-02-21 01:38:16 +00:00
|
|
|
if (!global_prefs.run_on_batteries && host_is_running_on_batteries()) {
|
2002-04-30 22:22:54 +00:00
|
|
|
should_suspend = true;
|
|
|
|
}
|
2002-11-19 22:57:05 +00:00
|
|
|
if (!user_idle) {
|
|
|
|
should_suspend = true;
|
|
|
|
}
|
2003-02-21 01:38:16 +00:00
|
|
|
if (suspend_requested) {
|
2002-11-25 19:44:15 +00:00
|
|
|
should_suspend = true;
|
2002-12-05 21:56:33 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
if (should_suspend) {
|
|
|
|
if (!activities_suspended) {
|
|
|
|
if (log_flags.task_debug) printf("SUSPENDING ACTIVITIES\n");
|
|
|
|
active_tasks.suspend_all();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (activities_suspended) {
|
|
|
|
if (log_flags.task_debug) printf("UNSUSPENDING ACTIVITIES\n");
|
|
|
|
active_tasks.unsuspend_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activities_suspended = should_suspend;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-28 21:50:51 +00:00
|
|
|
static void print_log(char* p) {
|
|
|
|
if (log_flags.poll_debug) {
|
|
|
|
printf(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-18 03:31:47 +00:00
|
|
|
int CLIENT_STATE::net_sleep(double x) {
|
|
|
|
return net_xfers->net_sleep(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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() {
|
2002-08-27 04:59:55 +00:00
|
|
|
bool action = false, x;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-01-13 23:37:56 +00:00
|
|
|
if (check_time_tests() == TIME_TESTS_RUNNING) return false;
|
2002-12-09 23:51:55 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
check_suspend_activities();
|
2003-01-07 22:49:42 +00:00
|
|
|
|
|
|
|
print_log("Polling; active layers:\n");
|
2003-02-26 00:47:57 +00:00
|
|
|
net_stats.poll(*net_xfers);
|
2003-01-07 22:49:42 +00:00
|
|
|
if (activities_suspended) {
|
2003-02-18 03:31:47 +00:00
|
|
|
print_log("None (suspended)\n");
|
2003-01-07 22:49:42 +00:00
|
|
|
} else {
|
2002-08-28 21:50:51 +00:00
|
|
|
// Call these functions in bottom to top order with
|
|
|
|
// respect to the FSM hierarchy
|
|
|
|
|
2003-02-26 00:47:57 +00:00
|
|
|
x = net_xfers->poll();
|
|
|
|
if (x) { action=true; print_log("net_xfers\n"); }
|
2002-08-28 21:50:51 +00:00
|
|
|
|
2002-08-27 04:59:55 +00:00
|
|
|
x = http_ops->poll();
|
2003-01-07 22:49:42 +00:00
|
|
|
if (x) {action=true; print_log("http_ops\n"); }
|
2002-08-28 21:50:51 +00:00
|
|
|
|
2002-08-27 04:59:55 +00:00
|
|
|
x = file_xfers->poll();
|
2003-01-07 22:49:42 +00:00
|
|
|
if (x) {action=true; print_log("file_xfers\n"); }
|
2002-08-28 21:50:51 +00:00
|
|
|
|
2002-12-05 21:56:33 +00:00
|
|
|
x = active_tasks.poll();
|
2002-08-28 21:50:51 +00:00
|
|
|
if (x) {action=true; print_log("active_tasks::poll\n"); }
|
|
|
|
|
2002-08-27 04:59:55 +00:00
|
|
|
x = active_tasks.poll_time();
|
2002-08-28 21:50:51 +00:00
|
|
|
if (x) {action=true; print_log("active_tasks::poll_time\n"); }
|
|
|
|
|
2002-08-27 04:59:55 +00:00
|
|
|
x = scheduler_rpc_poll();
|
2003-01-07 22:49:42 +00:00
|
|
|
if (x) {action=true; print_log("scheduler_rpc\n"); }
|
2002-08-28 21:50:51 +00:00
|
|
|
|
2002-08-27 04:59:55 +00:00
|
|
|
x = start_apps();
|
2002-08-28 21:50:51 +00:00
|
|
|
if (x) {action=true; print_log("start_apps\n"); }
|
|
|
|
|
2002-08-27 04:59:55 +00:00
|
|
|
x = pers_xfers->poll();
|
2003-01-07 22:49:42 +00:00
|
|
|
if (x) {action=true; print_log("pers_xfers\n"); }
|
2002-08-28 21:50:51 +00:00
|
|
|
|
2002-08-27 04:59:55 +00:00
|
|
|
x = handle_running_apps();
|
2002-08-28 21:50:51 +00:00
|
|
|
if (x) {action=true; print_log("handle_running_apps\n"); }
|
|
|
|
|
2002-08-27 04:59:55 +00:00
|
|
|
x = handle_pers_file_xfers();
|
2002-08-28 21:50:51 +00:00
|
|
|
if (x) {action=true; print_log("handle_pers_file_xfers\n"); }
|
|
|
|
|
2002-08-27 04:59:55 +00:00
|
|
|
x = garbage_collect();
|
2002-08-28 21:50:51 +00:00
|
|
|
if (x) {action=true; print_log("garbage_collect\n"); }
|
|
|
|
|
2002-08-27 04:59:55 +00:00
|
|
|
x = update_results();
|
2002-08-28 21:50:51 +00:00
|
|
|
if (x) {action=true; print_log("update_results\n"); }
|
|
|
|
|
2003-01-07 22:49:42 +00:00
|
|
|
if (write_state_file_if_needed()) {
|
2003-02-26 00:47:57 +00:00
|
|
|
fprintf(stderr, "Couldn't write state file");
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-01-07 22:49:42 +00:00
|
|
|
print_log("End poll\n");
|
2002-11-04 21:09:31 +00:00
|
|
|
if (!action) {
|
|
|
|
time_stats.update(true, !activities_suspended);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
char buf[256];
|
|
|
|
FILE* f = fopen(STATE_FILE_NAME, "r");
|
2002-07-31 19:05:15 +00:00
|
|
|
PROJECT temp_project, *project;
|
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-01-07 01:02:08 +00:00
|
|
|
global_prefs.confirm_before_connecting = false;
|
|
|
|
global_prefs.hangup_if_dialed = false;
|
2002-12-18 20:18:06 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!f) {
|
|
|
|
if (log_flags.state_debug) {
|
2002-05-17 22:33:57 +00:00
|
|
|
printf("No state file; will create one\n");
|
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 {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Project %s found in state file but not prefs.\n",
|
2002-07-31 19:05:15 +00:00
|
|
|
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);
|
2002-11-26 00:47:57 +00:00
|
|
|
retval = pers_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);
|
2002-08-12 21:54:19 +00:00
|
|
|
rp->state = RESULT_NEW;
|
2002-06-21 06:52:47 +00:00
|
|
|
} else {
|
2002-08-27 04:59:55 +00:00
|
|
|
fprintf(stderr, "error: link_result failed\n");
|
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>")) {
|
|
|
|
host_info.parse(f);
|
|
|
|
} else if (match_tag(buf, "<time_stats>")) {
|
|
|
|
time_stats.parse(f);
|
|
|
|
} else if (match_tag(buf, "<net_stats>")) {
|
|
|
|
net_stats.parse(f);
|
|
|
|
} else if (match_tag(buf, "<active_task_set>")) {
|
|
|
|
active_tasks.parse(f, this);
|
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
|
2002-12-05 21:56:33 +00:00
|
|
|
} else if (match_tag(buf, "<core_client_major_version>")) {
|
|
|
|
// TODO: handle old client state file if different version
|
|
|
|
} else if (match_tag(buf, "<core_client_minor_version>")) {
|
|
|
|
// TODO: handle old client state file if different version
|
2002-12-19 00:00:43 +00:00
|
|
|
} else if (match_tag(buf, "<confirm_before_connect/>")) {
|
2003-01-02 23:12:05 +00:00
|
|
|
global_prefs.confirm_before_connecting = true;
|
2002-12-18 20:18:06 +00:00
|
|
|
} else if (match_tag(buf, "<hangup_if_dialed/>")) {
|
2003-01-02 23:12:05 +00:00
|
|
|
global_prefs.hangup_if_dialed = true;
|
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;
|
|
|
|
} 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))) {
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "CLIENT_STATE::parse_state_file: unrecognized: %s\n", buf);
|
2002-08-29 05:15:54 +00:00
|
|
|
retval = ERR_XML_PARSE;
|
|
|
|
goto done;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-29 05:15:54 +00:00
|
|
|
done:
|
|
|
|
fclose(f);
|
|
|
|
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;
|
|
|
|
|
2002-06-10 06:14:18 +00:00
|
|
|
if (log_flags.state_debug) {
|
|
|
|
printf("Writing state file\n");
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!f) {
|
|
|
|
fprintf(stderr, "can't open temp state file: %s\n", STATE_FILE_TEMP);
|
|
|
|
return ERR_FOPEN;
|
|
|
|
}
|
|
|
|
fprintf(f, "<client_state>\n");
|
|
|
|
host_info.write(f);
|
|
|
|
time_stats.write(f, false);
|
|
|
|
net_stats.write(f, false);
|
|
|
|
for (j=0; j<projects.size(); j++) {
|
|
|
|
PROJECT* p = projects[j];
|
2002-06-21 06:52:47 +00:00
|
|
|
p->write_state(f);
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<apps.size(); i++) {
|
|
|
|
if (apps[i]->project == p) apps[i]->write(f);
|
|
|
|
}
|
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
|
|
|
if (file_infos[i]->project == p) {
|
|
|
|
file_infos[i]->write(f, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
// save proxy and preferences info
|
|
|
|
//
|
2002-12-10 01:10:56 +00:00
|
|
|
fprintf(f,
|
2002-12-18 20:18:06 +00:00
|
|
|
"%s"
|
|
|
|
"%s"
|
2002-12-10 01:10:56 +00:00
|
|
|
"%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":"",
|
|
|
|
global_prefs.confirm_before_connecting?"<confirm_before_connect/>\n":"",
|
2002-12-18 20:18:06 +00:00
|
|
|
global_prefs.hangup_if_dialed?"<hangup_if_dialed/>\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
|
|
|
);
|
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);
|
2002-06-10 06:14:18 +00:00
|
|
|
if (log_flags.state_debug) {
|
|
|
|
printf("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
|
|
|
// TODO: write no more often than X seconds
|
|
|
|
// Write the client_state.xml file if necessary
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::write_state_file_if_needed() {
|
|
|
|
int retval;
|
|
|
|
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
|
|
|
|
// in the client state record.
|
|
|
|
//
|
2002-06-21 06:52:47 +00:00
|
|
|
PROJECT* CLIENT_STATE::lookup_project(char* master_url) {
|
2002-04-30 22:22:54 +00:00
|
|
|
for (unsigned int i=0; i<projects.size(); i++) {
|
2002-06-21 06:52:47 +00:00
|
|
|
if (!strcmp(master_url, projects[i]->master_url)) {
|
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;
|
|
|
|
}
|
|
|
|
|
2002-11-09 01:15:38 +00:00
|
|
|
// Find the active task for a given workunit
|
|
|
|
//
|
2002-11-15 20:27:47 +00:00
|
|
|
ACTIVE_TASK* CLIENT_STATE::lookup_active_task_by_result(RESULT* rep)
|
2002-11-09 01:15:38 +00:00
|
|
|
{
|
2002-11-16 00:40:25 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"app_version refers to nonexistent app: %s\n", avp->app_name
|
|
|
|
);
|
|
|
|
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) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"app_version refers to nonexistent file: %s\n",
|
|
|
|
file_ref.file_name
|
|
|
|
);
|
|
|
|
return 1;
|
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
|
|
|
|
// any file associated with an app version must be signed
|
|
|
|
//
|
|
|
|
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) {
|
|
|
|
fprintf(stderr,
|
2002-05-17 22:33:57 +00:00
|
|
|
"I/O desc links 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) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"WU refers to nonexistent app: %s\n", wup->app_name
|
|
|
|
);
|
|
|
|
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) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"WU refers to nonexistent app_version: %s %d\n",
|
|
|
|
wup->app_name, wup->version_num
|
|
|
|
);
|
|
|
|
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) {
|
2002-08-27 04:59:55 +00:00
|
|
|
fprintf(stderr, "error: link_result: link_file_ref failed\n");
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, "CLIENT_STATE::latest_version_num: no version\n");
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
printf("Client state summary:\n");
|
|
|
|
printf(" %d projects\n", (int)projects.size());
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
2003-01-09 07:24:27 +00:00
|
|
|
printf(" %s", projects[i]->master_url);
|
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-01-13 23:37:56 +00:00
|
|
|
printf(" min RPC %d seconds from now", (int)(t-time(0)));
|
2003-01-09 07:24:27 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
|
|
|
printf(" %d file_infos\n", (int)file_infos.size());
|
|
|
|
for (i=0; i<file_infos.size(); i++) {
|
|
|
|
printf(" %s status:%d %s\n", file_infos[i]->name, file_infos[i]->status, file_infos[i]->pers_file_xfer?"active":"inactive");
|
|
|
|
}
|
|
|
|
printf(" %d app_versions\n", (int)app_versions.size());
|
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
printf(" %s %d\n", app_versions[i]->app_name, app_versions[i]->version_num);
|
|
|
|
}
|
|
|
|
printf(" %d workunits\n", (int)workunits.size());
|
|
|
|
for (i=0; i<workunits.size(); i++) {
|
|
|
|
printf(" %s\n", workunits[i]->name);
|
|
|
|
}
|
|
|
|
printf(" %d results\n", (int)results.size());
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
printf(" %s state:%d\n", results[i]->name, results[i]->state);
|
|
|
|
}
|
|
|
|
printf(" %d persistent file xfers\n", (int)pers_xfers->pers_file_xfers.size());
|
|
|
|
for (i=0; i<pers_xfers->pers_file_xfers.size(); i++) {
|
2003-02-12 19:21:44 +00:00
|
|
|
printf(" %s http op state: %d\n", pers_xfers->pers_file_xfers[i]->fip->name, (pers_xfers->pers_file_xfers[i]->fxp?pers_xfers->pers_file_xfers[i]->fxp->http_op_state:-1));
|
2003-01-07 22:49:42 +00:00
|
|
|
}
|
|
|
|
printf(" %d active tasks\n", (int)active_tasks.active_tasks.size());
|
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
|
|
|
printf(" %s\n", active_tasks.active_tasks[i]->result->name);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete unneeded records and files
|
|
|
|
//
|
|
|
|
bool CLIENT_STATE::garbage_collect() {
|
|
|
|
unsigned int i;
|
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;
|
|
|
|
vector<RESULT*>::iterator result_iter;
|
|
|
|
vector<WORKUNIT*>::iterator wu_iter;
|
|
|
|
vector<FILE_INFO*>::iterator fi_iter;
|
|
|
|
bool action = false;
|
2002-12-05 21:35:51 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// zero references counts on WUs and FILE_INFOs
|
|
|
|
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;
|
|
|
|
}
|
2002-08-07 22:52:10 +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) {
|
2002-04-30 22:22:54 +00:00
|
|
|
if (log_flags.state_debug) printf("deleting result %s\n", rp->name);
|
|
|
|
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
|
|
|
//
|
2002-12-05 21:56:33 +00:00
|
|
|
if(rp->wup->had_failure(failnum)) {
|
|
|
|
// 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).
|
|
|
|
//
|
|
|
|
report_project_error(
|
|
|
|
*rp,0,
|
2003-02-06 01:02:56 +00:00
|
|
|
"The work_unit corresponding to this result had an error"
|
2003-01-02 23:12:05 +00:00
|
|
|
);
|
2002-12-05 21:56:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rp->wup->ref_cnt++;
|
2002-10-10 22:36:21 +00:00
|
|
|
}
|
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
|
|
|
|
//
|
|
|
|
report_project_error(*rp,0,
|
2003-02-06 01:02:56 +00:00
|
|
|
"An output file of this result had an error"
|
2003-02-18 22:53:10 +00:00
|
|
|
);
|
2002-12-05 21:56:33 +00:00
|
|
|
}
|
2002-08-12 21:54:19 +00:00
|
|
|
} else {
|
|
|
|
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;
|
|
|
|
// reference-count files referred to by other WUs
|
|
|
|
//
|
|
|
|
wu_iter = workunits.begin();
|
|
|
|
while (wu_iter != workunits.end()) {
|
|
|
|
wup = *wu_iter;
|
|
|
|
if (wup->ref_cnt == 0) {
|
2002-06-10 06:14:18 +00:00
|
|
|
if (log_flags.state_debug) {
|
|
|
|
printf("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++;
|
|
|
|
}
|
|
|
|
wu_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete FILE_INFOs (and corresponding files)
|
|
|
|
// that are not referenced by any WORKUNIT or RESULT,
|
|
|
|
// and are not sticky.
|
|
|
|
//
|
|
|
|
fi_iter = file_infos.begin();
|
|
|
|
while (fi_iter != file_infos.end()) {
|
|
|
|
fip = *fi_iter;
|
|
|
|
if (fip->ref_cnt==0 && !fip->sticky && !fip->executable) {
|
|
|
|
fip->delete_file();
|
|
|
|
if (log_flags.state_debug) printf("deleting file %s\n", fip->name);
|
|
|
|
delete fip;
|
|
|
|
fi_iter = file_infos.erase(fi_iter);
|
|
|
|
action = true;
|
|
|
|
} else {
|
|
|
|
fi_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: delete obsolete APP_VERSIONs
|
|
|
|
|
2003-01-07 22:49:42 +00:00
|
|
|
if (action && log_flags.state_debug) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
if(rp->server_ack)
|
|
|
|
action = true;
|
|
|
|
|
2002-08-12 21:54:19 +00:00
|
|
|
switch (rp->state) {
|
2003-02-06 19:01:49 +00:00
|
|
|
case RESULT_NEW:
|
|
|
|
if (input_files_available(rp)) {
|
|
|
|
rp->state = RESULT_FILES_DOWNLOADED;
|
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESULT_FILES_DOWNLOADED:
|
|
|
|
// The transition to COMPUTE_DONE is performed
|
|
|
|
// in app_finished()
|
|
|
|
break;
|
|
|
|
case RESULT_COMPUTE_DONE:
|
|
|
|
// Once the computation has been done, check
|
|
|
|
// that the necessary files have been uploaded
|
|
|
|
// before moving on
|
|
|
|
if (rp->is_upload_done()) {
|
|
|
|
rp->ready_to_ack = true;
|
|
|
|
rp->state = RESULT_FILES_UPLOADED;
|
|
|
|
action = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESULT_FILES_UPLOADED:
|
|
|
|
// The transition to SERVER_ACK is performed in
|
|
|
|
// handle_scheduler_reply()
|
|
|
|
break;
|
2002-08-12 21:54:19 +00:00
|
|
|
}
|
|
|
|
result_iter++;
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
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;
|
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-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-no_time_test")) {
|
2002-06-28 18:32:18 +00:00
|
|
|
run_time_test = false;
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-exit_after_app_start")) {
|
2003-02-12 19:53:46 +00:00
|
|
|
exit_after_app_start_secs = atoi(argv[++i]);
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-giveup_after")) {
|
2002-09-26 05:57:10 +00:00
|
|
|
giveup_after = 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-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-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-update_prefs")) {
|
2003-02-20 00:58:55 +00:00
|
|
|
update_prefs = true;
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-add_new_project")) {
|
2002-12-19 22:43:38 +00:00
|
|
|
add_new_project();
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-version")) {
|
2002-12-18 21:05:18 +00:00
|
|
|
printf( "%.2f %s\n", MAJOR_VERSION+(MINOR_VERSION/100.0), HOST );
|
2003-01-07 01:02:08 +00:00
|
|
|
exit(0);
|
2003-02-26 00:47:57 +00:00
|
|
|
} else if (!strcmp(argv[i], "-help")) {
|
2002-12-19 22:43:38 +00:00
|
|
|
printf(
|
2003-02-20 00:58:55 +00:00
|
|
|
"Usage: %s [options]\n"
|
2002-12-19 22:43:38 +00:00
|
|
|
" -version show version info\n"
|
2003-02-20 00:58:55 +00:00
|
|
|
" -add_new_project add project (will prompt for URL, account key)\n",
|
|
|
|
argv[0]
|
2002-12-19 22:43:38 +00:00
|
|
|
);
|
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]);
|
|
|
|
exit(1);
|
2002-12-18 21:05:18 +00:00
|
|
|
}
|
2002-12-09 03:07:36 +00:00
|
|
|
}
|
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"))) {
|
|
|
|
strcpy(socks_user_name, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((p = getenv("SOCKS_PASSWD"))) {
|
|
|
|
strcpy(socks_user_name, p);
|
|
|
|
}
|
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) {
|
2002-08-26 22:50:36 +00:00
|
|
|
if (log_flags.state_debug) {
|
|
|
|
printf("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.
|
|
|
|
// The error will appear in the stderr_out field of the result.
|
2002-12-19 22:43:38 +00:00
|
|
|
//
|
2003-02-20 00:58:55 +00:00
|
|
|
// It goes through the input and output files for this result
|
|
|
|
// 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,
|
|
|
|
// in which case err_num is set to the an OS-specific error_code.
|
|
|
|
// 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-02-20 00:58:55 +00:00
|
|
|
// or it gets signaled, relevant info is printed to stderr_out of res.
|
2002-12-19 22:43:38 +00:00
|
|
|
//
|
|
|
|
int CLIENT_STATE::report_project_error(
|
2003-02-06 01:02:56 +00:00
|
|
|
RESULT& res, int err_num, char *err_msg
|
2003-02-20 00:58:55 +00:00
|
|
|
) {
|
2003-02-11 00:52:44 +00:00
|
|
|
char total_err[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-02-06 01:02:56 +00:00
|
|
|
if (res.ready_to_ack) {
|
2002-12-19 22:43:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-02-06 01:02:56 +00:00
|
|
|
|
|
|
|
res.ready_to_ack = true;
|
2003-01-07 01:02:08 +00:00
|
|
|
|
2003-02-06 01:02:56 +00:00
|
|
|
scheduler_op->backoff(res.project, "");
|
2002-12-09 22:36:46 +00:00
|
|
|
|
2003-02-20 00:58:55 +00:00
|
|
|
sprintf(
|
|
|
|
total_err,
|
2002-12-19 22:43:38 +00:00
|
|
|
"<message>%s</message>\n"
|
|
|
|
"<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
|
|
|
|
);
|
2002-12-09 22:36:46 +00:00
|
|
|
|
2003-02-11 00:52:44 +00:00
|
|
|
if (strlen(res.stderr_out)+strlen(total_err) < MAX_BLOB_LEN) {
|
2002-12-09 22:36:46 +00:00
|
|
|
strcat(res.stderr_out, total_err );
|
|
|
|
}
|
|
|
|
|
2003-02-06 01:02:56 +00:00
|
|
|
if ((res.state == RESULT_FILES_DOWNLOADED) && err_num) {
|
2002-12-19 22:43:38 +00:00
|
|
|
sprintf(total_err,"<couldnt_start>%d</couldnt_start>\n", err_num);
|
2003-02-11 00:52:44 +00:00
|
|
|
if (strlen(res.stderr_out)+strlen(total_err) < MAX_BLOB_LEN) {
|
2002-12-19 22:43:38 +00:00
|
|
|
strcat(res.stderr_out, total_err );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
sprintf(total_err,
|
|
|
|
"<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-02-11 00:52:44 +00:00
|
|
|
if (strlen(res.stderr_out)+strlen(total_err) < MAX_BLOB_LEN ) {
|
2002-12-19 22:43:38 +00:00
|
|
|
strcat( res.stderr_out, total_err );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
sprintf(total_err,
|
|
|
|
"<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-02-11 00:52:44 +00:00
|
|
|
if (strlen(res.stderr_out)+strlen(total_err) < MAX_BLOB_LEN ) {
|
2002-12-19 22:43:38 +00:00
|
|
|
strcat( res.stderr_out, total_err );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-18 20:43:49 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|