2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-05-12 21:39:23 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2005-01-20 23:22:22 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2004-05-12 21:39:23 +00:00
|
|
|
|
2004-05-12 21:46:35 +00:00
|
|
|
#include "cpp.h"
|
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2005-11-21 18:34:44 +00:00
|
|
|
#else
|
|
|
|
#include "config.h"
|
2004-05-12 21:46:35 +00:00
|
|
|
#endif
|
|
|
|
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstring>
|
2004-05-12 21:39:23 +00:00
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "filesys.h"
|
|
|
|
#include "parse.h"
|
2007-06-22 20:17:08 +00:00
|
|
|
#include "util.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2007-10-09 00:34:38 +00:00
|
|
|
#include "sandbox.h"
|
2004-05-12 21:39:23 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2004-05-12 21:39:23 +00:00
|
|
|
// Scan project dir for file names of the form trickle_up_X_Y
|
|
|
|
// where X is a result name and Y is a timestamp.
|
|
|
|
// Convert them to XML (for sched request message)
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) {
|
|
|
|
char project_dir[256], *p, *q, result_name[256], fname[256];
|
2005-03-09 00:16:38 +00:00
|
|
|
char* file_contents, path[256], newpath[256];
|
2004-05-12 21:39:23 +00:00
|
|
|
string fn;
|
|
|
|
time_t t;
|
|
|
|
int retval;
|
|
|
|
|
2007-03-13 19:33:27 +00:00
|
|
|
get_project_dir(project, project_dir, sizeof(project_dir));
|
2004-05-12 21:39:23 +00:00
|
|
|
DirScanner ds(project_dir);
|
|
|
|
|
2005-03-09 00:16:38 +00:00
|
|
|
// trickle-up filenames are of the form trickle_up_RESULTNAME_TIME[.sent]
|
|
|
|
//
|
2004-05-12 21:39:23 +00:00
|
|
|
while (ds.scan(fn)) {
|
|
|
|
strcpy(fname, fn.c_str());
|
2004-05-12 22:15:14 +00:00
|
|
|
if (strstr(fname, "trickle_up_") != fname) continue;
|
|
|
|
q = fname + strlen("trickle_up_");
|
2004-05-12 21:39:23 +00:00
|
|
|
p = strrchr(fname, '_');
|
|
|
|
if (p <= q) continue;
|
|
|
|
*p = 0;
|
|
|
|
strcpy(result_name, q);
|
2004-05-12 22:15:14 +00:00
|
|
|
*p = '_';
|
2004-05-12 21:39:23 +00:00
|
|
|
t = atoi(p+1);
|
|
|
|
|
2006-03-03 21:34:03 +00:00
|
|
|
sprintf(path, "%s/%s", project_dir, fname);
|
2004-05-12 21:39:23 +00:00
|
|
|
retval = read_file_malloc(path, file_contents);
|
|
|
|
if (retval) continue;
|
|
|
|
fprintf(f,
|
2004-07-06 04:01:15 +00:00
|
|
|
" <msg_from_host>\n"
|
2004-05-13 04:43:42 +00:00
|
|
|
" <result_name>%s</result_name>\n"
|
2004-05-12 21:39:23 +00:00
|
|
|
" <time>%d</time>\n"
|
|
|
|
"%s\n"
|
2004-07-06 04:01:15 +00:00
|
|
|
" </msg_from_host>\n",
|
2004-05-12 21:39:23 +00:00
|
|
|
result_name,
|
|
|
|
(int)t,
|
|
|
|
file_contents
|
|
|
|
);
|
|
|
|
free(file_contents);
|
2005-03-09 00:16:38 +00:00
|
|
|
|
|
|
|
// append .sent to filename, so we'll know which ones to delete later
|
|
|
|
//
|
|
|
|
if (!ends_with(fname, ".sent")) {
|
2006-03-03 21:34:03 +00:00
|
|
|
sprintf(newpath, "%s/%s.sent", project_dir, fname);
|
2005-03-09 00:16:38 +00:00
|
|
|
boinc_rename(path, newpath);
|
|
|
|
}
|
2004-05-12 21:39:23 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-04 16:00:28 +00:00
|
|
|
// Remove files when ack has been received.
|
|
|
|
// Remove only those ending with ".sent"
|
2005-03-09 00:16:38 +00:00
|
|
|
// (others arrived from application while RPC was happening)
|
2004-05-12 21:39:23 +00:00
|
|
|
//
|
|
|
|
int CLIENT_STATE::remove_trickle_files(PROJECT* project) {
|
|
|
|
char project_dir[256], path[256], fname[256];
|
|
|
|
string fn;
|
|
|
|
|
2007-03-13 19:33:27 +00:00
|
|
|
get_project_dir(project, project_dir, sizeof(project_dir));
|
2004-05-12 21:39:23 +00:00
|
|
|
DirScanner ds(project_dir);
|
|
|
|
|
|
|
|
while (ds.scan(fn)) {
|
|
|
|
strcpy(fname, fn.c_str());
|
2005-03-09 00:16:38 +00:00
|
|
|
if (!starts_with(fname, "trickle_up")) continue;
|
|
|
|
if (!ends_with(fname, ".sent")) continue;
|
2006-03-03 21:34:03 +00:00
|
|
|
sprintf(path, "%s/%s", project_dir, fname);
|
2008-01-15 19:12:43 +00:00
|
|
|
delete_project_owned_file(path, true);
|
2004-05-12 21:39:23 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse a trickle-down message in a scheduler reply.
|
|
|
|
// Locate the corresponding active task,
|
|
|
|
// write a file in the slot directory,
|
|
|
|
// and notify the task
|
|
|
|
//
|
|
|
|
int CLIENT_STATE::handle_trickle_down(PROJECT* project, FILE* in) {
|
|
|
|
char buf[256];
|
|
|
|
char result_name[256], path[256];
|
|
|
|
string body;
|
2006-07-28 20:32:27 +00:00
|
|
|
int send_time=0;
|
2004-05-12 21:39:23 +00:00
|
|
|
|
2004-05-15 22:09:26 +00:00
|
|
|
strcpy(result_name, "");
|
2004-05-12 21:39:23 +00:00
|
|
|
while (fgets(buf, 256, in)) {
|
|
|
|
if (match_tag(buf, "</trickle_down>")) {
|
|
|
|
RESULT* rp = lookup_result(project, result_name);
|
|
|
|
if (!rp) return ERR_NULL;
|
|
|
|
ACTIVE_TASK* atp = lookup_active_task_by_result(rp);
|
|
|
|
if (!atp) return ERR_NULL;
|
2006-03-03 21:34:03 +00:00
|
|
|
sprintf(path, "%s/trickle_down_%d", atp->slot_dir, send_time);
|
2004-05-12 21:39:23 +00:00
|
|
|
FILE* f = fopen(path, "w");
|
|
|
|
if (!f) return ERR_FOPEN;
|
|
|
|
fputs(body.c_str(), f);
|
|
|
|
fclose(f);
|
2004-07-02 04:49:17 +00:00
|
|
|
atp->have_trickle_down = true;
|
2004-05-12 21:39:23 +00:00
|
|
|
return 0;
|
|
|
|
} else if (parse_str(buf, "<result_name>", result_name, 256)) {
|
|
|
|
continue;
|
2004-07-06 04:01:15 +00:00
|
|
|
} else if (parse_int(buf, "<time>", send_time)) {
|
2004-05-12 21:39:23 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2004-07-06 04:01:15 +00:00
|
|
|
body += buf;
|
2004-05-12 21:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_acbefbad3d = "$Id$";
|