2003-07-01 20:37:09 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-07-01 20:37:09 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-08-11 04:28:23 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2003-08-11 04:28:23 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
2003-07-01 20:37:09 +00:00
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-08-11 04:28:23 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <ctime>
|
|
|
|
#include <cassert>
|
2003-05-20 22:57:28 +00:00
|
|
|
#include <unistd.h>
|
2004-07-21 21:50:25 +00:00
|
|
|
#include <cmath>
|
2004-12-31 15:39:05 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2002-07-05 05:33:40 +00:00
|
|
|
#include "crypt.h"
|
2004-04-13 23:55:05 +00:00
|
|
|
#include "error_numbers.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "md5_file.h"
|
2002-12-12 01:07:24 +00:00
|
|
|
#include "parse.h"
|
2004-04-13 23:55:05 +00:00
|
|
|
#include "util.h"
|
2004-09-20 23:03:47 +00:00
|
|
|
#include "filesys.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "backend_lib.h"
|
|
|
|
|
2004-04-30 23:18:56 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#include "fcgi_stdio.h"
|
|
|
|
#endif
|
|
|
|
|
2004-07-21 21:50:25 +00:00
|
|
|
static struct random_init {
|
|
|
|
random_init() {
|
|
|
|
srand48(getpid() + time(0));
|
|
|
|
}
|
|
|
|
} random_init;
|
|
|
|
|
2004-05-13 18:18:22 +00:00
|
|
|
int read_file(FILE* f, char* buf, int len) {
|
|
|
|
int n = fread(buf, 1, len, f);
|
2002-04-30 22:22:54 +00:00
|
|
|
buf[n] = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-13 18:18:22 +00:00
|
|
|
int read_filename(const char* path, char* buf, int len) {
|
2002-07-05 05:33:40 +00:00
|
|
|
int retval;
|
|
|
|
FILE* f = fopen(path, "r");
|
|
|
|
if (!f) return -1;
|
2004-05-13 18:18:22 +00:00
|
|
|
retval = read_file(f, buf, len);
|
2002-07-05 05:33:40 +00:00
|
|
|
fclose(f);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2004-12-31 15:39:05 +00:00
|
|
|
#ifdef BOINC_CACHE_MD5
|
|
|
|
static bool got_md5_info(
|
|
|
|
const char *path,
|
|
|
|
char *md5data,
|
|
|
|
double *nbytes
|
|
|
|
) {
|
|
|
|
|
|
|
|
// look for file named FILENAME.md5 containing md5sum and length.
|
|
|
|
// If found, and newer mod time than file, read md5 sum and file
|
|
|
|
// length from it.
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
char md5name[512];
|
|
|
|
struct stat md5stat, filestat;
|
|
|
|
bool retval=false;
|
|
|
|
char endline='\0';
|
|
|
|
|
|
|
|
sprintf(md5name, "%s.md5", path);
|
|
|
|
|
|
|
|
// get mod times for file
|
|
|
|
if (stat(path, &filestat))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
// get mod time for md5 cache file
|
|
|
|
if (stat(md5name, &md5stat))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
// if cached md5 newer, then open it
|
|
|
|
if (!(fp=fopen(md5name, "r")))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
// read two quantities: md5 sum and length. If we can't read
|
|
|
|
// these, or there is MORE stuff in the file' it's not an md5
|
|
|
|
// cache file
|
|
|
|
if (3 == fscanf(fp, "%s %lf%c", md5data, nbytes, &endline) &&
|
|
|
|
endline=='\n' &&
|
|
|
|
EOF==fgetc(fp)
|
|
|
|
)
|
|
|
|
retval=true;
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
// if this is one of our cached md5 files, but it's OLDER than the
|
|
|
|
// data file which it supposedly corresponds to, delete it.
|
|
|
|
if (retval && md5stat.st_mtime<filestat.st_mtime) {
|
|
|
|
unlink(md5name);
|
|
|
|
retval=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_md5_info(
|
|
|
|
const char *path,
|
|
|
|
const char *md5,
|
|
|
|
double nbytes
|
|
|
|
) {
|
|
|
|
// Write file FILENAME.md5 containing md5sum and length
|
|
|
|
FILE *fp;
|
|
|
|
char md5name[512];
|
|
|
|
struct stat statbuf;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
// if file already exists with this name, don't touch it.
|
|
|
|
sprintf(md5name, "%s.md5", path);
|
|
|
|
if (!stat(md5name, &statbuf))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if can't open the file, give up
|
|
|
|
if (!(fp=fopen(md5name, "w")))
|
|
|
|
return;
|
|
|
|
|
|
|
|
retval=fprintf(fp,"%s %.15e\n", md5, nbytes);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
// if we didn't write properly to the file, delete it.
|
|
|
|
if (retval<0)
|
|
|
|
unlink(md5name);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif // BOINC_CACHE_MD5
|
|
|
|
|
2002-12-12 01:07:24 +00:00
|
|
|
|
|
|
|
// process WU template
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
|
|
|
static int process_wu_template(
|
2004-07-13 13:54:09 +00:00
|
|
|
WORKUNIT& wu,
|
2004-07-02 17:53:31 +00:00
|
|
|
char* tmplate,
|
2004-07-13 13:54:09 +00:00
|
|
|
const char** infiles,
|
2004-12-06 22:41:19 +00:00
|
|
|
int ninfiles,
|
2004-08-06 11:42:41 +00:00
|
|
|
SCHED_CONFIG& config
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
|
|
|
char* p;
|
2004-09-20 23:03:47 +00:00
|
|
|
char buf[LARGE_BLOB_SIZE], md5[33], path[256], url[256], top_download_path[256];
|
2004-12-26 02:55:31 +00:00
|
|
|
//char out[LARGE_BLOB_SIZE];
|
|
|
|
std::string out;
|
2002-12-12 01:07:24 +00:00
|
|
|
int retval, file_number;
|
2002-04-30 22:22:54 +00:00
|
|
|
double nbytes;
|
2002-12-12 01:07:24 +00:00
|
|
|
char open_name[256];
|
2003-01-15 23:54:24 +00:00
|
|
|
bool found=false;
|
2002-12-05 19:13:06 +00:00
|
|
|
|
2004-12-26 02:55:31 +00:00
|
|
|
out = "";
|
2004-04-14 18:46:33 +00:00
|
|
|
for (p=strtok(tmplate, "\n"); p; p=strtok(0, "\n")) {
|
2002-12-12 01:07:24 +00:00
|
|
|
if (match_tag(p, "<file_info>")) {
|
2004-04-13 23:55:05 +00:00
|
|
|
file_number = -1;
|
2004-12-26 02:55:31 +00:00
|
|
|
out += "<file_info>\n";
|
2004-04-13 23:55:05 +00:00
|
|
|
while (1) {
|
|
|
|
p = strtok(0, "\n");
|
|
|
|
if (!p) break;
|
|
|
|
if (parse_int(p, "<number>", file_number)) {
|
|
|
|
continue;
|
|
|
|
} else if (match_tag(p, "</file_info>")) {
|
|
|
|
if (file_number < 0) {
|
|
|
|
fprintf(stderr, "No file number found\n");
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2004-12-06 22:41:19 +00:00
|
|
|
if (file_number >= ninfiles) {
|
|
|
|
fprintf(stderr, "Too few input files given; need at least %d\n", file_number+1);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2004-08-06 11:42:41 +00:00
|
|
|
dir_hier_path(
|
|
|
|
infiles[file_number], config.download_dir,
|
2005-01-02 07:44:40 +00:00
|
|
|
config.uldl_dir_fanout, true,
|
|
|
|
path, true
|
2004-08-06 11:42:41 +00:00
|
|
|
);
|
2004-11-22 19:17:13 +00:00
|
|
|
if (!boinc_file_exists(path)) {
|
|
|
|
sprintf(top_download_path,
|
|
|
|
"%s/%s",config.download_dir,
|
|
|
|
infiles[file_number]
|
|
|
|
);
|
|
|
|
boinc_copy(top_download_path,path);
|
|
|
|
}
|
2004-12-30 04:16:00 +00:00
|
|
|
#ifdef BOINC_CACHE_MD5
|
2004-12-31 15:39:05 +00:00
|
|
|
// see checkin notes Dec 30 2004
|
|
|
|
if (!got_md5_info(path, md5, &nbytes)) {
|
2004-12-30 04:16:00 +00:00
|
|
|
#endif
|
|
|
|
retval = md5_file(path, md5, nbytes);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "process_wu_template: md5_file %d\n", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
#ifdef BOINC_CACHE_MD5
|
2004-12-31 15:39:05 +00:00
|
|
|
else
|
|
|
|
write_md5_info(path, md5, nbytes);
|
|
|
|
}
|
2004-12-30 04:16:00 +00:00
|
|
|
#endif
|
|
|
|
|
2004-08-06 11:42:41 +00:00
|
|
|
dir_hier_url(
|
|
|
|
infiles[file_number], config.download_url,
|
2005-01-02 07:44:40 +00:00
|
|
|
config.uldl_dir_fanout, true,
|
|
|
|
url
|
2004-08-06 11:42:41 +00:00
|
|
|
);
|
2004-04-13 23:55:05 +00:00
|
|
|
sprintf(buf,
|
|
|
|
" <name>%s</name>\n"
|
2004-08-06 11:42:41 +00:00
|
|
|
" <url>%s</url>\n"
|
2004-04-13 23:55:05 +00:00
|
|
|
" <md5_cksum>%s</md5_cksum>\n"
|
|
|
|
" <nbytes>%.0f</nbytes>\n"
|
|
|
|
"</file_info>\n",
|
|
|
|
infiles[file_number],
|
2004-08-06 11:42:41 +00:00
|
|
|
url,
|
2004-04-13 23:55:05 +00:00
|
|
|
md5,
|
|
|
|
nbytes
|
|
|
|
);
|
2004-12-26 02:55:31 +00:00
|
|
|
out += buf;
|
2004-04-13 23:55:05 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2004-12-26 02:55:31 +00:00
|
|
|
out += p;
|
|
|
|
out += "\n";
|
2004-04-13 23:55:05 +00:00
|
|
|
}
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
2002-12-12 01:07:24 +00:00
|
|
|
} else if (match_tag(p, "<workunit>")) {
|
2003-01-15 23:54:24 +00:00
|
|
|
found = true;
|
2004-12-26 02:55:31 +00:00
|
|
|
out += "<workunit>\n";
|
2002-12-12 01:07:24 +00:00
|
|
|
} else if (match_tag(p, "</workunit>")) {
|
2004-12-26 02:55:31 +00:00
|
|
|
out += "</workunit>\n";
|
2002-12-12 01:07:24 +00:00
|
|
|
} else if (match_tag(p, "<file_ref>")) {
|
2004-04-13 23:55:05 +00:00
|
|
|
file_number = -1;
|
|
|
|
while (1) {
|
|
|
|
p = strtok(0, "\n");
|
|
|
|
if (!p) break;
|
|
|
|
if (parse_int(p, "<file_number>", file_number)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_str(p, "<open_name>", open_name, sizeof(open_name))) {
|
|
|
|
continue;
|
|
|
|
} else if (match_tag(p, "</file_ref>")) {
|
2004-07-23 20:48:49 +00:00
|
|
|
if (file_number < 0) {
|
|
|
|
fprintf(stderr, "No file number found\n");
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2004-04-13 23:55:05 +00:00
|
|
|
sprintf(buf,
|
|
|
|
"<file_ref>\n"
|
|
|
|
" <file_name>%s</file_name>\n"
|
|
|
|
" <open_name>%s</open_name>\n"
|
|
|
|
"</file_ref>\n",
|
|
|
|
infiles[file_number],
|
|
|
|
open_name
|
|
|
|
);
|
2004-12-26 02:55:31 +00:00
|
|
|
out += buf;
|
2004-04-13 23:55:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (parse_double(p, "<rsc_fpops_est>", wu.rsc_fpops_est)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_double(p, "<rsc_fpops_bound>", wu.rsc_fpops_bound)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_double(p, "<rsc_memory_bound>", wu.rsc_memory_bound)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_double(p, "<rsc_disk_bound>", wu.rsc_disk_bound)) {
|
|
|
|
continue;
|
2004-11-22 19:17:13 +00:00
|
|
|
} else if (parse_int(p, "<batch>", wu.batch)) {
|
|
|
|
continue;
|
2004-04-13 23:55:05 +00:00
|
|
|
} else if (parse_int(p, "<delay_bound>", wu.delay_bound)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_int(p, "<min_quorum>", wu.min_quorum)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_int(p, "<target_nresults>", wu.target_nresults)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_int(p, "<max_error_results>", wu.max_error_results)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_int(p, "<max_total_results>", wu.max_total_results)) {
|
|
|
|
continue;
|
|
|
|
} else if (parse_int(p, "<max_success_results>", wu.max_success_results)) {
|
|
|
|
continue;
|
2002-12-12 01:07:24 +00:00
|
|
|
} else {
|
2004-12-26 02:55:31 +00:00
|
|
|
out += p;
|
|
|
|
out += "\n";
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-15 23:54:24 +00:00
|
|
|
if (!found) {
|
|
|
|
fprintf(stderr, "create_work: bad WU template - no <workunit>\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2004-12-26 02:55:31 +00:00
|
|
|
if (out.size() > sizeof(wu.xml_doc)-1) {
|
2004-05-13 18:18:22 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"create_work: WU XML field is too long (%d bytes; max is %d)\n",
|
2004-12-26 02:55:31 +00:00
|
|
|
out.size(), sizeof(wu.xml_doc)-1
|
2004-05-13 18:18:22 +00:00
|
|
|
);
|
|
|
|
return ERR_BUFFER_OVERFLOW;
|
|
|
|
}
|
2004-12-26 02:55:31 +00:00
|
|
|
strcpy(wu.xml_doc, out.c_str());
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-07 19:31:34 +00:00
|
|
|
// Set the time-varying fields of a result to their initial state.
|
|
|
|
// This is used to create clones of existing results,
|
|
|
|
// so set only the time-varying fields
|
|
|
|
//
|
2004-12-06 22:41:19 +00:00
|
|
|
void initialize_result(DB_RESULT& result, TRANSITIONER_ITEM& wu) {
|
2002-11-07 19:31:34 +00:00
|
|
|
result.id = 0;
|
|
|
|
result.create_time = time(0);
|
2004-12-06 22:41:19 +00:00
|
|
|
result.workunitid = wu.id;
|
2002-12-07 00:56:51 +00:00
|
|
|
result.server_state = RESULT_SERVER_STATE_UNSENT;
|
2002-11-07 19:31:34 +00:00
|
|
|
result.hostid = 0;
|
2003-01-23 08:07:48 +00:00
|
|
|
result.report_deadline = 0;
|
2002-11-07 19:31:34 +00:00
|
|
|
result.sent_time = 0;
|
|
|
|
result.received_time = 0;
|
2002-12-09 23:06:17 +00:00
|
|
|
result.client_state = 0;
|
2002-11-07 19:31:34 +00:00
|
|
|
result.cpu_time = 0;
|
|
|
|
strcpy(result.xml_doc_out, "");
|
|
|
|
strcpy(result.stderr_out, "");
|
2003-01-23 08:07:48 +00:00
|
|
|
result.outcome = RESULT_OUTCOME_INIT;
|
2002-12-17 19:00:43 +00:00
|
|
|
result.file_delete_state = ASSIMILATE_INIT;
|
2003-01-23 08:07:48 +00:00
|
|
|
result.validate_state = VALIDATE_STATE_INIT;
|
2002-11-07 19:31:34 +00:00
|
|
|
result.claimed_credit = 0;
|
|
|
|
result.granted_credit = 0;
|
2004-12-06 22:41:19 +00:00
|
|
|
result.appid = wu.appid;
|
|
|
|
result.priority = wu.priority;
|
2002-11-07 19:31:34 +00:00
|
|
|
}
|
|
|
|
|
2002-10-16 01:21:00 +00:00
|
|
|
// Create a new result for the given WU.
|
2004-04-13 23:55:05 +00:00
|
|
|
// This is called ONLY from the transitioner
|
2002-10-16 01:21:00 +00:00
|
|
|
//
|
2002-07-05 05:33:40 +00:00
|
|
|
int create_result(
|
2004-12-06 22:41:19 +00:00
|
|
|
TRANSITIONER_ITEM& wu,
|
2004-07-02 17:53:31 +00:00
|
|
|
char* result_template_filename,
|
2004-07-13 13:54:09 +00:00
|
|
|
char* result_name_suffix,
|
2004-07-02 17:53:31 +00:00
|
|
|
R_RSA_PRIVATE_KEY& key,
|
2004-09-24 21:28:12 +00:00
|
|
|
SCHED_CONFIG& config,
|
2004-07-21 21:50:25 +00:00
|
|
|
char* query_string
|
|
|
|
// if nonzero, write value list here; else do insert
|
2002-07-05 05:33:40 +00:00
|
|
|
) {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_RESULT result;
|
2002-04-30 22:22:54 +00:00
|
|
|
char base_outfile_name[256];
|
2004-07-02 17:53:31 +00:00
|
|
|
char result_template[LARGE_BLOB_SIZE];
|
2002-04-30 22:22:54 +00:00
|
|
|
int retval;
|
2002-09-26 05:57:10 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
result.clear();
|
2004-12-06 22:41:19 +00:00
|
|
|
initialize_result(result, wu);
|
|
|
|
sprintf(result.name, "%s_%s", wu.name, result_name_suffix);
|
2003-06-04 17:21:26 +00:00
|
|
|
sprintf(base_outfile_name, "%s_", result.name);
|
2002-07-05 05:33:40 +00:00
|
|
|
|
2004-07-02 17:53:31 +00:00
|
|
|
retval = read_filename(result_template_filename, result_template, sizeof(result_template));
|
|
|
|
if (retval) {
|
2004-07-21 21:50:25 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Failed to read result template file '%s': %d\n",
|
|
|
|
result_template_filename, retval
|
|
|
|
);
|
2004-07-02 17:53:31 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
retval = process_result_template(
|
2004-07-02 17:53:31 +00:00
|
|
|
result_template,
|
2002-07-05 05:33:40 +00:00
|
|
|
key,
|
2002-10-09 04:56:41 +00:00
|
|
|
base_outfile_name,
|
2004-09-24 21:28:12 +00:00
|
|
|
config
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2004-07-02 17:53:31 +00:00
|
|
|
if (strlen(result_template) > sizeof(result.xml_doc_in)-1) {
|
2004-05-13 18:18:22 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"result XML doc is too long: %d bytes, max is %d\n",
|
2004-07-02 17:53:31 +00:00
|
|
|
strlen(result_template), sizeof(result.xml_doc_in)-1
|
2004-05-13 18:18:22 +00:00
|
|
|
);
|
|
|
|
return ERR_BUFFER_OVERFLOW;
|
|
|
|
}
|
2004-07-02 17:53:31 +00:00
|
|
|
safe_strncpy(result.xml_doc_in, result_template, sizeof(result.xml_doc_in));
|
2003-08-11 04:28:23 +00:00
|
|
|
|
2004-07-21 21:50:25 +00:00
|
|
|
result.random = lrand48();
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-07-21 21:50:25 +00:00
|
|
|
if (query_string) {
|
|
|
|
result.db_print_values(query_string);
|
|
|
|
} else {
|
|
|
|
retval = result.insert();
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "result.insert(): %d\n", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
2002-07-05 05:33:40 +00:00
|
|
|
}
|
2004-05-13 18:18:22 +00:00
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2003-09-30 18:09:58 +00:00
|
|
|
// make sure a WU's input files are actually there
|
|
|
|
//
|
2004-08-06 11:42:41 +00:00
|
|
|
int check_files(char** infiles, int ninfiles, SCHED_CONFIG& config) {
|
2003-09-30 18:09:58 +00:00
|
|
|
int i;
|
|
|
|
char path[256];
|
|
|
|
|
|
|
|
for (i=0; i<ninfiles; i++) {
|
2004-08-06 11:42:41 +00:00
|
|
|
dir_hier_path(
|
2005-01-02 07:44:40 +00:00
|
|
|
infiles[i], config.download_dir, config.uldl_dir_fanout, true, path
|
2004-08-06 11:42:41 +00:00
|
|
|
);
|
2005-01-02 07:44:40 +00:00
|
|
|
if (!boinc_file_exists(path)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-09-30 18:09:58 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
int create_work(
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_WORKUNIT& wu,
|
2003-09-16 21:50:03 +00:00
|
|
|
const char* _wu_template,
|
|
|
|
const char* result_template_filename,
|
2004-07-10 00:12:06 +00:00
|
|
|
const char* result_template_filepath,
|
2003-09-16 21:50:03 +00:00
|
|
|
const char** infiles,
|
2002-07-05 05:33:40 +00:00
|
|
|
int ninfiles,
|
2002-10-03 18:33:46 +00:00
|
|
|
R_RSA_PRIVATE_KEY& key,
|
2004-08-06 11:42:41 +00:00
|
|
|
SCHED_CONFIG& config
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
2003-08-15 23:44:28 +00:00
|
|
|
int retval;
|
2004-05-13 18:18:22 +00:00
|
|
|
char _result_template[LARGE_BLOB_SIZE];
|
|
|
|
char wu_template[LARGE_BLOB_SIZE];
|
2002-09-26 05:57:10 +00:00
|
|
|
|
2003-09-30 18:09:58 +00:00
|
|
|
#if 0
|
2004-08-06 11:42:41 +00:00
|
|
|
retval = check_files(infiles, ninfiles, config);
|
2003-09-30 18:09:58 +00:00
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "Missing input file: %s\n", infiles[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-01-15 23:54:24 +00:00
|
|
|
strcpy(wu_template, _wu_template);
|
2002-04-30 22:22:54 +00:00
|
|
|
wu.create_time = time(0);
|
|
|
|
retval = process_wu_template(
|
2004-08-06 11:42:41 +00:00
|
|
|
wu, wu_template, infiles, ninfiles, config
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2002-10-03 18:33:46 +00:00
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "process_wu_template: %d\n", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
2003-08-15 23:44:28 +00:00
|
|
|
|
2004-05-13 18:18:22 +00:00
|
|
|
retval = read_filename(
|
2004-07-10 00:12:06 +00:00
|
|
|
result_template_filepath, _result_template, sizeof(_result_template)
|
2004-05-13 18:18:22 +00:00
|
|
|
);
|
2002-10-03 18:33:46 +00:00
|
|
|
if (retval) {
|
2004-07-10 00:12:06 +00:00
|
|
|
fprintf(stderr, "create_work: can't read result template file %s\n", result_template_filepath);
|
2002-10-03 18:33:46 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-07-02 19:17:53 +00:00
|
|
|
if (strlen(result_template_filename) > sizeof(wu.result_template_file)-1) {
|
|
|
|
fprintf(stderr, "result template filename is too big: %d bytes, max is %d\n",
|
|
|
|
strlen(result_template_filename), sizeof(wu.result_template_file)-1
|
2004-05-13 18:18:22 +00:00
|
|
|
);
|
|
|
|
return ERR_BUFFER_OVERFLOW;
|
|
|
|
}
|
2004-07-02 19:17:53 +00:00
|
|
|
safe_strncpy(wu.result_template_file, result_template_filename, sizeof(wu.result_template_file));
|
2003-08-15 23:44:28 +00:00
|
|
|
|
2003-08-18 23:19:01 +00:00
|
|
|
wu.transition_time = time(0);
|
2003-08-15 23:44:28 +00:00
|
|
|
retval = wu.insert();
|
2002-11-06 09:03:55 +00:00
|
|
|
if (retval) {
|
2003-08-15 23:44:28 +00:00
|
|
|
fprintf(stderr, "create_work: workunit.insert() %d\n", retval);
|
2002-11-06 09:03:55 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2003-09-05 21:26:21 +00:00
|
|
|
wu.id = boinc_db.insert_id();
|
2003-08-15 23:44:28 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_b5f8b10eb5 = "$Id$";
|