2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-06-07 22:59:24 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2002-07-11 01:09:53 +00:00
|
|
|
#include <assert.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "db.h"
|
|
|
|
#include "parse.h"
|
2002-05-24 04:29:10 +00:00
|
|
|
#include "shmem.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "server_types.h"
|
|
|
|
#include "handle_request.h"
|
|
|
|
|
|
|
|
#define REQ_FILE_PREFIX "/tmp/boinc_req_"
|
|
|
|
#define REPLY_FILE_PREFIX "/tmp/boinc_reply_"
|
|
|
|
|
|
|
|
int return_error(char* p) {
|
2002-07-11 01:09:53 +00:00
|
|
|
assert(p!=NULL);
|
2002-04-30 22:22:54 +00:00
|
|
|
fprintf(stderr, "BOINC server: %s\n", p);
|
|
|
|
printf("<error_msg>%s</error_msg>\n", p);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the code below is convoluted because,
|
|
|
|
// instead of going from stdin to stdout directly,
|
|
|
|
// we go via a pair of disk files
|
|
|
|
// (this makes it easy to save the input,
|
|
|
|
// and to know the length of the output).
|
|
|
|
//
|
|
|
|
int main() {
|
|
|
|
FILE* fin, *fout;
|
2002-06-01 20:26:21 +00:00
|
|
|
int i, retval, pid;
|
2002-07-07 20:39:24 +00:00
|
|
|
char req_path[256], reply_path[256], path[256];
|
2002-05-24 04:29:10 +00:00
|
|
|
SCHED_SHMEM* ssp;
|
|
|
|
void* p;
|
2002-07-02 17:51:51 +00:00
|
|
|
unsigned int counter=0;
|
2002-07-07 20:39:24 +00:00
|
|
|
char* code_sign_key;
|
|
|
|
|
|
|
|
sprintf(path, "%s/code_sign_public", BOINC_KEY_DIR);
|
|
|
|
retval = read_file_malloc(path, code_sign_key);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"BOINC scheduler: can't read code sign key file (%s)\n", path
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-07-01 22:41:09 +00:00
|
|
|
|
2002-05-24 04:29:10 +00:00
|
|
|
retval = attach_shmem(BOINC_KEY, &p);
|
|
|
|
if (retval) {
|
2002-07-07 20:39:24 +00:00
|
|
|
fprintf(stderr, "BOINC scheduler: can't attach shmem\n");
|
2002-05-24 04:29:10 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
ssp = (SCHED_SHMEM*)p;
|
|
|
|
retval = ssp->verify();
|
|
|
|
if (retval) {
|
2002-07-07 20:39:24 +00:00
|
|
|
fprintf(stderr, "BOINC scheduler: shmem has wrong struct sizes - recompile\n");
|
2002-05-24 04:29:10 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2002-06-01 20:26:21 +00:00
|
|
|
|
|
|
|
for (i=0; i<10; i++) {
|
|
|
|
if (ssp->ready) break;
|
2002-07-07 20:39:24 +00:00
|
|
|
fprintf(stderr, "BOINC scheduler: waiting for ready flag\n");
|
2002-06-01 20:26:21 +00:00
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
if (!ssp->ready) {
|
2002-07-07 20:39:24 +00:00
|
|
|
fprintf(stderr, "BOINC scheduler: feeder doesn't seem to be running\n");
|
2002-06-01 20:26:21 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2002-06-21 18:31:32 +00:00
|
|
|
//fprintf(stderr, "got ready flag\n");
|
2002-07-02 17:51:51 +00:00
|
|
|
retval = db_open("boinc");
|
|
|
|
if (retval) {
|
2002-07-07 20:39:24 +00:00
|
|
|
exit(return_error("BOINC scheduler: can't open database"));
|
2002-07-02 17:51:51 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
pid = getpid();
|
2002-07-02 17:51:51 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
while(FCGI_Accept() >= 0) {
|
|
|
|
counter++;
|
|
|
|
#endif
|
|
|
|
sprintf(req_path, "%s%d_%u", REQ_FILE_PREFIX, pid, counter);
|
|
|
|
sprintf(reply_path, "%s%d_%u", REPLY_FILE_PREFIX, pid, counter);
|
2002-04-30 22:22:54 +00:00
|
|
|
fprintf(stdout, "Content-type: text/plain\n\n");
|
|
|
|
fout = fopen(req_path, "w");
|
|
|
|
if (!fout) {
|
|
|
|
exit(return_error("can't write request file"));
|
|
|
|
}
|
|
|
|
copy_stream(stdin, fout);
|
|
|
|
fclose(fout);
|
|
|
|
fin = fopen(req_path, "r");
|
|
|
|
if (!fin) {
|
|
|
|
exit(return_error("can't read request file"));
|
|
|
|
}
|
|
|
|
fout = fopen(reply_path, "w");
|
|
|
|
if (!fout) {
|
|
|
|
exit(return_error("can't write reply file"));
|
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
handle_request(fin, fout, *ssp, code_sign_key);
|
2002-04-30 22:22:54 +00:00
|
|
|
fclose(fin);
|
|
|
|
fclose(fout);
|
|
|
|
fin = fopen(reply_path, "r");
|
|
|
|
if (!fin) {
|
|
|
|
exit(return_error("can't read reply file"));
|
|
|
|
}
|
|
|
|
copy_stream(fin, stdout);
|
|
|
|
fclose(fin);
|
|
|
|
unlink(req_path);
|
|
|
|
unlink(reply_path);
|
2002-07-01 22:41:09 +00:00
|
|
|
#ifdef _USING_FCGI_
|
2002-06-07 21:21:55 +00:00
|
|
|
}
|
2002-07-01 22:41:09 +00:00
|
|
|
#endif
|
2002-07-02 17:51:51 +00:00
|
|
|
db_close();
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|