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
|
2003-08-11 04:28: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.
|
2003-08-11 04:28:23 +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.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
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/>.
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2009-01-13 23:06:02 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#include "boinc_fcgi.h"
|
|
|
|
#else
|
|
|
|
#include <cstdio>
|
|
|
|
#endif
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <string>
|
2011-05-13 18:40:10 +00:00
|
|
|
#include <vector>
|
2004-07-13 13:54:09 +00:00
|
|
|
#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
|
|
|
|
2009-01-13 23:06:02 +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"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2009-06-16 20:54:44 +00:00
|
|
|
#include "str_replace.h"
|
2008-02-26 17:24:29 +00:00
|
|
|
#include "common_defs.h"
|
2004-09-20 23:03:47 +00:00
|
|
|
#include "filesys.h"
|
2005-01-08 07:44:22 +00:00
|
|
|
#include "sched_util.h"
|
2008-09-22 20:33:59 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "backend_lib.h"
|
|
|
|
|
2004-04-30 23:18:56 +00:00
|
|
|
|
2006-04-28 16:59:53 +00:00
|
|
|
using std::string;
|
|
|
|
|
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;
|
2008-09-09 19:10:42 +00:00
|
|
|
#ifndef _USING_FCGI_
|
2002-07-05 05:33:40 +00:00
|
|
|
FILE* f = fopen(path, "r");
|
2008-09-09 19:10:42 +00:00
|
|
|
#else
|
|
|
|
FCGI_FILE *f=FCGI::fopen(path, "r");
|
|
|
|
#endif
|
2002-07-05 05:33:40 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-02-02 21:57:11 +00:00
|
|
|
// see checkin notes Dec 30 2004
|
|
|
|
//
|
2004-12-31 15:39:05 +00:00
|
|
|
static bool got_md5_info(
|
|
|
|
const char *path,
|
|
|
|
char *md5data,
|
|
|
|
double *nbytes
|
|
|
|
) {
|
2005-02-09 23:49:46 +00:00
|
|
|
bool retval=false;
|
2004-12-31 15:39:05 +00:00
|
|
|
// 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.
|
2008-09-09 19:10:42 +00:00
|
|
|
|
2004-12-31 15:39:05 +00:00
|
|
|
char md5name[512];
|
|
|
|
struct stat md5stat, filestat;
|
|
|
|
char endline='\0';
|
2005-02-02 21:57:11 +00:00
|
|
|
|
2004-12-31 15:39:05 +00:00
|
|
|
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
|
2008-09-09 19:10:42 +00:00
|
|
|
#ifndef _USING_FCGI_
|
|
|
|
FILE *fp=fopen(md5name, "r");
|
|
|
|
#else
|
|
|
|
FCGI_FILE *fp=FCGI::fopen(md5name, "r");
|
|
|
|
#endif
|
|
|
|
if (!fp)
|
2004-12-31 15:39:05 +00:00
|
|
|
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
|
2008-09-09 19:10:42 +00:00
|
|
|
if (3 == fscanf(fp, "%s %lf%c", md5data, nbytes, &endline) &&
|
2004-12-31 15:39:05 +00:00
|
|
|
endline=='\n' &&
|
2008-09-09 19:10:42 +00:00
|
|
|
EOF==fgetc(fp)
|
2004-12-31 15:39:05 +00:00
|
|
|
)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-02-02 21:57:11 +00:00
|
|
|
// see checkin notes Dec 30 2004
|
|
|
|
//
|
2004-12-31 15:39:05 +00:00
|
|
|
static void write_md5_info(
|
|
|
|
const char *path,
|
|
|
|
const char *md5,
|
|
|
|
double nbytes
|
|
|
|
) {
|
|
|
|
// Write file FILENAME.md5 containing md5sum and length
|
2005-10-29 20:16:07 +00:00
|
|
|
//
|
2004-12-31 15:39:05 +00:00
|
|
|
char md5name[512];
|
|
|
|
struct stat statbuf;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
// if file already exists with this name, don't touch it.
|
2005-10-29 20:16:07 +00:00
|
|
|
//
|
2004-12-31 15:39:05 +00:00
|
|
|
sprintf(md5name, "%s.md5", path);
|
2005-10-29 20:16:07 +00:00
|
|
|
if (!stat(md5name, &statbuf)) {
|
2004-12-31 15:39:05 +00:00
|
|
|
return;
|
2005-10-29 20:16:07 +00:00
|
|
|
}
|
2008-09-09 19:10:42 +00:00
|
|
|
|
|
|
|
#ifndef _USING_FCGI_
|
|
|
|
FILE *fp=fopen(md5name, "w");
|
|
|
|
#else
|
|
|
|
FCGI_FILE *fp=FCGI::fopen(md5name, "w");
|
|
|
|
#endif
|
2005-10-29 20:16:07 +00:00
|
|
|
|
2004-12-31 15:39:05 +00:00
|
|
|
// if can't open the file, give up
|
2005-10-29 20:16:07 +00:00
|
|
|
//
|
|
|
|
if (!fp) {
|
2004-12-31 15:39:05 +00:00
|
|
|
return;
|
2005-10-29 20:16:07 +00:00
|
|
|
}
|
2004-12-31 15:39:05 +00:00
|
|
|
|
2005-10-29 20:16:07 +00:00
|
|
|
retval = fprintf(fp,"%s %.15e\n", md5, nbytes);
|
2004-12-31 15:39:05 +00:00
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
// if we didn't write properly to the file, delete it.
|
2005-10-29 20:16:07 +00:00
|
|
|
//
|
|
|
|
if (retval<0) {
|
2004-12-31 15:39:05 +00:00
|
|
|
unlink(md5name);
|
2005-10-29 20:16:07 +00:00
|
|
|
}
|
2004-12-31 15:39:05 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-21 00:47:50 +00:00
|
|
|
// fill in the workunit's XML document (wu.xml_doc)
|
|
|
|
// by scanning the WU template, macro-substituting the input files,
|
|
|
|
// and putting in the command line element and additional XML
|
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,
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
SCHED_CONFIG& config_loc,
|
2007-01-30 18:19:30 +00:00
|
|
|
const char* command_line,
|
|
|
|
const char* additional_xml
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
2008-03-31 16:19:45 +00:00
|
|
|
char buf[BLOB_SIZE], md5[33], path[256], url[256], top_download_path[256];
|
2011-07-04 23:51:00 +00:00
|
|
|
string out, cmdline, md5str, urlstr, tmpstr;
|
2011-08-07 04:32:02 +00:00
|
|
|
int retval, file_number, itemp;
|
|
|
|
double nbytes, nbytesdef, dtemp;
|
2002-12-12 01:07:24 +00:00
|
|
|
char open_name[256];
|
2003-01-15 23:54:24 +00:00
|
|
|
bool found=false;
|
2008-02-21 00:47:50 +00:00
|
|
|
int nfiles_parsed = 0;
|
2002-12-05 19:13:06 +00:00
|
|
|
|
2004-12-26 02:55:31 +00:00
|
|
|
out = "";
|
2011-06-07 04:12:49 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
char tag[256];
|
|
|
|
bool is_tag;
|
|
|
|
mf.init_buf_read(tmplate);
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
|
|
|
if (!strcmp(tag, "input_template")) continue;
|
|
|
|
if (!strcmp(tag, "/input_template")) continue;
|
|
|
|
if (!strcmp(tag, "file_info")) {
|
2011-05-13 18:40:10 +00:00
|
|
|
vector<string> urls;
|
2006-04-28 18:31:32 +00:00
|
|
|
bool generated_locally = false;
|
2010-09-07 20:18:58 +00:00
|
|
|
file_number = nbytesdef = -1;
|
|
|
|
md5str = urlstr = "";
|
2004-12-26 02:55:31 +00:00
|
|
|
out += "<file_info>\n";
|
2011-06-07 04:12:49 +00:00
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (xp.parse_int(tag, "number", file_number)) {
|
2004-04-13 23:55:05 +00:00
|
|
|
continue;
|
2011-06-07 04:12:49 +00:00
|
|
|
} else if (xp.parse_bool(tag, "generated_locally", generated_locally)) {
|
2006-04-28 18:31:32 +00:00
|
|
|
continue;
|
2011-06-07 04:12:49 +00:00
|
|
|
} else if (xp.parse_string(tag, "url", urlstr)) {
|
2011-05-13 18:40:10 +00:00
|
|
|
urls.push_back(urlstr);
|
2010-09-07 20:18:58 +00:00
|
|
|
continue;
|
2011-06-07 04:12:49 +00:00
|
|
|
} else if (xp.parse_string(tag, "md5_cksum", md5str)) {
|
2010-09-07 20:18:58 +00:00
|
|
|
continue;
|
2011-06-07 04:12:49 +00:00
|
|
|
} else if (xp.parse_double(tag, "nbytes", nbytesdef)) {
|
2010-09-07 20:18:58 +00:00
|
|
|
continue;
|
2011-06-07 04:12:49 +00:00
|
|
|
} else if (!strcmp(tag, "/file_info")) {
|
2010-09-07 20:18:58 +00:00
|
|
|
if (nbytesdef != -1 || md5str != "" || urlstr != "") {
|
|
|
|
if (nbytesdef == -1 || md5str == "" || urlstr == "") {
|
|
|
|
fprintf(stderr, "All file properties must be defined "
|
2011-02-03 23:27:30 +00:00
|
|
|
"if at least one is defined (url, md5_cksum, nbytes)!\n"
|
|
|
|
);
|
2010-09-07 20:18:58 +00:00
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
}
|
2004-04-13 23:55:05 +00:00
|
|
|
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) {
|
2006-04-28 18:31:32 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Too few input files given; need at least %d\n",
|
|
|
|
file_number+1
|
|
|
|
);
|
2004-12-06 22:41:19 +00:00
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2008-02-21 00:47:50 +00:00
|
|
|
nfiles_parsed++;
|
2006-04-28 18:31:32 +00:00
|
|
|
if (generated_locally) {
|
|
|
|
sprintf(buf,
|
|
|
|
" <name>%s</name>\n"
|
|
|
|
" <generated_locally/>\n"
|
2008-01-07 22:04:54 +00:00
|
|
|
"</file_info>\n",
|
2004-11-22 19:17:13 +00:00
|
|
|
infiles[file_number]
|
|
|
|
);
|
2010-09-07 20:18:58 +00:00
|
|
|
} else if (nbytesdef == -1) {
|
2011-05-13 18:40:10 +00:00
|
|
|
// here if nybtes was not supplied; stage the file
|
|
|
|
//
|
2006-04-28 18:31:32 +00:00
|
|
|
dir_hier_path(
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
infiles[file_number], config_loc.download_dir,
|
|
|
|
config_loc.uldl_dir_fanout, path, true
|
2006-04-28 18:31:32 +00:00
|
|
|
);
|
2005-02-02 21:57:11 +00:00
|
|
|
|
2006-04-28 18:31:32 +00:00
|
|
|
// if file isn't found in hierarchy,
|
|
|
|
// look for it at top level and copy
|
|
|
|
//
|
|
|
|
if (!boinc_file_exists(path)) {
|
|
|
|
sprintf(top_download_path,
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
"%s/%s",config_loc.download_dir,
|
2006-04-28 18:31:32 +00:00
|
|
|
infiles[file_number]
|
|
|
|
);
|
|
|
|
boinc_copy(top_download_path, path);
|
2004-12-30 04:16:00 +00:00
|
|
|
}
|
2006-04-28 18:31:32 +00:00
|
|
|
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
if (!config_loc.cache_md5_info || !got_md5_info(path, md5, &nbytes)) {
|
2006-04-28 18:31:32 +00:00
|
|
|
retval = md5_file(path, md5, nbytes);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "process_wu_template: md5_file %d\n", retval);
|
|
|
|
return retval;
|
2011-05-13 18:40:10 +00:00
|
|
|
} else if (config_loc.cache_md5_info) {
|
2006-04-28 18:31:32 +00:00
|
|
|
write_md5_info(path, md5, nbytes);
|
|
|
|
}
|
2005-02-02 21:57:11 +00:00
|
|
|
}
|
2004-12-30 04:16:00 +00:00
|
|
|
|
2006-04-28 18:31:32 +00:00
|
|
|
dir_hier_url(
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
infiles[file_number], config_loc.download_url,
|
|
|
|
config_loc.uldl_dir_fanout, url
|
2006-04-28 18:31:32 +00:00
|
|
|
);
|
|
|
|
sprintf(buf,
|
|
|
|
" <name>%s</name>\n"
|
|
|
|
" <url>%s</url>\n"
|
|
|
|
" <md5_cksum>%s</md5_cksum>\n"
|
|
|
|
" <nbytes>%.0f</nbytes>\n"
|
|
|
|
"</file_info>\n",
|
|
|
|
infiles[file_number],
|
|
|
|
url,
|
|
|
|
md5,
|
|
|
|
nbytes
|
|
|
|
);
|
2010-09-07 20:18:58 +00:00
|
|
|
} else {
|
2011-05-13 18:40:10 +00:00
|
|
|
// here if nbytes etc. was supplied,
|
|
|
|
// i.e the file is already staged, possibly remotely
|
|
|
|
//
|
|
|
|
urlstr = "";
|
|
|
|
for (unsigned int i=0; i<urls.size(); i++) {
|
|
|
|
urlstr += " <url>" + urls.at(i) + "</url>\n";
|
|
|
|
}
|
2010-09-07 20:18:58 +00:00
|
|
|
sprintf(buf,
|
|
|
|
" <name>%s</name>\n"
|
2011-05-13 18:40:10 +00:00
|
|
|
"%s"
|
2010-09-07 20:18:58 +00:00
|
|
|
" <md5_cksum>%s</md5_cksum>\n"
|
|
|
|
" <nbytes>%.0f</nbytes>\n"
|
|
|
|
"</file_info>\n",
|
|
|
|
infiles[file_number],
|
|
|
|
urlstr.c_str(),
|
|
|
|
md5str.c_str(),
|
|
|
|
nbytesdef
|
|
|
|
);
|
2006-04-28 18:31:32 +00:00
|
|
|
}
|
2004-12-26 02:55:31 +00:00
|
|
|
out += buf;
|
2004-04-13 23:55:05 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2011-06-07 04:12:49 +00:00
|
|
|
char buf2[1024];
|
2011-07-04 23:51:00 +00:00
|
|
|
retval = xp.element(tag, buf2, sizeof(buf2));
|
|
|
|
if (retval) return retval;
|
|
|
|
out += buf2;
|
|
|
|
out += "\n";
|
2004-04-13 23:55:05 +00:00
|
|
|
}
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
2011-06-07 04:12:49 +00:00
|
|
|
} else if (!strcmp(tag, "workunit")) {
|
2003-01-15 23:54:24 +00:00
|
|
|
found = true;
|
2004-12-26 02:55:31 +00:00
|
|
|
out += "<workunit>\n";
|
2005-10-29 20:16:07 +00:00
|
|
|
if (command_line) {
|
2011-02-08 21:38:16 +00:00
|
|
|
//fprintf(stderr, "appending command line: %s\n", command_line);
|
2005-10-29 20:16:07 +00:00
|
|
|
out += "<command_line>\n";
|
|
|
|
out += command_line;
|
|
|
|
out += "\n</command_line>\n";
|
|
|
|
}
|
2011-06-07 04:12:49 +00:00
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!strcmp(tag, "/workunit")) {
|
|
|
|
if (additional_xml && strlen(additional_xml)) {
|
|
|
|
out += additional_xml;
|
|
|
|
out += "\n";
|
2004-07-23 20:48:49 +00:00
|
|
|
}
|
2011-06-07 04:12:49 +00:00
|
|
|
out += "</workunit>\n";
|
|
|
|
break;
|
|
|
|
} else if (!strcmp(tag, "file_ref")) {
|
|
|
|
out += "<file_ref>\n";
|
|
|
|
bool found_file_number = false, found_open_name = false;
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (xp.parse_int(tag, "file_number", file_number)) {
|
|
|
|
sprintf(buf, " <file_name>%s</file_name>\n",
|
|
|
|
infiles[file_number]
|
|
|
|
);
|
|
|
|
out += buf;
|
|
|
|
found_file_number = true;
|
|
|
|
continue;
|
|
|
|
} else if (xp.parse_str(tag, "open_name", open_name, sizeof(open_name))) {
|
|
|
|
sprintf(buf, " <open_name>%s</open_name>\n", open_name);
|
|
|
|
out += buf;
|
|
|
|
found_open_name = true;
|
|
|
|
continue;
|
|
|
|
} else if (!strcmp(tag, "/file_ref")) {
|
|
|
|
if (!found_file_number) {
|
|
|
|
fprintf(stderr, "No file number found\n");
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
if (!found_open_name) {
|
|
|
|
fprintf(stderr, "No open name found\n");
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
out += "</file_ref>\n";
|
|
|
|
break;
|
2011-07-04 23:51:00 +00:00
|
|
|
} else if (xp.parse_string(tag, "file_name", tmpstr)) {
|
|
|
|
fprintf(stderr, "<file_name> ignored in <file_ref> element.\n");
|
|
|
|
continue;
|
2011-06-07 04:12:49 +00:00
|
|
|
} else {
|
|
|
|
char buf2[1024];
|
2011-07-04 23:51:00 +00:00
|
|
|
retval = xp.element(tag, buf2, sizeof(buf2));
|
|
|
|
if (retval) return retval;
|
|
|
|
out += buf2;
|
|
|
|
out += "\n";
|
2011-06-07 04:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (xp.parse_string(tag, "command_line", cmdline)) {
|
|
|
|
if (command_line) {
|
|
|
|
fprintf(stderr, "Can't specify command line twice");
|
2006-06-14 20:17:35 +00:00
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2011-06-07 04:12:49 +00:00
|
|
|
out += "<command_line>\n";
|
|
|
|
out += cmdline;
|
|
|
|
out += "\n</command_line>\n";
|
2011-08-07 04:32:02 +00:00
|
|
|
} else if (xp.parse_double(tag, "rsc_fpops_est", dtemp)) {
|
|
|
|
if (!wu.rsc_fpops_est) {
|
|
|
|
wu.rsc_fpops_est = dtemp;
|
|
|
|
}
|
2011-06-07 04:12:49 +00:00
|
|
|
continue;
|
2011-08-07 04:32:02 +00:00
|
|
|
} else if (xp.parse_double(tag, "rsc_fpops_bound", dtemp)) {
|
|
|
|
if (!wu.rsc_fpops_bound) {
|
|
|
|
wu.rsc_fpops_bound = dtemp;
|
|
|
|
}
|
2011-06-07 04:12:49 +00:00
|
|
|
continue;
|
2011-08-07 04:32:02 +00:00
|
|
|
} else if (xp.parse_double(tag, "rsc_memory_bound", dtemp)) {
|
|
|
|
if (!wu.rsc_memory_bound) {
|
|
|
|
wu.rsc_memory_bound = dtemp;
|
|
|
|
}
|
2011-06-07 04:12:49 +00:00
|
|
|
continue;
|
2011-08-07 04:32:02 +00:00
|
|
|
} else if (xp.parse_double(tag, "rsc_bandwidth_bound", dtemp)) {
|
|
|
|
if (!wu.rsc_bandwidth_bound) {
|
|
|
|
wu.rsc_bandwidth_bound = dtemp;
|
|
|
|
}
|
2011-06-07 04:12:49 +00:00
|
|
|
continue;
|
2011-08-07 04:32:02 +00:00
|
|
|
} else if (xp.parse_double(tag, "rsc_disk_bound", dtemp)) {
|
|
|
|
if (!wu.rsc_disk_bound) {
|
|
|
|
wu.rsc_disk_bound = dtemp;
|
|
|
|
}
|
2011-06-07 04:12:49 +00:00
|
|
|
continue;
|
|
|
|
} else if (xp.parse_int(tag, "batch", wu.batch)) {
|
|
|
|
continue;
|
2011-08-07 04:32:02 +00:00
|
|
|
} else if (xp.parse_int(tag, "delay_bound", itemp)) {
|
|
|
|
if (!wu.delay_bound) {
|
|
|
|
wu.delay_bound = itemp;
|
|
|
|
}
|
2011-06-07 04:12:49 +00:00
|
|
|
continue;
|
|
|
|
} else if (xp.parse_int(tag, "min_quorum", wu.min_quorum)) {
|
|
|
|
continue;
|
|
|
|
} else if (xp.parse_int(tag, "target_nresults", wu.target_nresults)) {
|
|
|
|
continue;
|
|
|
|
} else if (xp.parse_int(tag, "max_error_results", wu.max_error_results)) {
|
|
|
|
continue;
|
|
|
|
} else if (xp.parse_int(tag, "max_total_results", wu.max_total_results)) {
|
|
|
|
continue;
|
|
|
|
} else if (xp.parse_int(tag, "max_success_results", wu.max_success_results)) {
|
|
|
|
continue;
|
2006-06-14 20:17:35 +00:00
|
|
|
} else {
|
2011-06-07 04:12:49 +00:00
|
|
|
char buf2[1024];
|
2011-07-04 23:51:00 +00:00
|
|
|
retval = xp.element(tag, buf2, sizeof(buf2));
|
|
|
|
if (retval) return retval;
|
|
|
|
out += buf2;
|
|
|
|
out += "\n";
|
2004-04-13 23:55:05 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-15 23:54:24 +00:00
|
|
|
if (!found) {
|
2008-02-21 00:47:50 +00:00
|
|
|
fprintf(stderr, "process_wu_template: bad WU template - no <workunit>\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (nfiles_parsed != ninfiles) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"process_wu_template: %d input files listed, but template has %d\n",
|
|
|
|
ninfiles, nfiles_parsed
|
|
|
|
);
|
2003-01-15 23:54:24 +00:00
|
|
|
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",
|
2010-07-08 18:02:07 +00:00
|
|
|
(int)out.size(), (int)sizeof(wu.xml_doc)-1
|
2004-05-13 18:18:22 +00:00
|
|
|
);
|
|
|
|
return ERR_BUFFER_OVERFLOW;
|
|
|
|
}
|
2011-02-08 21:38:16 +00:00
|
|
|
//fprintf(stderr, "copying to xml_doc: %s\n", out.c_str());
|
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;
|
|
|
|
}
|
|
|
|
|
2006-01-26 00:19:05 +00:00
|
|
|
// initialize an about-to-be-created result, given its WU
|
2002-11-07 19:31:34 +00:00
|
|
|
//
|
2008-02-21 00:47:50 +00:00
|
|
|
static void initialize_result(DB_RESULT& result, WORKUNIT& 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;
|
2006-01-26 00:19:05 +00:00
|
|
|
result.batch = wu.batch;
|
2002-11-07 19:31:34 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 00:47:50 +00:00
|
|
|
int create_result_ti(
|
|
|
|
TRANSITIONER_ITEM& ti,
|
|
|
|
char* result_template_filename,
|
|
|
|
char* result_name_suffix,
|
|
|
|
R_RSA_PRIVATE_KEY& key,
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
SCHED_CONFIG& config_loc,
|
2008-02-21 00:47:50 +00:00
|
|
|
char* query_string,
|
|
|
|
// if nonzero, write value list here; else do insert
|
|
|
|
int priority_increase
|
|
|
|
) {
|
|
|
|
WORKUNIT wu;
|
|
|
|
|
|
|
|
// copy relevant fields from TRANSITIONER_ITEM to WORKUNIT
|
|
|
|
//
|
|
|
|
strcpy(wu.name, ti.name);
|
|
|
|
wu.id = ti.id;
|
|
|
|
wu.appid = ti.appid;
|
|
|
|
wu.priority = ti.priority;
|
|
|
|
wu.batch = ti.batch;
|
|
|
|
return create_result(
|
|
|
|
wu,
|
|
|
|
result_template_filename,
|
|
|
|
result_name_suffix,
|
|
|
|
key,
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
config_loc,
|
2008-02-21 00:47:50 +00:00
|
|
|
query_string,
|
|
|
|
priority_increase
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2002-10-16 01:21:00 +00:00
|
|
|
// Create a new result for the given WU.
|
2010-08-29 08:43:40 +00:00
|
|
|
// This is called from:
|
|
|
|
// - the transitioner
|
|
|
|
// - the scheduler (for assigned jobs)
|
2002-10-16 01:21:00 +00:00
|
|
|
//
|
2002-07-05 05:33:40 +00:00
|
|
|
int create_result(
|
2008-02-21 00:47:50 +00:00
|
|
|
WORKUNIT& 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,
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
SCHED_CONFIG& config_loc,
|
2007-04-05 17:02:01 +00:00
|
|
|
char* query_string,
|
2004-07-21 21:50:25 +00:00
|
|
|
// if nonzero, write value list here; else do insert
|
2008-02-21 00:47:50 +00:00
|
|
|
int priority_increase
|
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];
|
2008-03-31 16:19:45 +00:00
|
|
|
char result_template[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);
|
2010-07-16 18:38:14 +00:00
|
|
|
result.priority += priority_increase;
|
2004-12-06 22:41:19 +00:00
|
|
|
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);
|
2006-05-30 17:02:46 +00:00
|
|
|
retval = read_filename(
|
|
|
|
result_template_filename, result_template, sizeof(result_template)
|
|
|
|
);
|
2004-07-02 17:53:31 +00:00
|
|
|
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(
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
result_template, key, base_outfile_name, config_loc
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2006-05-30 17:02:46 +00:00
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "process_result_template() error: %d\n", retval);
|
|
|
|
}
|
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",
|
2010-07-08 18:02:07 +00:00
|
|
|
(int)strlen(result_template), (int)sizeof(result.xml_doc_in)-1
|
2004-05-13 18:18:22 +00:00
|
|
|
);
|
|
|
|
return ERR_BUFFER_OVERFLOW;
|
|
|
|
}
|
2006-01-05 06:42:45 +00:00
|
|
|
strlcpy(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
|
|
|
}
|
2005-06-27 16:31:49 +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
|
|
|
|
//
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
int check_files(char** infiles, int ninfiles, SCHED_CONFIG& config_loc) {
|
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(
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
infiles[i], config_loc.download_dir, config_loc.uldl_dir_fanout, path
|
2004-08-06 11:42:41 +00:00
|
|
|
);
|
2010-07-08 18:02:07 +00:00
|
|
|
if (!boinc_file_exists(path)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2005-01-02 07:44:40 +00:00
|
|
|
|
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,
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
SCHED_CONFIG& config_loc,
|
2007-01-30 18:19:30 +00:00
|
|
|
const char* command_line,
|
|
|
|
const char* additional_xml
|
2002-04-30 22:22:54 +00:00
|
|
|
) {
|
2003-08-15 23:44:28 +00:00
|
|
|
int retval;
|
2008-03-31 16:19:45 +00:00
|
|
|
char _result_template[BLOB_SIZE];
|
|
|
|
char wu_template[BLOB_SIZE];
|
2002-09-26 05:57:10 +00:00
|
|
|
|
2003-09-30 18:09:58 +00:00
|
|
|
#if 0
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
retval = check_files(infiles, ninfiles, config_loc);
|
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(
|
- server code: at some point I made a global var "SCHED_CONFIG config",
mostly so that the parse function could assume
that everything was initially zero.
However, various back-end functions pass around SCHED_CONFIG&
as an argument (also named "config").
This creates a shadow, which is always bad.
Worse is the possibility that some projects have back-end programs
that have a SCHED_CONFIG variable that's automatic,
and therefore isn't zero initially,
and therefore isn't parsing correctly.
To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers,
and have the parse routine zero the structure.
I was tempted to remove the SCHED_CONFIG& args to back-end functions,
but this would have broken some projects' code.
I did, however, change the name from config to config_loc
to avoid shadowing.
Also fixed various other compiler warnings.
svn path=/trunk/boinc/; revision=15541
2008-07-02 17:24:53 +00:00
|
|
|
wu, wu_template, infiles, ninfiles, config_loc, command_line, additional_xml
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2002-10-03 18:33:46 +00:00
|
|
|
if (retval) {
|
2011-04-20 23:32:14 +00:00
|
|
|
fprintf(stderr, "process_wu_template(): %d\n", retval);
|
2002-10-03 18:33:46 +00:00
|
|
|
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) {
|
2011-04-20 23:32:14 +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) {
|
2010-07-08 18:02:07 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"result template filename is too big: %d bytes, max is %d\n",
|
|
|
|
(int)strlen(result_template_filename),
|
|
|
|
(int)sizeof(wu.result_template_file)-1
|
2004-05-13 18:18:22 +00:00
|
|
|
);
|
|
|
|
return ERR_BUFFER_OVERFLOW;
|
|
|
|
}
|
2006-01-05 06:42:45 +00:00
|
|
|
strlcpy(wu.result_template_file, result_template_filename, sizeof(wu.result_template_file));
|
2003-08-15 23:44:28 +00:00
|
|
|
|
2007-04-20 17:14:08 +00:00
|
|
|
if (wu.rsc_fpops_est == 0) {
|
|
|
|
fprintf(stderr, "no rsc_fpops_est given; can't create job\n");
|
|
|
|
return ERR_NO_OPTION;
|
|
|
|
}
|
|
|
|
if (wu.rsc_fpops_bound == 0) {
|
|
|
|
fprintf(stderr, "no rsc_fpops_bound given; can't create job\n");
|
|
|
|
return ERR_NO_OPTION;
|
|
|
|
}
|
|
|
|
if (wu.rsc_disk_bound == 0) {
|
|
|
|
fprintf(stderr, "no rsc_disk_bound given; can't create job\n");
|
|
|
|
return ERR_NO_OPTION;
|
|
|
|
}
|
|
|
|
if (wu.target_nresults == 0) {
|
|
|
|
fprintf(stderr, "no target_nresults given; can't create job\n");
|
|
|
|
return ERR_NO_OPTION;
|
|
|
|
}
|
|
|
|
if (wu.max_error_results == 0) {
|
|
|
|
fprintf(stderr, "no max_error_results given; can't create job\n");
|
|
|
|
return ERR_NO_OPTION;
|
|
|
|
}
|
|
|
|
if (wu.max_total_results == 0) {
|
|
|
|
fprintf(stderr, "no max_total_results given; can't create job\n");
|
|
|
|
return ERR_NO_OPTION;
|
|
|
|
}
|
|
|
|
if (wu.max_success_results == 0) {
|
|
|
|
fprintf(stderr, "no max_success_results given; can't create job\n");
|
|
|
|
return ERR_NO_OPTION;
|
|
|
|
}
|
2009-09-16 03:10:22 +00:00
|
|
|
if (wu.max_success_results > wu.max_total_results) {
|
|
|
|
fprintf(stderr, "max_success_results > max_total_results; can't create job\n");
|
|
|
|
return ERR_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
if (wu.max_error_results > wu.max_total_results) {
|
|
|
|
fprintf(stderr, "max_error_results > max_total_results; can't create job\n");
|
|
|
|
return ERR_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
if (wu.target_nresults > wu.max_success_results) {
|
|
|
|
fprintf(stderr, "target_nresults > max_success_results; can't create job\n");
|
|
|
|
return ERR_INVALID_PARAM;
|
|
|
|
}
|
2008-02-26 17:24:29 +00:00
|
|
|
if (strstr(wu.name, ASSIGNED_WU_STR)) {
|
2008-02-21 00:47:50 +00:00
|
|
|
wu.transition_time = INT_MAX;
|
|
|
|
} else {
|
|
|
|
wu.transition_time = time(0);
|
|
|
|
}
|
2008-03-04 23:50:38 +00:00
|
|
|
if (wu.id) {
|
|
|
|
retval = wu.update();
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "create_work: workunit.update() %d\n", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
retval = wu.insert();
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "create_work: workunit.insert() %d\n", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
wu.id = boinc_db.insert_id();
|
2002-11-06 09:03:55 +00:00
|
|
|
}
|
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
|
|
|
|
2011-04-24 02:00:27 +00:00
|
|
|
// STUFF RELATED TO FILE UPLOAD/DOWNLOAD
|
|
|
|
|
2011-07-19 20:52:41 +00:00
|
|
|
int get_file(
|
2011-07-20 22:27:01 +00:00
|
|
|
int host_id, const char* file_name, vector<const char*> urls,
|
|
|
|
double max_nbytes,
|
|
|
|
double report_deadline,
|
|
|
|
bool generate_upload_certificate,
|
|
|
|
R_RSA_PRIVATE_KEY& key
|
2011-04-24 02:00:27 +00:00
|
|
|
) {;
|
2011-07-19 20:52:41 +00:00
|
|
|
char buf[8192];
|
2011-04-24 02:00:27 +00:00
|
|
|
DB_MSG_TO_HOST mth;
|
|
|
|
int retval;
|
2011-07-19 20:52:41 +00:00
|
|
|
|
2011-04-24 02:00:27 +00:00
|
|
|
mth.clear();
|
|
|
|
mth.create_time = time(0);
|
|
|
|
mth.hostid = host_id;
|
|
|
|
strcpy(mth.variety, "file_xfer");
|
|
|
|
mth.handled = false;
|
|
|
|
sprintf(mth.xml,
|
|
|
|
"<app>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
" <name>file_xfer</name>\n"
|
2011-04-24 02:00:27 +00:00
|
|
|
"</app>\n"
|
|
|
|
"<app_version>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
" <app_name>file_xfer</app_name>\n"
|
|
|
|
" <version_num>0</version_num>\n"
|
2011-04-24 02:00:27 +00:00
|
|
|
"</app_version>\n"
|
|
|
|
"<file_info>\n"
|
2011-07-20 22:27:01 +00:00
|
|
|
" <name>%s</name>\n"
|
|
|
|
" <max_nbytes>%.0f</max_nbytes>\n",
|
|
|
|
max_nbytes,
|
2011-07-19 20:52:41 +00:00
|
|
|
file_name
|
|
|
|
);
|
|
|
|
for (unsigned int i=0; i<urls.size(); i++) {
|
|
|
|
sprintf(buf, " <url>%s</url>\n", urls[i]);
|
|
|
|
strcat(mth.xml, buf);
|
|
|
|
}
|
|
|
|
sprintf(buf,
|
2011-04-24 02:00:27 +00:00
|
|
|
"</file_info>\n"
|
|
|
|
"<workunit>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
" <name>upload_%s</name>\n"
|
|
|
|
" <app_name>file_xfer</app_name>\n"
|
|
|
|
"</workunit>\n"
|
|
|
|
"<result>\n"
|
|
|
|
" <wu_name>upload_%s</wu_name>\n"
|
|
|
|
" <name>upload_%s</name>\n"
|
|
|
|
" <file_ref>\n"
|
|
|
|
" <file_name>%s</file_name>\n"
|
|
|
|
" </file_ref>\n"
|
2011-07-20 22:27:01 +00:00
|
|
|
" <report_deadline>%f</report_deadline>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
"</result>\n",
|
|
|
|
file_name,
|
|
|
|
file_name,
|
|
|
|
file_name,
|
2011-07-20 22:27:01 +00:00
|
|
|
file_name,
|
|
|
|
report_deadline
|
2011-04-24 02:00:27 +00:00
|
|
|
);
|
2011-07-19 20:52:41 +00:00
|
|
|
strcat(mth.xml, buf);
|
2011-07-20 22:27:01 +00:00
|
|
|
if (generate_upload_certificate) {
|
|
|
|
add_signatures(mth.xml, key);
|
|
|
|
}
|
2011-07-19 20:52:41 +00:00
|
|
|
|
2011-04-24 02:00:27 +00:00
|
|
|
retval = mth.insert();
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "msg_to_host.insert(): %s\n", boincerror(retval));
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-19 20:52:41 +00:00
|
|
|
int put_file(
|
|
|
|
int host_id, const char* file_name,
|
2011-07-20 22:27:01 +00:00
|
|
|
vector<const char*> urls, const char* md5, double nbytes,
|
|
|
|
double report_deadline
|
2011-04-24 02:00:27 +00:00
|
|
|
) {
|
2011-07-19 20:52:41 +00:00
|
|
|
char buf[8192];
|
2011-04-24 02:00:27 +00:00
|
|
|
DB_MSG_TO_HOST mth;
|
|
|
|
int retval;
|
|
|
|
mth.clear();
|
|
|
|
mth.create_time = time(0);
|
|
|
|
mth.hostid = host_id;
|
|
|
|
strcpy(mth.variety, "file_xfer");
|
|
|
|
mth.handled = false;
|
|
|
|
sprintf(mth.xml,
|
|
|
|
"<app>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
" <name>file_xfer</name>\n"
|
2011-04-24 02:00:27 +00:00
|
|
|
"</app>\n"
|
|
|
|
"<app_version>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
" <app_name>file_xfer</app_name>\n"
|
|
|
|
" <version_num>0</version_num>\n"
|
2011-04-24 02:00:27 +00:00
|
|
|
"</app_version>\n"
|
|
|
|
"<file_info>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
" <name>%s</name>\n",
|
|
|
|
file_name
|
|
|
|
);
|
|
|
|
for (unsigned int i=0; i<urls.size(); i++) {
|
|
|
|
sprintf(buf, " <url>%s</url>\n", urls[i]);
|
|
|
|
strcat(mth.xml, buf);
|
|
|
|
}
|
|
|
|
sprintf(buf,
|
2011-04-24 02:00:27 +00:00
|
|
|
" <md5_cksum>%s</md5_cksum>\n"
|
|
|
|
" <nbytes>%.0f</nbytes>\n"
|
|
|
|
" <sticky/>\n"
|
|
|
|
"</file_info>\n"
|
|
|
|
"<workunit>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
" <name>download_%s</name>\n"
|
|
|
|
" <app_name>file_xfer</app_name>\n"
|
2011-04-24 02:00:27 +00:00
|
|
|
" <file_ref>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
" <file_name>%s</file_name>\n"
|
2011-04-24 02:00:27 +00:00
|
|
|
" </file_ref>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
"</workunit>\n"
|
|
|
|
"<result>\n"
|
|
|
|
" <wu_name>download_%s</wu_name>\n"
|
|
|
|
" <name>download_%s</name>\n"
|
2011-07-20 22:27:01 +00:00
|
|
|
" <report_deadline>%f</report_deadline>\n"
|
2011-07-19 20:52:41 +00:00
|
|
|
"</result>\n",
|
|
|
|
md5,
|
|
|
|
nbytes,
|
|
|
|
file_name,
|
|
|
|
file_name,
|
|
|
|
file_name,
|
2011-07-20 22:27:01 +00:00
|
|
|
file_name,
|
|
|
|
report_deadline
|
2011-04-24 02:00:27 +00:00
|
|
|
);
|
2011-07-19 20:52:41 +00:00
|
|
|
strcat(mth.xml, buf);
|
2011-04-24 02:00:27 +00:00
|
|
|
retval = mth.insert();
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "msg_to_host.insert(): %s\n", boincerror(retval));
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_b5f8b10eb5 = "$Id$";
|