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
|
|
|
|
2011-09-01 19:58:27 +00:00
|
|
|
#include "process_input_template.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2011-09-01 19:58:27 +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;
|
|
|
|
}
|
|
|
|
|
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);
|
2011-09-01 19:58:27 +00:00
|
|
|
retval = process_input_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-09-01 19:58:27 +00:00
|
|
|
fprintf(stderr, "process_input_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",
|
2011-08-10 17:11:08 +00:00
|
|
|
file_name,
|
|
|
|
max_nbytes
|
2011-07-19 20:52:41 +00:00
|
|
|
);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-10-18 07:15:04 +00:00
|
|
|
int cancel_jobs(int min_id, int max_id) {
|
|
|
|
DB_WORKUNIT wu;
|
|
|
|
DB_RESULT result;
|
|
|
|
char set_clause[256], where_clause[256];
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
sprintf(set_clause, "server_state=%d, outcome=%d",
|
|
|
|
RESULT_SERVER_STATE_OVER, RESULT_OUTCOME_DIDNT_NEED
|
|
|
|
);
|
|
|
|
sprintf(where_clause, "server_state=%d and workunitid >=%d and workunitid<= %d",
|
|
|
|
RESULT_SERVER_STATE_UNSENT, min_id, max_id
|
|
|
|
);
|
|
|
|
retval = result.update_fields_noid(set_clause, where_clause);
|
|
|
|
if (retval) return retval;
|
|
|
|
|
|
|
|
sprintf(set_clause, "error_mask=error_mask|%d, transition_time=%d",
|
|
|
|
WU_ERROR_CANCELLED, (int)(time(0))
|
|
|
|
);
|
|
|
|
sprintf(where_clause, "id>=%d and id<=%d", min_id, max_id);
|
|
|
|
retval = wu.update_fields_noid(set_clause, where_clause);
|
|
|
|
if (retval) return retval;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_b5f8b10eb5 = "$Id$";
|