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-06-14 20:15:51 +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-06-14 20:15:51 +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-09-26 18:11:06 +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/>.
|
2005-01-20 23:22:22 +00:00
|
|
|
|
2002-09-20 21:17:47 +00:00
|
|
|
// The BOINC file upload handler.
|
2007-03-05 18:34:30 +00:00
|
|
|
// See doc/upload.php for protocol spec.
|
2003-12-17 19:14:17 +00:00
|
|
|
//
|
2002-07-05 05:33:40 +00:00
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <ctime>
|
2002-08-07 22:52:10 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cerrno>
|
2003-12-17 19:11:47 +00:00
|
|
|
#include <unistd.h>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <csignal>
|
2005-04-19 14:30:07 +00:00
|
|
|
#include <fcntl.h>
|
2009-09-17 17:56:59 +00:00
|
|
|
#include <string>
|
2002-07-05 05:33:40 +00:00
|
|
|
|
2009-02-26 00:23:23 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#include "boinc_fcgi.h"
|
|
|
|
#else
|
|
|
|
#include <cstdio>
|
|
|
|
#endif
|
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "crypt.h"
|
2002-07-05 05:33:40 +00:00
|
|
|
#include "parse.h"
|
2003-03-06 17:42:49 +00:00
|
|
|
#include "util.h"
|
2004-10-06 20:45:21 +00:00
|
|
|
#include "error_numbers.h"
|
2009-05-07 13:54:51 +00:00
|
|
|
#include "str_util.h"
|
2006-05-31 20:39:32 +00:00
|
|
|
#include "filesys.h"
|
2009-09-17 17:56:59 +00:00
|
|
|
#include "svn_version.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
|
2003-08-15 00:45:25 +00:00
|
|
|
#include "sched_config.h"
|
2003-05-16 19:22:57 +00:00
|
|
|
#include "sched_util.h"
|
2002-07-05 05:33:40 +00:00
|
|
|
|
2008-02-05 20:16:57 +00:00
|
|
|
#include "sched_msgs.h"
|
2005-12-14 22:48:05 +00:00
|
|
|
|
2012-12-24 20:14:22 +00:00
|
|
|
using std::string;
|
|
|
|
|
2012-08-15 21:27:38 +00:00
|
|
|
#define LOCK_FILES
|
|
|
|
// comment this out to not lock files
|
|
|
|
// this may avoid filesystem hangs
|
|
|
|
|
2003-05-08 17:13:57 +00:00
|
|
|
#define ERR_TRANSIENT true
|
|
|
|
#define ERR_PERMANENT false
|
|
|
|
|
2005-04-11 09:00:50 +00:00
|
|
|
char this_filename[256];
|
2009-01-12 23:05:49 +00:00
|
|
|
double start_time();
|
2005-04-11 09:00:50 +00:00
|
|
|
|
2004-01-22 01:35:09 +00:00
|
|
|
inline static const char* get_remote_addr() {
|
|
|
|
char* p = getenv("REMOTE_ADDR");
|
|
|
|
if (p) return p;
|
|
|
|
return "Unknown remote address";
|
2003-06-14 20:15:54 +00:00
|
|
|
}
|
|
|
|
|
2003-06-14 20:15:50 +00:00
|
|
|
int return_error(bool transient, const char* message, ...) {
|
2004-10-07 17:39:13 +00:00
|
|
|
va_list va;
|
|
|
|
va_start(va, message);
|
|
|
|
char buf[10240];
|
|
|
|
|
|
|
|
vsprintf(buf, message, va);
|
|
|
|
va_end(va);
|
|
|
|
|
2005-12-14 22:48:05 +00:00
|
|
|
fprintf(stdout,
|
2002-12-02 04:29:40 +00:00
|
|
|
"Content-type: text/plain\n\n"
|
|
|
|
"<data_server_reply>\n"
|
2003-05-08 17:13:57 +00:00
|
|
|
" <status>%d</status>\n"
|
2002-12-02 04:29:40 +00:00
|
|
|
" <message>%s</message>\n"
|
|
|
|
"</data_server_reply>\n",
|
2003-05-08 17:13:57 +00:00
|
|
|
transient?1:-1,
|
2004-10-07 17:39:13 +00:00
|
|
|
buf
|
2003-06-14 20:15:53 +00:00
|
|
|
);
|
2003-06-14 20:15:50 +00:00
|
|
|
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"Returning error to client %s: %s (%s)\n",
|
2003-06-14 20:15:54 +00:00
|
|
|
get_remote_addr(), buf,
|
2003-06-14 20:15:53 +00:00
|
|
|
transient?"transient":"permanent"
|
|
|
|
);
|
2002-12-02 04:29:40 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
int return_success(const char* text) {
|
2005-12-14 22:48:05 +00:00
|
|
|
fprintf(stdout,
|
2002-12-02 04:29:40 +00:00
|
|
|
"Content-type: text/plain\n\n"
|
|
|
|
"<data_server_reply>\n"
|
|
|
|
" <status>0</status>\n"
|
|
|
|
);
|
2003-05-08 17:13:57 +00:00
|
|
|
if (text) {
|
2005-12-14 22:48:05 +00:00
|
|
|
fprintf(stdout, " %s\n", text);
|
2003-05-08 17:13:57 +00:00
|
|
|
}
|
2005-12-14 22:48:05 +00:00
|
|
|
fprintf(stdout, "</data_server_reply>\n");
|
2002-07-05 05:33:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-18 23:38:52 +00:00
|
|
|
#define BLOCK_SIZE (256*1024)
|
2005-04-19 14:30:07 +00:00
|
|
|
double bytes_left=-1;
|
2002-07-05 05:33:40 +00:00
|
|
|
|
|
|
|
// read from socket, write to file
|
2004-01-22 01:35:09 +00:00
|
|
|
// ALWAYS returns an HTML reply
|
2002-07-05 05:33:40 +00:00
|
|
|
//
|
2002-07-07 20:39:24 +00:00
|
|
|
int copy_socket_to_file(FILE* in, char* path, double offset, double nbytes) {
|
2002-07-05 05:33:40 +00:00
|
|
|
unsigned char buf[BLOCK_SIZE];
|
2005-04-15 19:44:26 +00:00
|
|
|
struct stat sbuf;
|
2012-08-18 23:38:52 +00:00
|
|
|
int pid, fd=0;
|
2005-04-15 19:44:26 +00:00
|
|
|
|
2005-04-19 14:30:07 +00:00
|
|
|
// caller guarantees that nbytes > offset
|
2006-01-11 22:08:39 +00:00
|
|
|
//
|
2002-07-05 05:33:40 +00:00
|
|
|
bytes_left = nbytes - offset;
|
2003-08-15 19:23:44 +00:00
|
|
|
|
2005-04-19 16:35:59 +00:00
|
|
|
while (bytes_left > 0) {
|
2007-01-26 18:38:17 +00:00
|
|
|
int n, m, to_write;
|
2005-04-19 14:30:07 +00:00
|
|
|
|
|
|
|
m = bytes_left<(double)BLOCK_SIZE ? (int)bytes_left : BLOCK_SIZE;
|
|
|
|
|
2005-04-19 16:35:59 +00:00
|
|
|
// try to get m bytes from socket (n>=0 is number actually returned)
|
2006-01-11 22:08:39 +00:00
|
|
|
//
|
2002-07-05 05:33:40 +00:00
|
|
|
n = fread(buf, 1, m, in);
|
2005-04-19 14:30:07 +00:00
|
|
|
|
2012-08-18 23:38:52 +00:00
|
|
|
// delay opening the file until we've done the first socket read
|
|
|
|
// to avoid filesystem lockups (WCG, possible paranoia)
|
|
|
|
//
|
|
|
|
if (!fd) {
|
|
|
|
// Use raw IO not buffered IO so that we can use reliable
|
|
|
|
// posix file locking.
|
|
|
|
// Advisory file locking is not guaranteed reliable when
|
|
|
|
// used with stream buffered IO.
|
|
|
|
//
|
2012-08-22 18:23:01 +00:00
|
|
|
fd = open(path,
|
2012-08-18 23:38:52 +00:00
|
|
|
O_WRONLY|O_CREAT,
|
|
|
|
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH
|
|
|
|
);
|
|
|
|
if (fd<0) {
|
|
|
|
return return_error(ERR_TRANSIENT,
|
|
|
|
"can't open file %s: %s\n", path, strerror(errno)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef LOCK_FILES
|
|
|
|
// Put an advisory lock on the file.
|
|
|
|
// This will prevent OTHER instances of file_upload_handler
|
|
|
|
// from being able to write to the file.
|
|
|
|
//
|
|
|
|
pid = mylockf(fd);
|
|
|
|
if (pid>0) {
|
|
|
|
close(fd);
|
|
|
|
return return_error(ERR_TRANSIENT,
|
|
|
|
"can't lock file %s: %s locked by PID=%d\n",
|
|
|
|
path, strerror(errno), pid
|
|
|
|
);
|
|
|
|
} else if (pid < 0) {
|
|
|
|
close(fd);
|
|
|
|
return return_error(ERR_TRANSIENT, "can't lock file %s\n", path);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// check that file length corresponds to offset
|
|
|
|
// TODO: use a 64-bit variant
|
|
|
|
//
|
|
|
|
if (stat(path, &sbuf)) {
|
|
|
|
close(fd);
|
|
|
|
return return_error(ERR_TRANSIENT,
|
|
|
|
"can't stat file %s: %s\n", path, strerror(errno)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (sbuf.st_size < offset) {
|
|
|
|
close(fd);
|
|
|
|
return return_error(ERR_TRANSIENT,
|
|
|
|
"length of file %s %d bytes < offset %.0f bytes",
|
|
|
|
path, (int)sbuf.st_size, offset
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (offset) lseek(fd, offset, SEEK_SET);
|
|
|
|
if (sbuf.st_size > offset) {
|
|
|
|
log_messages.printf(MSG_CRITICAL,
|
|
|
|
"file %s length on disk %d bytes; host upload starting at %.0f bytes.\n",
|
|
|
|
this_filename, (int)sbuf.st_size, offset
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-19 14:30:07 +00:00
|
|
|
// try to write n bytes to file
|
2006-01-11 22:08:39 +00:00
|
|
|
//
|
2005-04-19 14:30:07 +00:00
|
|
|
to_write=n;
|
|
|
|
while (to_write > 0) {
|
2007-03-05 18:34:30 +00:00
|
|
|
ssize_t ret = write(fd, buf+n-to_write, to_write);
|
2009-03-25 16:52:26 +00:00
|
|
|
if (ret < 0) {
|
2005-04-19 14:30:07 +00:00
|
|
|
close(fd);
|
2007-06-20 22:34:06 +00:00
|
|
|
const char* errmsg;
|
2007-03-05 18:34:30 +00:00
|
|
|
if (errno == ENOSPC) {
|
|
|
|
errmsg = "No space left on server";
|
|
|
|
} else {
|
|
|
|
errmsg = strerror(errno);
|
|
|
|
}
|
2006-01-11 22:08:39 +00:00
|
|
|
return return_error(ERR_TRANSIENT,
|
2007-03-05 18:34:30 +00:00
|
|
|
"can't write file %s: %s\n", path, errmsg
|
2006-01-11 22:08:39 +00:00
|
|
|
);
|
2005-04-19 14:30:07 +00:00
|
|
|
}
|
|
|
|
to_write -= ret;
|
2002-07-05 05:33:40 +00:00
|
|
|
}
|
2005-04-19 14:30:07 +00:00
|
|
|
|
|
|
|
// check that we got all bytes from socket that were requested
|
2007-01-26 18:38:17 +00:00
|
|
|
// Note: fread() reads less than requested only if there's
|
|
|
|
// an error or EOF (see the man page)
|
2006-01-11 22:08:39 +00:00
|
|
|
//
|
2005-04-19 14:30:07 +00:00
|
|
|
if (n != m) {
|
|
|
|
close(fd);
|
2007-01-26 18:38:17 +00:00
|
|
|
if (feof(in)) {
|
|
|
|
return return_error(ERR_TRANSIENT,
|
|
|
|
"EOF on socket read : asked for %d, got %d\n",
|
|
|
|
m, n
|
|
|
|
);
|
|
|
|
} else if (ferror(in)) {
|
|
|
|
return return_error(ERR_TRANSIENT,
|
|
|
|
"error %d (%s) on socket read: asked for %d, got %d\n",
|
|
|
|
ferror(in), strerror(ferror(in)), m, n
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return return_error(ERR_TRANSIENT,
|
|
|
|
"incomplete socket read: asked for %d, got %d\n",
|
|
|
|
m, n
|
|
|
|
);
|
|
|
|
}
|
2005-04-19 14:30:07 +00:00
|
|
|
}
|
|
|
|
|
2002-07-05 05:33:40 +00:00
|
|
|
bytes_left -= n;
|
|
|
|
}
|
2005-04-19 14:30:07 +00:00
|
|
|
close(fd);
|
2004-01-22 01:35:09 +00:00
|
|
|
return return_success(0);
|
2002-07-05 05:33:40 +00:00
|
|
|
}
|
|
|
|
|
2003-06-14 20:15:46 +00:00
|
|
|
// read from socket, discard data
|
|
|
|
//
|
|
|
|
void copy_socket_to_null(FILE* in) {
|
|
|
|
unsigned char buf[BLOCK_SIZE];
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int n = fread(buf, 1, BLOCK_SIZE, in);
|
|
|
|
if (n <= 0) return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-22 01:35:09 +00:00
|
|
|
// ALWAYS generates an HTML reply
|
|
|
|
//
|
2002-12-02 04:29:40 +00:00
|
|
|
int handle_file_upload(FILE* in, R_RSA_PUBLIC_KEY& key) {
|
2012-05-09 16:11:50 +00:00
|
|
|
char buf[256], path[MAXPATHLEN], signed_xml[1024];
|
2011-07-20 20:48:25 +00:00
|
|
|
char name[256], stemp[256];
|
2011-07-20 20:08:05 +00:00
|
|
|
double max_nbytes=-1;
|
2011-07-20 20:48:25 +00:00
|
|
|
char xml_signature[1024];
|
2002-07-05 05:33:40 +00:00
|
|
|
int retval;
|
2011-07-20 20:08:05 +00:00
|
|
|
double offset=0, nbytes = -1;
|
2011-07-20 20:48:25 +00:00
|
|
|
bool is_valid, btemp;
|
2002-11-09 20:26:50 +00:00
|
|
|
|
2011-07-20 20:08:05 +00:00
|
|
|
strcpy(name, "");
|
|
|
|
strcpy(xml_signature, "");
|
|
|
|
bool found_data = false;
|
2002-07-05 05:33:40 +00:00
|
|
|
while (fgets(buf, 256, in)) {
|
2011-07-20 20:48:25 +00:00
|
|
|
#if 1
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL, "got:%s\n", buf);
|
2004-10-06 20:45:21 +00:00
|
|
|
#endif
|
2011-07-20 20:08:05 +00:00
|
|
|
if (match_tag(buf, "<file_info>")) continue;
|
|
|
|
if (match_tag(buf, "</file_info>")) continue;
|
|
|
|
if (match_tag(buf, "<signed_xml>")) continue;
|
|
|
|
if (match_tag(buf, "</signed_xml>")) continue;
|
2011-07-20 20:48:25 +00:00
|
|
|
if (parse_bool(buf, "generated_locally", btemp)) continue;
|
|
|
|
if (parse_bool(buf, "upload_when_present", btemp)) continue;
|
|
|
|
if (parse_str(buf, "<url>", stemp, sizeof(stemp))) continue;
|
|
|
|
if (parse_str(buf, "<md5_cksum>", stemp, sizeof(stemp))) continue;
|
|
|
|
if (match_tag(buf, "<xml_signature>")) {
|
|
|
|
copy_element_contents(
|
|
|
|
in, "</xml_signature>", xml_signature, sizeof(xml_signature)
|
|
|
|
);
|
2011-07-20 20:08:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (parse_str(buf, "<name>", name, sizeof(name))) {
|
|
|
|
strcpy(this_filename, name);
|
2004-08-04 13:11:21 +00:00
|
|
|
continue;
|
2002-07-05 05:33:40 +00:00
|
|
|
}
|
2011-07-20 20:08:05 +00:00
|
|
|
if (parse_double(buf, "<max_nbytes>", max_nbytes)) continue;
|
2007-06-14 18:02:00 +00:00
|
|
|
if (parse_double(buf, "<offset>", offset)) continue;
|
|
|
|
if (parse_double(buf, "<nbytes>", nbytes)) continue;
|
|
|
|
if (match_tag(buf, "<data>")) {
|
2011-07-20 20:08:05 +00:00
|
|
|
found_data = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
log_messages.printf(MSG_CRITICAL, "unrecognized: %s", buf);
|
|
|
|
}
|
2011-07-20 20:48:25 +00:00
|
|
|
if (strlen(name) == 0) {
|
|
|
|
return return_error(ERR_PERMANENT, "Missing name");
|
|
|
|
}
|
2011-07-20 20:08:05 +00:00
|
|
|
if (!found_data) {
|
|
|
|
return return_error(ERR_PERMANENT, "Missing <data> tag");
|
|
|
|
}
|
|
|
|
if (!config.ignore_upload_certificates) {
|
|
|
|
if (strlen(xml_signature) == 0) {
|
2011-07-20 20:48:25 +00:00
|
|
|
return return_error(ERR_PERMANENT, "missing signature");
|
|
|
|
}
|
|
|
|
if (max_nbytes < 0) {
|
|
|
|
return return_error(ERR_PERMANENT, "missing max_nbytes");
|
|
|
|
}
|
|
|
|
sprintf(signed_xml,
|
|
|
|
"<name>%s</name><max_nbytes>%.0f</max_nbytes>",
|
|
|
|
name, max_nbytes
|
|
|
|
);
|
2012-02-09 20:34:29 +00:00
|
|
|
retval = check_string_signature(
|
2011-07-20 20:48:25 +00:00
|
|
|
signed_xml, xml_signature, key, is_valid
|
|
|
|
);
|
|
|
|
if (retval || !is_valid) {
|
2011-07-20 20:08:05 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2012-02-09 20:34:29 +00:00
|
|
|
"check_string_signature() [%s] [%s] retval %d, is_valid = %d\n",
|
2011-07-20 20:48:25 +00:00
|
|
|
signed_xml, xml_signature,
|
|
|
|
retval, is_valid
|
2004-08-06 11:42:41 +00:00
|
|
|
);
|
2012-12-24 20:14:22 +00:00
|
|
|
log_messages.printf(MSG_NORMAL, "signed xml: %s\n", signed_xml);
|
|
|
|
log_messages.printf(MSG_NORMAL, "signature: %s\n", xml_signature);
|
2011-07-20 20:48:25 +00:00
|
|
|
return return_error(ERR_PERMANENT, "invalid signature");
|
2011-07-20 20:08:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nbytes < 0) {
|
|
|
|
return return_error(ERR_PERMANENT, "nbytes missing or negative");
|
|
|
|
}
|
|
|
|
|
|
|
|
// enforce limits in signed XML
|
|
|
|
//
|
|
|
|
if (!config.ignore_upload_certificates) {
|
|
|
|
if (nbytes > max_nbytes) {
|
|
|
|
sprintf(buf,
|
|
|
|
"file size (%d KB) exceeds limit (%d KB)",
|
|
|
|
(int)(nbytes/1024), (int)(max_nbytes/1024)
|
2004-06-16 20:18:57 +00:00
|
|
|
);
|
2011-07-20 20:08:05 +00:00
|
|
|
copy_socket_to_null(in);
|
|
|
|
return return_error(ERR_PERMANENT, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure filename is legit
|
|
|
|
//
|
|
|
|
if (strstr(name, "..")) {
|
|
|
|
return return_error(ERR_PERMANENT,
|
|
|
|
"file_upload_handler: .. found in filename: %s",
|
|
|
|
name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(name) == 0) {
|
|
|
|
return return_error(ERR_PERMANENT,
|
|
|
|
"file_upload_handler: no filename; nbytes %f", nbytes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = dir_hier_path(
|
|
|
|
name, config.upload_dir, config.uldl_dir_fanout,
|
|
|
|
path, true
|
|
|
|
);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(MSG_CRITICAL,
|
|
|
|
"Failed to find/create directory for file '%s' in '%s'\n",
|
|
|
|
name, config.upload_dir
|
|
|
|
);
|
|
|
|
return return_error(ERR_TRANSIENT, "can't open file");
|
|
|
|
}
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"Starting upload of %s from %s [offset=%.0f, nbytes=%.0f]\n",
|
|
|
|
name,
|
|
|
|
get_remote_addr(),
|
|
|
|
offset, nbytes
|
|
|
|
);
|
2005-12-14 22:48:05 +00:00
|
|
|
#ifndef _USING_FCGI_
|
2011-07-20 20:08:05 +00:00
|
|
|
fflush(stderr);
|
2005-12-14 22:48:05 +00:00
|
|
|
#endif
|
2011-07-20 20:08:05 +00:00
|
|
|
if (offset >= nbytes) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2011-07-20 20:08:05 +00:00
|
|
|
"ERROR: offset >= nbytes!!\n"
|
2007-06-14 18:02:00 +00:00
|
|
|
);
|
2011-07-20 20:08:05 +00:00
|
|
|
return return_success(0);
|
2002-07-05 05:33:40 +00:00
|
|
|
}
|
2011-07-20 20:08:05 +00:00
|
|
|
retval = copy_socket_to_file(in, path, offset, nbytes);
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"Ended upload of %s from %s; retval %d\n",
|
|
|
|
name,
|
|
|
|
get_remote_addr(),
|
|
|
|
retval
|
|
|
|
);
|
|
|
|
#ifndef _USING_FCGI_
|
|
|
|
fflush(stderr);
|
|
|
|
#endif
|
|
|
|
return retval;
|
2002-07-05 05:33:40 +00:00
|
|
|
}
|
|
|
|
|
2007-09-12 08:25:22 +00:00
|
|
|
bool volume_full(char* path) {
|
|
|
|
double total, avail;
|
|
|
|
int retval = get_filesystem_info(total, avail, path);
|
|
|
|
if (retval) return false;
|
2007-09-27 15:08:40 +00:00
|
|
|
if (avail<1e6) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-09-12 08:25:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-01-22 01:35:09 +00:00
|
|
|
// always returns HTML reply
|
|
|
|
//
|
2002-12-02 04:29:40 +00:00
|
|
|
int handle_get_file_size(char* file_name) {
|
|
|
|
struct stat sbuf;
|
2012-05-09 16:11:50 +00:00
|
|
|
char path[MAXPATHLEN], buf[256];
|
2005-04-19 14:30:07 +00:00
|
|
|
int retval, pid, fd;
|
2002-12-02 04:29:40 +00:00
|
|
|
|
|
|
|
// TODO: check to ensure path doesn't point somewhere bad
|
|
|
|
// Use 64-bit variant
|
|
|
|
//
|
2006-01-11 22:08:39 +00:00
|
|
|
retval = dir_hier_path(
|
|
|
|
file_name, config.upload_dir, config.uldl_dir_fanout, path
|
|
|
|
);
|
|
|
|
if (retval) {
|
2009-03-25 16:52:26 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2006-01-11 22:08:39 +00:00
|
|
|
"Failed to find/create directory for file '%s' in '%s'.\n",
|
|
|
|
file_name, config.upload_dir
|
|
|
|
);
|
|
|
|
return return_error(ERR_TRANSIENT, "can't open file");
|
2005-09-30 12:54:12 +00:00
|
|
|
}
|
|
|
|
|
2007-09-12 08:25:22 +00:00
|
|
|
// if the volume is full, report a transient error
|
|
|
|
// to prevent the client from starting a transfer
|
|
|
|
//
|
2007-09-27 15:08:40 +00:00
|
|
|
if (volume_full(config.upload_dir)) {
|
2007-10-04 17:30:28 +00:00
|
|
|
return return_error(ERR_TRANSIENT, "Server is out of disk space");
|
2007-09-12 08:25:22 +00:00
|
|
|
}
|
|
|
|
|
2006-01-11 22:08:39 +00:00
|
|
|
fd = open(path, O_WRONLY|O_APPEND);
|
2005-04-19 14:30:07 +00:00
|
|
|
|
|
|
|
if (fd<0 && ENOENT==errno) {
|
2005-04-14 18:01:54 +00:00
|
|
|
// file does not exist: return zero length
|
|
|
|
//
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2005-09-26 23:28:48 +00:00
|
|
|
"handle_get_file_size(): [%s] returning zero\n", file_name
|
|
|
|
);
|
2002-12-02 04:29:40 +00:00
|
|
|
return return_success("<file_size>0</file_size>");
|
2005-04-19 14:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fd<0) {
|
|
|
|
// can't get file descriptor: try again later
|
2005-04-14 18:01:54 +00:00
|
|
|
//
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2005-09-30 12:54:12 +00:00
|
|
|
"handle_get_file_size(): cannot open [%s] %s\n",
|
2005-09-26 23:28:48 +00:00
|
|
|
file_name, strerror(errno)
|
|
|
|
);
|
2005-04-19 14:30:07 +00:00
|
|
|
return return_error(ERR_TRANSIENT, "can't open file");
|
|
|
|
}
|
|
|
|
|
2012-12-24 20:14:22 +00:00
|
|
|
if ((pid = mylockf(fd))) {
|
2005-04-14 18:01:54 +00:00
|
|
|
// file locked by another file_upload_handler: try again later
|
|
|
|
//
|
2005-04-19 14:30:07 +00:00
|
|
|
close(fd);
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2005-09-26 23:28:48 +00:00
|
|
|
"handle_get_file_size(): [%s] returning error\n", file_name
|
|
|
|
);
|
2006-01-11 22:08:39 +00:00
|
|
|
return return_error(ERR_TRANSIENT,
|
|
|
|
"[%s] locked by file_upload_handler PID=%d", file_name, pid
|
|
|
|
);
|
2009-03-25 16:52:26 +00:00
|
|
|
}
|
2005-04-19 14:30:07 +00:00
|
|
|
// file exists, writable, not locked by anyone else, so return length.
|
|
|
|
//
|
|
|
|
retval = stat(path, &sbuf);
|
|
|
|
close(fd);
|
|
|
|
if (retval) {
|
|
|
|
// file DOES perhaps exist, but can't stat it: try again later
|
2005-04-14 18:01:54 +00:00
|
|
|
//
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2005-09-26 23:28:48 +00:00
|
|
|
"handle_get_file_size(): [%s] returning error %s\n",
|
|
|
|
file_name, strerror(errno)
|
|
|
|
);
|
2005-04-19 14:30:07 +00:00
|
|
|
return return_error(ERR_TRANSIENT, "cannot stat file" );
|
2002-12-02 04:29:40 +00:00
|
|
|
}
|
2005-04-19 14:30:07 +00:00
|
|
|
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2005-09-26 23:28:48 +00:00
|
|
|
"handle_get_file_size(): [%s] returning %d\n",
|
2005-04-19 14:30:07 +00:00
|
|
|
file_name, (int)sbuf.st_size
|
|
|
|
);
|
|
|
|
sprintf(buf, "<file_size>%d</file_size>", (int)sbuf.st_size);
|
|
|
|
return return_success(buf);
|
2002-12-02 04:29:40 +00:00
|
|
|
}
|
|
|
|
|
2004-01-22 01:35:09 +00:00
|
|
|
// always generates an HTML reply
|
|
|
|
//
|
2002-12-02 04:29:40 +00:00
|
|
|
int handle_request(FILE* in, R_RSA_PUBLIC_KEY& key) {
|
|
|
|
char buf[256];
|
|
|
|
char file_name[256];
|
2005-10-04 18:30:49 +00:00
|
|
|
int major, minor, release, retval=0;
|
2005-12-13 08:04:57 +00:00
|
|
|
bool got_version = true;
|
2004-01-22 01:35:09 +00:00
|
|
|
bool did_something = false;
|
2009-01-12 23:05:49 +00:00
|
|
|
double start_time = dtime();
|
2002-12-02 04:29:40 +00:00
|
|
|
|
2008-02-05 20:16:57 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
log_messages.set_indent_level(1);
|
|
|
|
#endif
|
2002-12-02 04:29:40 +00:00
|
|
|
while (fgets(buf, 256, in)) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_DEBUG, "handle_request: %s", buf);
|
2002-12-02 04:29:40 +00:00
|
|
|
if (parse_int(buf, "<core_client_major_version>", major)) {
|
2005-12-13 08:04:57 +00:00
|
|
|
continue;
|
2004-01-22 01:35:09 +00:00
|
|
|
} else if (parse_int(buf, "<core_client_minor_version>", minor)) {
|
|
|
|
continue;
|
2005-10-04 18:30:49 +00:00
|
|
|
} else if (parse_int(buf, "<core_client_release>", release)) {
|
|
|
|
continue;
|
2002-12-02 04:29:40 +00:00
|
|
|
} else if (match_tag(buf, "<file_upload>")) {
|
2005-12-14 22:48:05 +00:00
|
|
|
|
2002-12-02 04:29:40 +00:00
|
|
|
if (!got_version) {
|
2004-01-22 01:35:09 +00:00
|
|
|
retval = return_error(ERR_PERMANENT, "Missing version");
|
2002-12-02 04:29:40 +00:00
|
|
|
} else {
|
2004-01-22 01:35:09 +00:00
|
|
|
retval = handle_file_upload(in, key);
|
2002-12-02 04:29:40 +00:00
|
|
|
}
|
2004-01-22 01:35:09 +00:00
|
|
|
did_something = true;
|
|
|
|
break;
|
2002-12-02 04:29:40 +00:00
|
|
|
} else if (parse_str(buf, "<get_file_size>", file_name, sizeof(file_name))) {
|
2005-10-28 14:32:40 +00:00
|
|
|
if (strstr(file_name, "..")) {
|
2006-01-11 22:08:39 +00:00
|
|
|
return return_error(ERR_PERMANENT, "Bad filename");
|
|
|
|
}
|
2002-12-02 04:29:40 +00:00
|
|
|
if (!got_version) {
|
2004-01-22 01:35:09 +00:00
|
|
|
retval = return_error(ERR_PERMANENT, "Missing version");
|
2002-12-02 04:29:40 +00:00
|
|
|
} else {
|
2004-01-22 01:35:09 +00:00
|
|
|
retval = handle_get_file_size(file_name);
|
2002-12-02 04:29:40 +00:00
|
|
|
}
|
2004-01-22 01:35:09 +00:00
|
|
|
did_something = true;
|
|
|
|
break;
|
2005-04-14 18:01:54 +00:00
|
|
|
} else if (match_tag(buf, "<data_server_request>")) {
|
|
|
|
// DO NOTHING
|
2004-01-22 01:35:09 +00:00
|
|
|
} else {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_DEBUG, "handle_request: unrecognized %s\n", buf);
|
2002-12-02 04:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
2004-01-22 01:35:09 +00:00
|
|
|
if (!did_something) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL, "handle_request: no command\n");
|
2008-02-21 00:47:50 +00:00
|
|
|
return return_error(ERR_TRANSIENT, "no command");
|
2004-01-22 01:35:09 +00:00
|
|
|
}
|
|
|
|
|
2009-01-12 23:05:49 +00:00
|
|
|
log_messages.printf(MSG_DEBUG, "elapsed time %f seconds\n", dtime()-start_time);
|
2005-05-04 16:31:25 +00:00
|
|
|
|
2004-01-22 01:35:09 +00:00
|
|
|
return retval;
|
2002-12-02 04:29:40 +00:00
|
|
|
}
|
|
|
|
|
2002-07-05 05:33:40 +00:00
|
|
|
int get_key(R_RSA_PUBLIC_KEY& key) {
|
|
|
|
int retval;
|
2002-07-12 18:27:29 +00:00
|
|
|
char buf[256];
|
2002-10-03 18:33:46 +00:00
|
|
|
sprintf(buf, "%s/upload_public", config.key_dir);
|
2008-09-09 19:10:42 +00:00
|
|
|
#ifndef _USING_FCGI_
|
|
|
|
FILE *f = fopen(buf, "r");
|
|
|
|
#else
|
|
|
|
FCGI_FILE *f = FCGI::fopen(buf, "r");
|
|
|
|
#endif
|
2002-07-05 05:33:40 +00:00
|
|
|
if (!f) return -1;
|
2009-07-27 20:54:15 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
retval = scan_key_hex(FCGI_ToFILE(f), (KEY*)&key, sizeof(key));
|
|
|
|
#else
|
2002-07-05 05:33:40 +00:00
|
|
|
retval = scan_key_hex(f, (KEY*)&key, sizeof(key));
|
2009-07-27 20:54:15 +00:00
|
|
|
#endif
|
2002-07-05 05:33:40 +00:00
|
|
|
fclose(f);
|
|
|
|
if (retval) return retval;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-11 09:00:50 +00:00
|
|
|
void boinc_catch_signal(int signal_num) {
|
2006-01-12 15:36:46 +00:00
|
|
|
char buffer[512]="";
|
2007-06-14 18:02:00 +00:00
|
|
|
if (this_filename[0]) {
|
|
|
|
sprintf(buffer, "FILE=%s (%.0f bytes left) ", this_filename, bytes_left);
|
|
|
|
}
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2009-01-12 23:05:49 +00:00
|
|
|
"%sIP=%s caught signal %d [%s]\n",
|
2006-01-12 15:36:46 +00:00
|
|
|
buffer, get_remote_addr(),
|
2009-01-12 23:05:49 +00:00
|
|
|
signal_num, strsignal(signal_num)
|
2005-04-11 09:00:50 +00:00
|
|
|
);
|
2005-04-19 14:30:07 +00:00
|
|
|
|
2007-06-14 18:02:00 +00:00
|
|
|
// there is no point in trying to return an error.
|
|
|
|
// At this point Apache has broken the connection
|
|
|
|
// so a write to stdout will just generate a SIGPIPE
|
2005-04-19 14:30:07 +00:00
|
|
|
//
|
|
|
|
// return_error(ERR_TRANSIENT, "while downloading %s server caught signal %d", this_filename, signal_num);
|
2009-06-02 23:26:12 +00:00
|
|
|
_exit(1);
|
2004-01-22 01:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void installer() {
|
|
|
|
signal(SIGHUP, boinc_catch_signal); // terminal line hangup
|
|
|
|
signal(SIGINT, boinc_catch_signal); // interrupt program
|
2005-04-11 09:00:50 +00:00
|
|
|
signal(SIGQUIT, boinc_catch_signal); // quit program
|
2004-01-22 01:35:09 +00:00
|
|
|
signal(SIGILL, boinc_catch_signal); // illegal instruction
|
2005-04-11 09:00:50 +00:00
|
|
|
signal(SIGTRAP, boinc_catch_signal); // illegal instruction
|
2004-01-22 01:35:09 +00:00
|
|
|
signal(SIGABRT, boinc_catch_signal); // abort(2) call
|
|
|
|
signal(SIGFPE, boinc_catch_signal); // bus error
|
2005-04-11 09:00:50 +00:00
|
|
|
signal(SIGKILL, boinc_catch_signal); // bus error
|
2004-01-22 01:35:09 +00:00
|
|
|
signal(SIGBUS, boinc_catch_signal); // bus error
|
|
|
|
signal(SIGSEGV, boinc_catch_signal); // segmentation violation
|
|
|
|
signal(SIGSYS, boinc_catch_signal); // system call given invalid argument
|
|
|
|
signal(SIGPIPE, boinc_catch_signal); // write on a pipe with no reader
|
2005-04-11 09:00:50 +00:00
|
|
|
signal(SIGTERM, boinc_catch_signal); // terminate process
|
2004-01-22 01:35:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 17:56:59 +00:00
|
|
|
void usage(char *name) {
|
|
|
|
fprintf(stderr,
|
- server: change the following from per-host to per-(host, app version):
- daily quota mechanism
- reliable mechanism (accelerated retries)
- "trusted" mechanism (adaptive replication)
- scheduler: enforce host scale probation only for apps with
host_scale_check set.
- validator: do scale probation on invalid results
(need this in addition to error and timeout cases)
- feeder: update app version scales every 10 min, not 10 sec
- back-end apps: support --foo as well as -foo for options
Notes:
- If you have, say, cuda, cuda23 and cuda_fermi plan classes,
a host will have separate quotas for each one.
That means it could error out on 100 jobs for cuda_fermi,
and when its quota goes to zero,
error out on 100 jobs for cuda23, etc.
This is intentional; there may be cases where one version
works but not the others.
- host.error_rate and host.max_results_day are deprecated
TODO:
- the values in the app table for limits on jobs in progress etc.
should override rather than config.xml.
Implementation notes:
scheduler:
process_request():
read all host_app_versions for host at start;
Compute "reliable" and "trusted" for each one.
write modified records at end
get_app_version():
add "reliable_only" arg; if set, use only reliable versions
skip over-quota versions
Multi-pass scheduling: if have at least one reliable version,
do a pass for jobs that need reliable,
and use only reliable versions.
Then clear best_app_versions cache.
Score-based scheduling: for need-reliable jobs,
it will pick the fastest version,
then give a score bonus if that version happens to be reliable.
When get back a successful result from client:
increase daily quota
When get back an error result from client:
impose scale probation
decrease daily quota if not aborted
Validator:
when handling a WU, create a vector of HOST_APP_VERSION
parallel to vector of RESULT.
Pass it to assign_credit_set().
Make copies of originals so we can update only modified ones
update HOST_APP_VERSION error rates
Transitioner:
decrease quota on timeout
svn path=/trunk/boinc/; revision=21181
2010-04-15 03:13:56 +00:00
|
|
|
"This is the BOINC file upload handler.\n"
|
2009-09-17 17:56:59 +00:00
|
|
|
"It receives the results from the clients\n"
|
|
|
|
"and puts them on the file server.\n\n"
|
- server: change the following from per-host to per-(host, app version):
- daily quota mechanism
- reliable mechanism (accelerated retries)
- "trusted" mechanism (adaptive replication)
- scheduler: enforce host scale probation only for apps with
host_scale_check set.
- validator: do scale probation on invalid results
(need this in addition to error and timeout cases)
- feeder: update app version scales every 10 min, not 10 sec
- back-end apps: support --foo as well as -foo for options
Notes:
- If you have, say, cuda, cuda23 and cuda_fermi plan classes,
a host will have separate quotas for each one.
That means it could error out on 100 jobs for cuda_fermi,
and when its quota goes to zero,
error out on 100 jobs for cuda23, etc.
This is intentional; there may be cases where one version
works but not the others.
- host.error_rate and host.max_results_day are deprecated
TODO:
- the values in the app table for limits on jobs in progress etc.
should override rather than config.xml.
Implementation notes:
scheduler:
process_request():
read all host_app_versions for host at start;
Compute "reliable" and "trusted" for each one.
write modified records at end
get_app_version():
add "reliable_only" arg; if set, use only reliable versions
skip over-quota versions
Multi-pass scheduling: if have at least one reliable version,
do a pass for jobs that need reliable,
and use only reliable versions.
Then clear best_app_versions cache.
Score-based scheduling: for need-reliable jobs,
it will pick the fastest version,
then give a score bonus if that version happens to be reliable.
When get back a successful result from client:
increase daily quota
When get back an error result from client:
impose scale probation
decrease daily quota if not aborted
Validator:
when handling a WU, create a vector of HOST_APP_VERSION
parallel to vector of RESULT.
Pass it to assign_credit_set().
Make copies of originals so we can update only modified ones
update HOST_APP_VERSION error rates
Transitioner:
decrease quota on timeout
svn path=/trunk/boinc/; revision=21181
2010-04-15 03:13:56 +00:00
|
|
|
"Normally this is run as a CGI program.\n\n"
|
2009-09-17 17:56:59 +00:00
|
|
|
"Usage: %s [OPTION]...\n\n"
|
|
|
|
"Options:\n"
|
- server: change the following from per-host to per-(host, app version):
- daily quota mechanism
- reliable mechanism (accelerated retries)
- "trusted" mechanism (adaptive replication)
- scheduler: enforce host scale probation only for apps with
host_scale_check set.
- validator: do scale probation on invalid results
(need this in addition to error and timeout cases)
- feeder: update app version scales every 10 min, not 10 sec
- back-end apps: support --foo as well as -foo for options
Notes:
- If you have, say, cuda, cuda23 and cuda_fermi plan classes,
a host will have separate quotas for each one.
That means it could error out on 100 jobs for cuda_fermi,
and when its quota goes to zero,
error out on 100 jobs for cuda23, etc.
This is intentional; there may be cases where one version
works but not the others.
- host.error_rate and host.max_results_day are deprecated
TODO:
- the values in the app table for limits on jobs in progress etc.
should override rather than config.xml.
Implementation notes:
scheduler:
process_request():
read all host_app_versions for host at start;
Compute "reliable" and "trusted" for each one.
write modified records at end
get_app_version():
add "reliable_only" arg; if set, use only reliable versions
skip over-quota versions
Multi-pass scheduling: if have at least one reliable version,
do a pass for jobs that need reliable,
and use only reliable versions.
Then clear best_app_versions cache.
Score-based scheduling: for need-reliable jobs,
it will pick the fastest version,
then give a score bonus if that version happens to be reliable.
When get back a successful result from client:
increase daily quota
When get back an error result from client:
impose scale probation
decrease daily quota if not aborted
Validator:
when handling a WU, create a vector of HOST_APP_VERSION
parallel to vector of RESULT.
Pass it to assign_credit_set().
Make copies of originals so we can update only modified ones
update HOST_APP_VERSION error rates
Transitioner:
decrease quota on timeout
svn path=/trunk/boinc/; revision=21181
2010-04-15 03:13:56 +00:00
|
|
|
" [ -h | --help ] Show this help text.\n"
|
|
|
|
" [ -v | --version ] Show version information.\n",
|
2009-09-17 17:56:59 +00:00
|
|
|
name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2002-07-05 05:33:40 +00:00
|
|
|
int retval;
|
|
|
|
R_RSA_PUBLIC_KEY key;
|
2012-05-09 16:11:50 +00:00
|
|
|
char log_path[MAXPATHLEN];
|
2007-06-20 22:34:06 +00:00
|
|
|
#ifdef _USING_FCGI_
|
2007-05-23 20:42:45 +00:00
|
|
|
unsigned int counter=0;
|
2007-06-20 22:34:06 +00:00
|
|
|
#endif
|
2003-12-15 02:31:29 +00:00
|
|
|
|
2009-09-17 17:56:59 +00:00
|
|
|
for(int c = 1; c < argc; c++) {
|
2012-12-24 20:14:22 +00:00
|
|
|
string option(argv[c]);
|
- server: change the following from per-host to per-(host, app version):
- daily quota mechanism
- reliable mechanism (accelerated retries)
- "trusted" mechanism (adaptive replication)
- scheduler: enforce host scale probation only for apps with
host_scale_check set.
- validator: do scale probation on invalid results
(need this in addition to error and timeout cases)
- feeder: update app version scales every 10 min, not 10 sec
- back-end apps: support --foo as well as -foo for options
Notes:
- If you have, say, cuda, cuda23 and cuda_fermi plan classes,
a host will have separate quotas for each one.
That means it could error out on 100 jobs for cuda_fermi,
and when its quota goes to zero,
error out on 100 jobs for cuda23, etc.
This is intentional; there may be cases where one version
works but not the others.
- host.error_rate and host.max_results_day are deprecated
TODO:
- the values in the app table for limits on jobs in progress etc.
should override rather than config.xml.
Implementation notes:
scheduler:
process_request():
read all host_app_versions for host at start;
Compute "reliable" and "trusted" for each one.
write modified records at end
get_app_version():
add "reliable_only" arg; if set, use only reliable versions
skip over-quota versions
Multi-pass scheduling: if have at least one reliable version,
do a pass for jobs that need reliable,
and use only reliable versions.
Then clear best_app_versions cache.
Score-based scheduling: for need-reliable jobs,
it will pick the fastest version,
then give a score bonus if that version happens to be reliable.
When get back a successful result from client:
increase daily quota
When get back an error result from client:
impose scale probation
decrease daily quota if not aborted
Validator:
when handling a WU, create a vector of HOST_APP_VERSION
parallel to vector of RESULT.
Pass it to assign_credit_set().
Make copies of originals so we can update only modified ones
update HOST_APP_VERSION error rates
Transitioner:
decrease quota on timeout
svn path=/trunk/boinc/; revision=21181
2010-04-15 03:13:56 +00:00
|
|
|
if(option == "-v" || option == "--version") {
|
2009-09-17 17:56:59 +00:00
|
|
|
printf("%s\n", SVN_VERSION);
|
|
|
|
exit(0);
|
- server: change the following from per-host to per-(host, app version):
- daily quota mechanism
- reliable mechanism (accelerated retries)
- "trusted" mechanism (adaptive replication)
- scheduler: enforce host scale probation only for apps with
host_scale_check set.
- validator: do scale probation on invalid results
(need this in addition to error and timeout cases)
- feeder: update app version scales every 10 min, not 10 sec
- back-end apps: support --foo as well as -foo for options
Notes:
- If you have, say, cuda, cuda23 and cuda_fermi plan classes,
a host will have separate quotas for each one.
That means it could error out on 100 jobs for cuda_fermi,
and when its quota goes to zero,
error out on 100 jobs for cuda23, etc.
This is intentional; there may be cases where one version
works but not the others.
- host.error_rate and host.max_results_day are deprecated
TODO:
- the values in the app table for limits on jobs in progress etc.
should override rather than config.xml.
Implementation notes:
scheduler:
process_request():
read all host_app_versions for host at start;
Compute "reliable" and "trusted" for each one.
write modified records at end
get_app_version():
add "reliable_only" arg; if set, use only reliable versions
skip over-quota versions
Multi-pass scheduling: if have at least one reliable version,
do a pass for jobs that need reliable,
and use only reliable versions.
Then clear best_app_versions cache.
Score-based scheduling: for need-reliable jobs,
it will pick the fastest version,
then give a score bonus if that version happens to be reliable.
When get back a successful result from client:
increase daily quota
When get back an error result from client:
impose scale probation
decrease daily quota if not aborted
Validator:
when handling a WU, create a vector of HOST_APP_VERSION
parallel to vector of RESULT.
Pass it to assign_credit_set().
Make copies of originals so we can update only modified ones
update HOST_APP_VERSION error rates
Transitioner:
decrease quota on timeout
svn path=/trunk/boinc/; revision=21181
2010-04-15 03:13:56 +00:00
|
|
|
} else if(option == "-h" || option == "--help") {
|
2009-09-17 17:56:59 +00:00
|
|
|
usage(argv[0]);
|
|
|
|
exit(0);
|
2009-10-12 16:44:26 +00:00
|
|
|
} else if (option.length()){
|
2009-09-17 17:56:59 +00:00
|
|
|
fprintf(stderr, "unknown command line argument: %s\n\n", argv[c]);
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-11 09:00:50 +00:00
|
|
|
installer();
|
|
|
|
|
2004-12-06 22:41:19 +00:00
|
|
|
get_log_path(log_path, "file_upload_handler.log");
|
2008-02-05 20:16:57 +00:00
|
|
|
#ifndef _USING_FCGI_
|
2003-12-15 02:31:29 +00:00
|
|
|
if (!freopen(log_path, "a", stderr)) {
|
2009-03-25 16:52:26 +00:00
|
|
|
fprintf(stderr, "Can't open log file '%s' (errno: %d)\n",
|
|
|
|
log_path, errno
|
|
|
|
);
|
|
|
|
return_error(ERR_TRANSIENT, "can't open log file '%s' (errno: %d)",
|
|
|
|
log_path, errno
|
|
|
|
);
|
2003-04-03 18:35:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2008-02-05 20:16:57 +00:00
|
|
|
#else
|
2008-09-09 19:10:42 +00:00
|
|
|
FCGI_FILE *f = FCGI::fopen(log_path, "a");
|
2008-02-05 20:16:57 +00:00
|
|
|
if (f) {
|
|
|
|
log_messages.redirect(f);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Can't redirect FCGI log messages\n");
|
|
|
|
return_error(ERR_TRANSIENT, "can't open log file (FCGI)");
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-12-14 22:48:05 +00:00
|
|
|
#endif
|
2003-04-03 18:35:40 +00:00
|
|
|
|
2009-05-07 13:54:51 +00:00
|
|
|
retval = config.parse_file();
|
2006-06-07 04:10:04 +00:00
|
|
|
if (retval) {
|
2009-05-07 13:54:51 +00:00
|
|
|
fprintf(stderr, "Can't parse config.xml: %s\n", boincerror(retval));
|
2009-03-25 16:52:26 +00:00
|
|
|
return_error(ERR_TRANSIENT,
|
|
|
|
"can't parse config file", log_path, errno
|
|
|
|
);
|
2006-06-07 04:10:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-04-18 05:37:31 +00:00
|
|
|
log_messages.pid = getpid();
|
2006-06-07 04:10:04 +00:00
|
|
|
log_messages.set_debug_level(config.fuh_debug_level);
|
2003-06-14 20:15:44 +00:00
|
|
|
|
2012-12-24 20:14:22 +00:00
|
|
|
#ifndef _USING_FCGI_
|
2009-05-07 13:54:51 +00:00
|
|
|
if (boinc_file_exists(config.project_path("stop_upload"))) {
|
2012-12-24 20:14:22 +00:00
|
|
|
return_error(ERR_TRANSIENT,
|
|
|
|
"File uploads are temporarily disabled."
|
|
|
|
);
|
2006-05-31 20:39:32 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2012-12-24 20:14:22 +00:00
|
|
|
#endif
|
2006-05-31 20:39:32 +00:00
|
|
|
|
2005-12-13 08:04:57 +00:00
|
|
|
if (!config.ignore_upload_certificates) {
|
|
|
|
retval = get_key(key);
|
|
|
|
if (retval) {
|
|
|
|
return_error(ERR_TRANSIENT, "can't read key file");
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-07-05 05:33:40 +00:00
|
|
|
}
|
2003-06-14 20:15:47 +00:00
|
|
|
|
2005-12-14 22:48:05 +00:00
|
|
|
#ifdef _USING_FCGI_
|
2009-07-17 16:13:51 +00:00
|
|
|
while(FCGI_Accept() >= 0) {
|
|
|
|
counter++;
|
|
|
|
//fprintf(stderr, "file_upload_handler (FCGI): counter: %d\n", counter);
|
2012-12-24 20:14:22 +00:00
|
|
|
if (boinc_file_exists(config.project_path("stop_upload"))) {
|
|
|
|
return_error(ERR_TRANSIENT,
|
|
|
|
"File uploads are temporarily disabled."
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
2009-07-17 16:13:51 +00:00
|
|
|
log_messages.set_indent_level(0);
|
2005-12-14 22:48:05 +00:00
|
|
|
#endif
|
2009-07-17 16:13:51 +00:00
|
|
|
handle_request(stdin, key);
|
2005-12-14 22:48:05 +00:00
|
|
|
#ifdef _USING_FCGI_
|
2009-07-17 16:13:51 +00:00
|
|
|
// flush log for FCGI, otherwise it just buffers a lot
|
|
|
|
log_messages.flush();
|
|
|
|
}
|
|
|
|
// when exiting, write headers back to apache so it won't complain
|
|
|
|
// about "incomplete headers"
|
|
|
|
fprintf(stdout,"Content-type: text/plain\n\n");
|
2005-12-14 22:48:05 +00:00
|
|
|
#endif
|
2002-07-05 05:33:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_470a0d4d11 = "$Id$";
|