2003-10-18 19:35:58 +00:00
|
|
|
// The contents of this file are subject to the BOINC 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
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
|
|
|
//
|
|
|
|
// 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):
|
|
|
|
//
|
|
|
|
|
2004-01-30 22:19:19 +00:00
|
|
|
// Logic related to general (also known as global) preferences:
|
|
|
|
// when to compute, how much disk to use, etc.
|
|
|
|
//
|
|
|
|
|
2004-03-05 04:37:53 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2004-03-05 04:37:53 +00:00
|
|
|
#endif
|
|
|
|
|
2004-06-10 00:12:29 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
#if HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-04-07 06:51:42 +00:00
|
|
|
#include "util.h"
|
2003-10-18 19:35:58 +00:00
|
|
|
#include "filesys.h"
|
2004-10-01 18:48:34 +00:00
|
|
|
#include "parse.h"
|
2003-10-18 19:35:58 +00:00
|
|
|
#include "file_names.h"
|
2003-10-19 19:03:49 +00:00
|
|
|
#include "cpu_benchmark.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2003-10-18 19:35:58 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::min;
|
|
|
|
using std::string;
|
|
|
|
|
2003-10-18 19:35:58 +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;
|
2004-03-31 23:39:12 +00:00
|
|
|
|
2004-06-30 01:10:22 +00:00
|
|
|
// max_cpus may have changed, so update ncpus
|
2004-03-31 23:39:12 +00:00
|
|
|
//
|
2004-06-30 01:10:22 +00:00
|
|
|
set_ncpus();
|
2003-10-18 19:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the maximum allowed disk usage as determined by user preferences.
|
|
|
|
// There are three different settings in the prefs;
|
|
|
|
// return the least of the three.
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::allowed_disk_usage(double& size) {
|
|
|
|
double percent_space, min_val;
|
|
|
|
|
2004-07-09 00:14:23 +00:00
|
|
|
percent_space = host_info.d_total*global_prefs.disk_max_used_pct/100.0;
|
2003-10-18 19:35:58 +00:00
|
|
|
|
|
|
|
min_val = host_info.d_free - global_prefs.disk_min_free_gb*(1024.*1024.*1024.);
|
|
|
|
|
|
|
|
size = min(min(global_prefs.disk_max_used_gb*(1024.*1024.*1024.), percent_space), min_val);
|
2004-08-12 10:13:01 +00:00
|
|
|
if (size < 0) size = 0;
|
2003-10-18 19:35:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::project_disk_usage(PROJECT* p, double& size) {
|
2004-07-21 21:30:25 +00:00
|
|
|
char buf[256];
|
|
|
|
unsigned int i;
|
|
|
|
double s;
|
2003-10-18 19:35:58 +00:00
|
|
|
|
2004-07-21 21:30:25 +00:00
|
|
|
get_project_dir(p, buf);
|
|
|
|
dir_size(buf, size);
|
2003-11-04 22:22:06 +00:00
|
|
|
|
2004-07-21 21:30:25 +00:00
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks.active_tasks[i];
|
|
|
|
if (atp->wup->project != p) continue;
|
|
|
|
get_slot_dir(atp->slot, buf);
|
|
|
|
dir_size(buf, s);
|
|
|
|
size += s;
|
|
|
|
}
|
2003-10-18 19:35:58 +00:00
|
|
|
|
2004-07-21 21:30:25 +00:00
|
|
|
return 0;
|
2003-10-18 19:35:58 +00:00
|
|
|
}
|
|
|
|
|
2003-11-04 22:22:06 +00:00
|
|
|
int CLIENT_STATE::total_disk_usage(double& size) {
|
2003-10-18 19:35:58 +00:00
|
|
|
return dir_size(".", size);
|
|
|
|
}
|
|
|
|
|
2004-08-06 17:32:22 +00:00
|
|
|
int CLIENT_STATE::allowed_project_disk_usage(double& size) {
|
|
|
|
double other_disk_used;
|
|
|
|
double total_disk_available;
|
|
|
|
double project_disk_used;
|
|
|
|
total_disk_usage(other_disk_used);
|
|
|
|
allowed_disk_usage(total_disk_available);
|
|
|
|
for(unsigned int i=0; i<projects.size(); i++) {
|
|
|
|
project_disk_usage(projects[i], project_disk_used);
|
|
|
|
other_disk_used -= project_disk_used;
|
|
|
|
}
|
|
|
|
size = total_disk_available - other_disk_used;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-18 19:35:58 +00:00
|
|
|
// returns true if start_hour == end_hour or start_hour <= now < end_hour
|
|
|
|
//
|
|
|
|
inline bool now_between_two_hours(int start_hour, int end_hour) {
|
|
|
|
if (start_hour == end_hour) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t now = time(0);
|
|
|
|
struct tm *tmp = localtime(&now);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-10 00:12:29 +00:00
|
|
|
|
2003-10-18 19:35:58 +00:00
|
|
|
// See if (on the basis of user run request and prefs)
|
|
|
|
// we should suspend activities.
|
|
|
|
//
|
2004-11-21 06:33:14 +00:00
|
|
|
int CLIENT_STATE::check_suspend_activities(double now, int& reason) {
|
2004-11-18 22:18:00 +00:00
|
|
|
static double last_time = 0;
|
2003-10-18 19:35:58 +00:00
|
|
|
reason = 0;
|
|
|
|
|
|
|
|
// Don't work while we're running CPU benchmarks
|
|
|
|
//
|
2004-03-21 00:10:15 +00:00
|
|
|
if (are_cpu_benchmarks_running()) {
|
2003-10-18 19:35:58 +00:00
|
|
|
reason |= SUSPEND_REASON_BENCHMARKS;
|
|
|
|
}
|
|
|
|
|
2004-11-21 06:33:14 +00:00
|
|
|
if (user_run_request == USER_RUN_REQUEST_ALWAYS) return 0;
|
2003-10-18 19:35:58 +00:00
|
|
|
|
|
|
|
if (user_run_request == USER_RUN_REQUEST_NEVER) {
|
|
|
|
reason |= SUSPEND_REASON_USER_REQ;
|
2004-11-21 06:33:14 +00:00
|
|
|
return 0;
|
2003-10-18 19:35:58 +00:00
|
|
|
}
|
|
|
|
|
2004-11-21 06:33:14 +00:00
|
|
|
if (now - last_time < 5.0) return 1;
|
|
|
|
last_time = now;
|
|
|
|
|
2004-03-31 19:43:15 +00:00
|
|
|
if (!global_prefs.run_on_batteries
|
|
|
|
&& host_info.host_is_running_on_batteries()
|
|
|
|
) {
|
2003-10-18 19:35:58 +00:00
|
|
|
reason |= SUSPEND_REASON_BATTERIES;
|
|
|
|
}
|
|
|
|
|
2004-06-29 19:54:50 +00:00
|
|
|
if (!global_prefs.run_if_user_active
|
|
|
|
&& !host_info.users_idle(
|
|
|
|
check_all_logins, global_prefs.idle_time_to_run
|
|
|
|
)
|
|
|
|
) {
|
2003-10-18 19:35:58 +00:00
|
|
|
reason |= SUSPEND_REASON_USER_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!now_between_two_hours(global_prefs.start_hour, global_prefs.end_hour)) {
|
|
|
|
reason |= SUSPEND_REASON_TIME_OF_DAY;
|
|
|
|
}
|
2004-08-05 21:42:26 +00:00
|
|
|
|
2004-11-21 06:33:14 +00:00
|
|
|
return 0;
|
2003-10-18 19:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::suspend_activities(int reason) {
|
|
|
|
string s_reason;
|
2004-04-01 23:19:13 +00:00
|
|
|
s_reason = "Suspending computation and network activity";
|
2003-10-18 19:35:58 +00:00
|
|
|
if (reason & SUSPEND_REASON_BATTERIES) {
|
|
|
|
s_reason += " - on batteries";
|
|
|
|
}
|
|
|
|
if (reason & SUSPEND_REASON_USER_ACTIVE) {
|
|
|
|
s_reason += " - user is active";
|
|
|
|
}
|
|
|
|
if (reason & SUSPEND_REASON_USER_REQ) {
|
|
|
|
s_reason += " - user request";
|
|
|
|
}
|
|
|
|
if (reason & SUSPEND_REASON_TIME_OF_DAY) {
|
|
|
|
s_reason += " - time of day";
|
|
|
|
}
|
|
|
|
if (reason & SUSPEND_REASON_BENCHMARKS) {
|
|
|
|
s_reason += " - running CPU benchmarks";
|
|
|
|
}
|
2004-08-06 17:32:22 +00:00
|
|
|
if (reason & SUSPEND_REASON_DISK_SIZE) {
|
2004-08-23 22:06:48 +00:00
|
|
|
s_reason += " - out of disk space - change global prefs";
|
2004-08-06 17:32:22 +00:00
|
|
|
}
|
2003-10-18 19:35:58 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, const_cast<char*>(s_reason.c_str()));
|
2004-08-06 23:17:59 +00:00
|
|
|
active_tasks.suspend_all(global_prefs.leave_apps_in_memory);
|
2003-10-18 19:35:58 +00:00
|
|
|
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() {
|
2004-04-02 00:19:22 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Resuming computation and network activity");
|
2003-10-18 19:35:58 +00:00
|
|
|
active_tasks.unsuspend_all();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-11-18 22:18:00 +00:00
|
|
|
void CLIENT_STATE::check_suspend_network(double now, int& reason) {
|
2004-04-01 23:19:13 +00:00
|
|
|
reason = 0;
|
|
|
|
|
|
|
|
if (user_network_request == USER_RUN_REQUEST_ALWAYS) return;
|
|
|
|
if (user_network_request == USER_RUN_REQUEST_NEVER) {
|
|
|
|
reason |= SUSPEND_REASON_USER_REQ;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::suspend_network(int reason) {
|
|
|
|
string s_reason;
|
|
|
|
s_reason = "Suspending network activity";
|
|
|
|
if (reason & SUSPEND_REASON_USER_REQ) {
|
|
|
|
s_reason += " - user request";
|
|
|
|
}
|
|
|
|
msg_printf(NULL, MSG_INFO, const_cast<char*>(s_reason.c_str()));
|
|
|
|
pers_file_xfers->suspend();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLIENT_STATE::resume_network() {
|
2004-04-02 00:19:22 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Resuming network activity");
|
2004-04-01 23:19:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-10-01 08:15:58 +00:00
|
|
|
// call this only after parsing global prefs
|
|
|
|
//
|
|
|
|
PROJECT* CLIENT_STATE::global_prefs_source_project() {
|
2004-10-06 19:09:37 +00:00
|
|
|
return lookup_project(global_prefs.source_project);
|
2004-10-01 08:15:58 +00:00
|
|
|
}
|
|
|
|
|
2004-03-30 23:05:34 +00:00
|
|
|
void CLIENT_STATE::show_global_prefs_source(bool found_venue) {
|
2004-10-01 08:15:58 +00:00
|
|
|
PROJECT* pp = global_prefs_source_project();
|
2004-03-30 23:05:34 +00:00
|
|
|
if (pp) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"General prefs: from %s (last modified %s)\n",
|
|
|
|
pp->get_project_name(), time_to_string(global_prefs.mod_time)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"General prefs: from unknown project %s (last modified %s)\n",
|
2004-10-06 19:09:37 +00:00
|
|
|
global_prefs.source_project,
|
2004-03-30 23:05:34 +00:00
|
|
|
time_to_string(global_prefs.mod_time)
|
|
|
|
);
|
|
|
|
}
|
2004-10-01 08:15:58 +00:00
|
|
|
if (strlen(main_host_venue)) {
|
2004-03-30 23:05:34 +00:00
|
|
|
if (found_venue) {
|
2004-03-31 23:39:12 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2004-10-01 08:15:58 +00:00
|
|
|
"General prefs: using separate prefs for %s\n", main_host_venue
|
2004-03-31 23:39:12 +00:00
|
|
|
);
|
2004-03-30 23:05:34 +00:00
|
|
|
} else {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
2004-03-31 23:39:12 +00:00
|
|
|
"General prefs: no separate prefs for %s; using your defaults\n",
|
2004-10-01 08:15:58 +00:00
|
|
|
main_host_venue
|
2004-03-31 23:39:12 +00:00
|
|
|
);
|
2004-03-30 23:05:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
msg_printf(NULL, MSG_INFO, "General prefs: using your defaults\n");
|
|
|
|
}
|
|
|
|
}
|
2004-10-01 18:48:34 +00:00
|
|
|
|
|
|
|
// parse user's project preferences,
|
|
|
|
// generating FILE_REF and FILE_INFO objects for each <app_file> element.
|
|
|
|
//
|
|
|
|
int PROJECT::parse_preferences_for_user_files() {
|
|
|
|
char* p, *q, *q2;
|
|
|
|
char buf[1024];
|
|
|
|
string timestamp, open_name, url, filename;
|
|
|
|
FILE_INFO* fip;
|
|
|
|
FILE_REF fr;
|
|
|
|
STRING256 url_str;
|
|
|
|
char prefs_buf[MAX_BLOB_LEN];
|
|
|
|
strcpy(prefs_buf, project_specific_prefs.c_str());
|
|
|
|
p = prefs_buf;
|
|
|
|
|
|
|
|
user_files.clear();
|
|
|
|
while (1) {
|
|
|
|
q = strstr(p, "<app_file>");
|
|
|
|
if (!q) break;
|
|
|
|
q2 = strstr(q, "</app_file>");
|
|
|
|
if (!q2) break;
|
|
|
|
*q2 = 0;
|
|
|
|
strcpy(buf, q);
|
|
|
|
if (!parse_str(buf, "<timestamp>", timestamp)) break;
|
|
|
|
if (!parse_str(buf, "<open_name>", open_name)) break;
|
|
|
|
if (!parse_str(buf, "<url>", url)) break;
|
|
|
|
strcpy(url_str.text, url.c_str());
|
|
|
|
|
|
|
|
filename = open_name + "_" + timestamp;
|
|
|
|
fip = gstate.lookup_file_info(this, filename.c_str());
|
|
|
|
if (!fip) {
|
|
|
|
fip = new FILE_INFO;
|
|
|
|
fip->project = this;
|
|
|
|
fip->urls.push_back(url_str);
|
|
|
|
strcpy(fip->name, filename.c_str());
|
|
|
|
fip->is_user_file = true;
|
|
|
|
gstate.file_infos.push_back(fip);
|
|
|
|
}
|
|
|
|
|
|
|
|
fr.file_info = fip;
|
|
|
|
strcpy(fr.open_name, open_name.c_str());
|
|
|
|
user_files.push_back(fr);
|
|
|
|
|
|
|
|
p = q2+strlen("</app_file>");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_92ad99cddf = "$Id$";
|