- client: more fixes to GUI RPC addition.

Also, replace get_project_dir() with a memoized member function of PROJECT
This commit is contained in:
David Anderson 2013-04-18 13:57:33 -07:00
parent 0880c7107a
commit 64d7fa3474
11 changed files with 57 additions and 62 deletions

View File

@ -420,14 +420,13 @@ void ACTIVE_TASK_SET::get_memory_usage() {
// Move it from slot dir to project dir // Move it from slot dir to project dir
// //
int ACTIVE_TASK::move_trickle_file() { int ACTIVE_TASK::move_trickle_file() {
char project_dir[MAXPATHLEN], new_path[MAXPATHLEN], old_path[MAXPATHLEN]; char new_path[MAXPATHLEN], old_path[MAXPATHLEN];
int retval; int retval;
get_project_dir(result->project, project_dir, sizeof(project_dir));
sprintf(old_path, "%s/trickle_up.xml", slot_dir); sprintf(old_path, "%s/trickle_up.xml", slot_dir);
sprintf(new_path, sprintf(new_path,
"%s/trickle_up_%s_%d.xml", "%s/trickle_up_%s_%d.xml",
project_dir, result->name, (int)time(0) result->project->project_dir(), result->name, (int)time(0)
); );
retval = boinc_rename(old_path, new_path); retval = boinc_rename(old_path, new_path);

View File

@ -118,13 +118,12 @@ void max_concurrent_init() {
} }
void check_app_config() { void check_app_config() {
char dir[256], path[MAXPATHLEN]; char path[MAXPATHLEN];
FILE* f; FILE* f;
for (unsigned int i=0; i<gstate.projects.size(); i++) { for (unsigned int i=0; i<gstate.projects.size(); i++) {
PROJECT* p = gstate.projects[i]; PROJECT* p = gstate.projects[i];
get_project_dir(p, dir, sizeof(dir)); sprintf(path, "%s/%s", p->project_dir(), APP_CONFIG_FILE_NAME);
sprintf(path, "%s/%s", dir, APP_CONFIG_FILE_NAME);
f = boinc_fopen(path, "r"); f = boinc_fopen(path, "r");
if (!f) continue; if (!f) continue;
msg_printf(p, MSG_INFO, msg_printf(p, MSG_INFO,

View File

@ -193,8 +193,6 @@ int ACTIVE_TASK::get_shmem_seg_name() {
} }
void ACTIVE_TASK::init_app_init_data(APP_INIT_DATA& aid) { void ACTIVE_TASK::init_app_init_data(APP_INIT_DATA& aid) {
char project_dir[256], project_path[MAXPATHLEN];
aid.major_version = BOINC_MAJOR_VERSION; aid.major_version = BOINC_MAJOR_VERSION;
aid.minor_version = BOINC_MINOR_VERSION; aid.minor_version = BOINC_MINOR_VERSION;
aid.release = BOINC_RELEASE; aid.release = BOINC_RELEASE;
@ -212,9 +210,7 @@ void ACTIVE_TASK::init_app_init_data(APP_INIT_DATA& aid) {
aid.hostid = wup->project->hostid; aid.hostid = wup->project->hostid;
safe_strcpy(aid.user_name, wup->project->user_name); safe_strcpy(aid.user_name, wup->project->user_name);
safe_strcpy(aid.team_name, wup->project->team_name); safe_strcpy(aid.team_name, wup->project->team_name);
get_project_dir(wup->project, project_dir, sizeof(project_dir)); strcpy(aid.project_dir, wup->project->project_dir_absolute());
relative_to_absolute(project_dir, project_path);
strcpy(aid.project_dir, project_path);
relative_to_absolute("", aid.boinc_dir); relative_to_absolute("", aid.boinc_dir);
strcpy(aid.authenticator, wup->project->authenticator); strcpy(aid.authenticator, wup->project->authenticator);
aid.slot = slot; aid.slot = slot;
@ -941,8 +937,7 @@ int ACTIVE_TASK::start() {
// //
char libpath[8192]; char libpath[8192];
char newlibs[256]; char newlibs[256];
get_project_dir(wup->project, buf, sizeof(buf)); sprintf(newlibs, "../../%s:.:../..", wup->project->project_dir());
sprintf(newlibs, "../../%s:.:../..", buf);
#ifdef __APPLE__ #ifdef __APPLE__
strcat(newlibs, ":/usr/local/cuda/lib/"); strcat(newlibs, ":/usr/local/cuda/lib/");
#endif #endif

View File

@ -479,7 +479,7 @@ int CLIENT_STATE::add_project(
const char* master_url, const char* _auth, const char* project_name, const char* master_url, const char* _auth, const char* project_name,
bool attached_via_acct_mgr bool attached_via_acct_mgr
) { ) {
char path[MAXPATHLEN], canonical_master_url[256], auth[256], dir[256]; char path[MAXPATHLEN], canonical_master_url[256], auth[256];
PROJECT* project; PROJECT* project;
FILE* f; FILE* f;
int retval; int retval;
@ -532,8 +532,7 @@ int CLIENT_STATE::add_project(
// (unless PROJECT/app_info.xml is found, so that // (unless PROJECT/app_info.xml is found, so that
// people using anonymous platform don't have to get apps again) // people using anonymous platform don't have to get apps again)
// //
get_project_dir(project, dir, sizeof(dir)); sprintf(path, "%s/%s", project->project_dir(), APP_INFO_FILE_NAME);
sprintf(path, "%s/%s", dir, APP_INFO_FILE_NAME);
if (boinc_file_exists(path)) { if (boinc_file_exists(path)) {
project->anonymous_platform = true; project->anonymous_platform = true;
f = fopen(path, "r"); f = fopen(path, "r");

View File

@ -79,19 +79,18 @@ double CLIENT_STATE::allowed_disk_usage(double boinc_total) {
// GLOBAL_STATE::total_disk_usage // GLOBAL_STATE::total_disk_usage
// //
int CLIENT_STATE::get_disk_usages() { int CLIENT_STATE::get_disk_usages() {
char buf[256];
unsigned int i; unsigned int i;
double size; double size;
PROJECT* p; PROJECT* p;
int retval; int retval;
char buf[MAXPATHLEN];
client_disk_usage = 0; client_disk_usage = 0;
total_disk_usage = 0; total_disk_usage = 0;
for (i=0; i<projects.size(); i++) { for (i=0; i<projects.size(); i++) {
p = projects[i]; p = projects[i];
p->disk_usage = 0; p->disk_usage = 0;
get_project_dir(p, buf, sizeof(buf)); retval = dir_size(p->project_dir(), size);
retval = dir_size(buf, size);
if (!retval) p->disk_usage = size; if (!retval) p->disk_usage = size;
} }

View File

@ -806,14 +806,13 @@ int CLIENT_STATE::write_state_file_if_needed() {
// //
void CLIENT_STATE::check_anonymous() { void CLIENT_STATE::check_anonymous() {
unsigned int i; unsigned int i;
char dir[256], path[MAXPATHLEN]; char path[MAXPATHLEN];
FILE* f; FILE* f;
int retval; int retval;
for (i=0; i<projects.size(); i++) { for (i=0; i<projects.size(); i++) {
PROJECT* p = projects[i]; PROJECT* p = projects[i];
get_project_dir(p, dir, sizeof(dir)); sprintf(path, "%s/%s", p->project_dir(), APP_INFO_FILE_NAME);
sprintf(path, "%s/%s", dir, APP_INFO_FILE_NAME);
f = fopen(path, "r"); f = fopen(path, "r");
if (!f) continue; if (!f) continue;
msg_printf(p, MSG_INFO, msg_printf(p, MSG_INFO,

View File

@ -46,14 +46,13 @@ using std::string;
// Convert them to XML (for sched request message) // Convert them to XML (for sched request message)
// //
int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) { int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) {
char project_dir[256], *p, *q, result_name[256], fname[256]; char *p, *q, result_name[256], fname[256];
char* file_contents, path[MAXPATHLEN], newpath[MAXPATHLEN]; char* file_contents, path[MAXPATHLEN], newpath[MAXPATHLEN];
string fn; string fn;
time_t t; time_t t;
int retval; int retval;
get_project_dir(project, project_dir, sizeof(project_dir)); DirScanner ds(project->project_dir());
DirScanner ds(project_dir);
// trickle-up filenames are of the form trickle_up_RESULTNAME_TIME[.sent] // trickle-up filenames are of the form trickle_up_RESULTNAME_TIME[.sent]
// //
@ -68,7 +67,7 @@ int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) {
*p = '_'; *p = '_';
t = atoi(p+1); t = atoi(p+1);
sprintf(path, "%s/%s", project_dir, fname); sprintf(path, "%s/%s", project->project_dir(), fname);
retval = read_file_malloc(path, file_contents); retval = read_file_malloc(path, file_contents);
if (retval) continue; if (retval) continue;
fprintf(f, fprintf(f,
@ -87,7 +86,7 @@ int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) {
// append .sent to filename, so we'll know which ones to delete later // append .sent to filename, so we'll know which ones to delete later
// //
if (!ends_with(fname, ".sent")) { if (!ends_with(fname, ".sent")) {
sprintf(newpath, "%s/%s.sent", project_dir, fname); sprintf(newpath, "%s/%s.sent", project->project_dir(), fname);
boinc_rename(path, newpath); boinc_rename(path, newpath);
} }
} }
@ -99,17 +98,16 @@ int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) {
// (others arrived from application while RPC was happening) // (others arrived from application while RPC was happening)
// //
int CLIENT_STATE::remove_trickle_files(PROJECT* project) { int CLIENT_STATE::remove_trickle_files(PROJECT* project) {
char project_dir[256], path[MAXPATHLEN], fname[256]; char path[MAXPATHLEN], fname[256];
string fn; string fn;
get_project_dir(project, project_dir, sizeof(project_dir)); DirScanner ds(project->project_dir());
DirScanner ds(project_dir);
while (ds.scan(fn)) { while (ds.scan(fn)) {
strcpy(fname, fn.c_str()); strcpy(fname, fn.c_str());
if (!starts_with(fname, "trickle_up")) continue; if (!starts_with(fname, "trickle_up")) continue;
if (!ends_with(fname, ".sent")) continue; if (!ends_with(fname, ".sent")) continue;
sprintf(path, "%s/%s", project_dir, fname); sprintf(path, "%s/%s", project->project_dir(), fname);
delete_project_owned_file(path, true); delete_project_owned_file(path, true);
} }
return 0; return 0;

View File

@ -65,12 +65,6 @@ int make_soft_link(PROJECT* project, char* link_path, char* rel_file_path) {
return 0; return 0;
} }
void get_project_dir(PROJECT* p, char* path, int len) {
char buf[1024];
escape_project_url(p->master_url, buf);
snprintf(path, len, "%s/%s", PROJECTS_DIR, buf);
}
// Gets the pathname of a file // Gets the pathname of a file
// //
void get_pathname(FILE_INFO* fip, char* path, int len) { void get_pathname(FILE_INFO* fip, char* path, int len) {
@ -85,10 +79,10 @@ void get_pathname(FILE_INFO* fip, char* path, int len) {
if (fip->is_auto_update_file) { if (fip->is_auto_update_file) {
boinc_version_dir(*p, gstate.auto_update.version, buf); boinc_version_dir(*p, gstate.auto_update.version, buf);
} else { } else {
get_project_dir(p, buf, sizeof(buf)); strcpy(buf, p->project_dir());
} }
#else #else
get_project_dir(p, buf, sizeof(buf)); strcpy(buf, p->project_dir());
#endif #endif
snprintf(path, len, "%s/%s", buf, fip->name); snprintf(path, len, "%s/%s", buf, fip->name);
} else { } else {
@ -133,7 +127,6 @@ void get_slot_dir(int slot, char* path, int len) {
// Create the directory for the project p // Create the directory for the project p
// //
int make_project_dir(PROJECT& p) { int make_project_dir(PROJECT& p) {
char buf[1024];
int retval; int retval;
boinc_mkdir(PROJECTS_DIR); boinc_mkdir(PROJECTS_DIR);
@ -151,36 +144,33 @@ int make_project_dir(PROJECT& p) {
set_to_project_group(PROJECTS_DIR); set_to_project_group(PROJECTS_DIR);
} }
#endif #endif
get_project_dir(&p, buf, sizeof(buf)); retval = boinc_mkdir(p.project_dir());
retval = boinc_mkdir(buf);
#ifndef _WIN32 #ifndef _WIN32
if (g_use_sandbox) { if (g_use_sandbox) {
old_mask = umask(2); old_mask = umask(2);
// Contents of projects directory must be world-readable so BOINC Client can read // Contents of projects directory must be world-readable so BOINC Client can read
// files written by projects which have user boinc_project and group boinc_project // files written by projects which have user boinc_project and group boinc_project
chmod(buf, chmod(p.project_dir(),
S_IRUSR|S_IWUSR|S_IXUSR S_IRUSR|S_IWUSR|S_IXUSR
|S_IRGRP|S_IWGRP|S_IXGRP |S_IRGRP|S_IWGRP|S_IXGRP
|S_IROTH|S_IXOTH |S_IROTH|S_IXOTH
); );
umask(old_mask); umask(old_mask);
set_to_project_group(buf); set_to_project_group(p.project_dir());
} }
#endif #endif
return retval; return retval;
} }
int remove_project_dir(PROJECT& p) { int remove_project_dir(PROJECT& p) {
char buf[1024];
int retval; int retval;
get_project_dir(&p, buf, sizeof(buf)); retval = client_clean_out_dir(p.project_dir(), "remove project dir");
retval = client_clean_out_dir(buf, "remove project dir");
if (retval) { if (retval) {
msg_printf(&p, MSG_INTERNAL_ERROR, "Can't delete file %s", boinc_failed_file); msg_printf(&p, MSG_INTERNAL_ERROR, "Can't delete file %s", boinc_failed_file);
return retval; return retval;
} }
return remove_project_owned_dir(buf); return remove_project_owned_dir(p.project_dir());
} }
// Create the slot directory for the specified slot # // Create the slot directory for the specified slot #
@ -341,9 +331,9 @@ bool is_image_file(const char* filename) {
} }
void boinc_version_dir(PROJECT& p, VERSION_INFO& vi, char* buf) { void boinc_version_dir(PROJECT& p, VERSION_INFO& vi, char* buf) {
char projdir[1024]; sprintf(buf, "%s/boinc_version_%d_%d_%d",
get_project_dir(&p, projdir, sizeof(projdir)); p.project_dir(), vi.major, vi.minor, vi.release
sprintf(buf, "%s/boinc_version_%d_%d_%d", projdir, vi.major, vi.minor, vi.release); );
} }
bool is_version_dir(char* buf, VERSION_INFO& vi) { bool is_version_dir(char* buf, VERSION_INFO& vi) {

View File

@ -27,7 +27,6 @@ extern int make_soft_link(PROJECT* project, char* link_path, char* rel_file_path
// get the pathname (relative to client home dir) of a project file // get the pathname (relative to client home dir) of a project file
// //
extern void get_pathname(FILE_INFO* fip, char* path, int len); extern void get_pathname(FILE_INFO* fip, char* path, int len);
extern void get_project_dir(PROJECT*, char*, int);
// get the pathname (relative to client home dir) of the // get the pathname (relative to client home dir) of the
// directory used for a particular application "slot" // directory used for a particular application "slot"

View File

@ -18,6 +18,7 @@
#include <string.h> #include <string.h>
#include "str_replace.h" #include "str_replace.h"
#include "url.h"
#include "client_msgs.h" #include "client_msgs.h"
#include "client_state.h" #include "client_state.h"
@ -468,9 +469,7 @@ int PROJECT::write_state(MIOFILE& out, bool gui_rpc) {
if (strlen(host_venue)) { if (strlen(host_venue)) {
out.printf(" <venue>%s</venue>\n", host_venue); out.printf(" <venue>%s</venue>\n", host_venue);
} }
char project_dir[MAXPATHLEN]; out.printf(" <project_dir>%s</project_dir>\n", project_dir_absolute());
get_project_dir(this, project_dir, sizeof(project_dir));
out.printf(" <project_dir>%s</project_dir>\n", project_dir);
} else { } else {
for (i=0; i<scheduler_urls.size(); i++) { for (i=0; i<scheduler_urls.size(); i++) {
out.printf( out.printf(
@ -639,12 +638,11 @@ const char* PROJECT::get_scheduler_url(int index, double r) {
// //
void PROJECT::delete_project_file_symlinks() { void PROJECT::delete_project_file_symlinks() {
unsigned int i; unsigned int i;
char project_dir[256], path[MAXPATHLEN]; char path[MAXPATHLEN];
get_project_dir(this, project_dir, sizeof(project_dir));
for (i=0; i<project_files.size(); i++) { for (i=0; i<project_files.size(); i++) {
FILE_REF& fref = project_files[i]; FILE_REF& fref = project_files[i];
sprintf(path, "%s/%s", project_dir, fref.open_name); sprintf(path, "%s/%s", project_dir(), fref.open_name);
delete_project_owned_file(path, false); delete_project_owned_file(path, false);
} }
} }
@ -698,15 +696,14 @@ void PROJECT::write_project_files(MIOFILE& f) {
// has several logical names, so try them all // has several logical names, so try them all
// //
int PROJECT::write_symlink_for_project_file(FILE_INFO* fip) { int PROJECT::write_symlink_for_project_file(FILE_INFO* fip) {
char project_dir[256], link_path[MAXPATHLEN], file_path[MAXPATHLEN]; char link_path[MAXPATHLEN], file_path[MAXPATHLEN];
unsigned int i; unsigned int i;
get_project_dir(this, project_dir, sizeof(project_dir));
for (i=0; i<project_files.size(); i++) { for (i=0; i<project_files.size(); i++) {
FILE_REF& fref = project_files[i]; FILE_REF& fref = project_files[i];
if (fref.file_info != fip) continue; if (fref.file_info != fip) continue;
sprintf(link_path, "%s/%s", project_dir, fref.open_name); sprintf(link_path, "%s/%s", project_dir(), fref.open_name);
sprintf(file_path, "%s/%s", project_dir, fip->name); sprintf(file_path, "%s/%s", project_dir(), fip->name);
make_soft_link(this, link_path, file_path); make_soft_link(this, link_path, file_path);
} }
return 0; return 0;
@ -858,3 +855,19 @@ void PROJECT::trim_statistics() {
} }
} }
} }
const char* PROJECT::project_dir() {
if (_project_dir[0] == 0) {
char buf[1024];
escape_project_url(master_url, buf);
sprintf(_project_dir, "%s/%s", PROJECTS_DIR, buf);
}
return _project_dir;
}
const char* PROJECT::project_dir_absolute() {
if (_project_dir_absolute[0] == 0) {
relative_to_absolute(project_dir(), _project_dir_absolute);
}
return _project_dir_absolute;
}

View File

@ -22,6 +22,9 @@
#include "client_types.h" #include "client_types.h"
struct PROJECT : PROJ_AM { struct PROJECT : PROJ_AM {
char _project_dir[MAXPATHLEN];
char _project_dir_absolute[MAXPATHLEN];
// the following items come from the account file // the following items come from the account file
// They are a function only of the user and the project // They are a function only of the user and the project
// //
@ -300,6 +303,8 @@ struct PROJECT : PROJ_AM {
int parse_account_file(); int parse_account_file();
int parse_state(XML_PARSER&); int parse_state(XML_PARSER&);
int write_state(MIOFILE&, bool gui_rpc=false); int write_state(MIOFILE&, bool gui_rpc=false);
const char* project_dir();
const char* project_dir_absolute();
// statistic of the last x days // statistic of the last x days
std::vector<DAILY_STATS> statistics; std::vector<DAILY_STATS> statistics;