326
332
if (parse_double(buf, "<nbytes>", nbytes)) continue;
327
333
if (parse_str(buf, "<md5_cksum>", temp, sizeof(temp))) continue;
328
334
if (match_tag(buf, "<data>")) {
330
336
return return_error(ERR_PERMANENT, "nbytes missing or negative");
366
log_messages.printf(MSG_CRITICAL,
372
log_messages.printf(MSG_CRITICAL,
367
373
"Failed to find/create directory for file '%s' in '%s'\n",
368
374
file_info.name, config.upload_dir
427
433
file_name, config.upload_dir, config.uldl_dir_fanout, path
430
log_messages.printf(MSG_CRITICAL,
436
log_messages.printf(MSG_CRITICAL,
431
437
"Failed to find/create directory for file '%s' in '%s'.\n",
432
438
file_name, config.upload_dir
472
478
return return_error(ERR_TRANSIENT,
473
479
"[%s] locked by file_upload_handler PID=%d", file_name, pid
476
482
// file exists, writable, not locked by anyone else, so return length.
478
484
retval = stat(path, &sbuf);
503
509
int major, minor, release, retval=0;
504
510
bool got_version = true;
505
511
bool did_something = false;
512
double start_time = dtime();
507
514
#ifdef _USING_FCGI_
508
515
log_messages.set_indent_level(1);
546
553
return return_error(ERR_TRANSIENT, "no command");
549
log_messages.printf(MSG_DEBUG,
550
"elapsed time %f seconds\n", elapsed_wallclock_time()
556
log_messages.printf(MSG_DEBUG, "elapsed time %f seconds\n", dtime()-start_time);
563
568
FCGI_FILE *f = FCGI::fopen(buf, "r");
565
570
if (!f) return -1;
572
retval = scan_key_hex(FCGI_ToFILE(f), (KEY*)&key, sizeof(key));
566
574
retval = scan_key_hex(f, (KEY*)&key, sizeof(key));
568
577
if (retval) return retval;
575
584
sprintf(buffer, "FILE=%s (%.0f bytes left) ", this_filename, bytes_left);
577
586
log_messages.printf(MSG_CRITICAL,
578
"%sIP=%s caught signal %d [%s] elapsed time %f seconds\n",
587
"%sIP=%s caught signal %d [%s]\n",
579
588
buffer, get_remote_addr(),
580
signal_num, strsignal(signal_num), elapsed_wallclock_time()
589
signal_num, strsignal(signal_num)
583
592
// there is no point in trying to return an error.
604
613
signal(SIGTERM, boinc_catch_signal); // terminate process
616
void usage(char *name) {
618
"This is the BOINC file upload handler.\n"
619
"It receives the results from the clients\n"
620
"and puts them on the file server.\n\n"
621
"Normally this is run as a CGI program.\n\n"
622
"Usage: %s [OPTION]...\n\n"
624
" [ -h | --help ] Show this help text.\n"
625
" [ -v | --version ] Show version information.\n",
630
int main(int argc, char *argv[]) {
609
632
R_RSA_PUBLIC_KEY key;
610
633
char log_path[256];
611
634
#ifdef _USING_FCGI_
612
635
unsigned int counter=0;
614
elapsed_wallclock_time();
638
for(int c = 1; c < argc; c++) {
639
std::string option(argv[c]);
640
if(option == "-v" || option == "--version") {
641
printf("%s\n", SVN_VERSION);
643
} else if(option == "-h" || option == "--help") {
646
} else if (option.length()){
647
fprintf(stderr, "unknown command line argument: %s\n\n", argv[c]);
618
655
get_log_path(log_path, "file_upload_handler.log");
619
656
#ifndef _USING_FCGI_
620
657
if (!freopen(log_path, "a", stderr)) {
621
fprintf(stderr, "Can't open log file\n");
622
return_error(ERR_TRANSIENT, "can't open log file");
658
fprintf(stderr, "Can't open log file '%s' (errno: %d)\n",
661
return_error(ERR_TRANSIENT, "can't open log file '%s' (errno: %d)",
636
retval = config.parse_file("..");
677
retval = config.parse_file();
679
fprintf(stderr, "Can't parse config.xml: %s\n", boincerror(retval));
680
return_error(ERR_TRANSIENT,
681
"can't parse config file", log_path, errno
641
686
log_messages.pid = getpid();
642
687
log_messages.set_debug_level(config.fuh_debug_level);
644
if (boinc_file_exists("../stop_upload")) {
689
if (boinc_file_exists(config.project_path("stop_upload"))) {
645
690
return_error(ERR_TRANSIENT, "Maintenance underway: file uploads are temporarily disabled.");
657
702
#ifdef _USING_FCGI_
658
while(FCGI_Accept() >= 0) {
660
//fprintf(stderr, "file_upload_handler (FCGI): counter: %d\n", counter);
661
log_messages.set_indent_level(0);
703
while(FCGI_Accept() >= 0) {
705
//fprintf(stderr, "file_upload_handler (FCGI): counter: %d\n", counter);
706
log_messages.set_indent_level(0);
663
handle_request(stdin, key);
708
handle_request(stdin, key);
664
709
#ifdef _USING_FCGI_
665
// flush log for FCGI, otherwise it just buffers a lot
666
log_messages.flush();
668
// when exiting, write headers back to apache so it won't complain
669
// about "incomplete headers"
670
fprintf(stdout,"Content-type: text/plain\n\n");
710
// flush log for FCGI, otherwise it just buffers a lot
711
log_messages.flush();
713
// when exiting, write headers back to apache so it won't complain
714
// about "incomplete headers"
715
fprintf(stdout,"Content-type: text/plain\n\n");
675
const char *BOINC_RCSID_470a0d4d11 = "$Id: file_upload_handler.cpp 16069 2008-09-26 18:20:24Z davea $";
720
const char *BOINC_RCSID_470a0d4d11 = "$Id: file_upload_handler.cpp 21181 2010-04-15 03:13:56Z davea $";