2003-01-07 08:11:16 +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-12-17 19:00:43 +00:00
|
|
|
#include <string.h>
|
2002-12-17 19:35:38 +00:00
|
|
|
#include <stdlib.h>
|
2002-12-17 19:00:43 +00:00
|
|
|
#include <unistd.h>
|
2003-01-07 08:11:16 +00:00
|
|
|
#include <time.h>
|
2002-12-17 19:00:43 +00:00
|
|
|
|
|
|
|
#include "db.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
CONFIG config;
|
|
|
|
|
2003-01-07 01:02:08 +00:00
|
|
|
void write_log(char* p) {
|
|
|
|
time_t now = time(0);
|
|
|
|
char* timestr = ctime(&now);
|
|
|
|
*(strchr(timestr, '\n')) = 0;
|
|
|
|
fprintf(stderr, "%s: %s", timestr, p);
|
|
|
|
}
|
|
|
|
|
2002-12-17 19:00:43 +00:00
|
|
|
// return nonzero if did anything
|
|
|
|
//
|
2002-12-18 01:34:51 +00:00
|
|
|
bool do_pass(APP app) {
|
2002-12-17 19:00:43 +00:00
|
|
|
WORKUNIT wu;
|
|
|
|
RESULT result;
|
|
|
|
bool did_something = false;
|
|
|
|
int retval;
|
2003-01-07 22:49:42 +00:00
|
|
|
char buf[MAX_BLOB_SIZE];
|
2002-12-17 19:00:43 +00:00
|
|
|
|
2002-12-18 01:34:51 +00:00
|
|
|
wu.appid = app.id;
|
2002-12-17 19:00:43 +00:00
|
|
|
wu.assimilate_state = ASSIMILATE_READY;
|
2002-12-18 01:34:51 +00:00
|
|
|
while (!db_workunit_enum_app_assimilate_state(wu)) {
|
2002-12-17 19:00:43 +00:00
|
|
|
did_something = true;
|
2003-01-07 22:49:42 +00:00
|
|
|
|
2003-01-09 07:24:27 +00:00
|
|
|
sprintf(buf, "Assimilating WU %s, assim state %d\n", wu.name, wu.assimilate_state);
|
2003-01-07 22:49:42 +00:00
|
|
|
write_log(buf);
|
|
|
|
|
2002-12-17 19:00:43 +00:00
|
|
|
switch(wu.main_state) {
|
|
|
|
case WU_MAIN_STATE_INIT:
|
2003-01-07 01:02:08 +00:00
|
|
|
write_log("ERROR; WU shouldn't be in init state\n");
|
2002-12-17 19:00:43 +00:00
|
|
|
break;
|
|
|
|
case WU_MAIN_STATE_DONE:
|
|
|
|
if (!wu.canonical_resultid) {
|
2003-01-07 01:02:08 +00:00
|
|
|
write_log("ERROR: canonical resultid zero\n");
|
2002-12-17 19:00:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
retval = db_result(wu.canonical_resultid, result);
|
|
|
|
if (retval) {
|
2003-01-07 01:02:08 +00:00
|
|
|
write_log("can't get canonical result\n");
|
2002-12-17 19:00:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-01-07 22:49:42 +00:00
|
|
|
sprintf(buf, "canonical result for WU %s:\n%s", wu.name, result.xml_doc_out);
|
|
|
|
write_log(buf);
|
|
|
|
|
2002-12-17 19:00:43 +00:00
|
|
|
result.file_delete_state = FILE_DELETE_READY;
|
|
|
|
db_result_update(result);
|
|
|
|
break;
|
|
|
|
case WU_MAIN_STATE_ERROR:
|
|
|
|
printf("WU %s had an error\n", wu.name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wu.assimilate_state = ASSIMILATE_DONE;
|
|
|
|
db_workunit_update(wu);
|
|
|
|
}
|
|
|
|
return did_something;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
int retval;
|
|
|
|
bool asynch = false, one_pass = false;
|
2002-12-18 01:34:51 +00:00
|
|
|
APP app;
|
2002-12-17 19:00:43 +00:00
|
|
|
int i;
|
2003-01-07 01:02:08 +00:00
|
|
|
char buf[256];
|
2002-12-17 19:00:43 +00:00
|
|
|
|
|
|
|
for (i=1; i<argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "-asynch")) {
|
|
|
|
asynch = true;
|
|
|
|
} else if (!strcmp(argv[i], "-one_pass")) {
|
|
|
|
one_pass = true;
|
2002-12-18 01:34:51 +00:00
|
|
|
} else if (!strcmp(argv[i], "-app")) {
|
|
|
|
strcpy(app.name, argv[++i]);
|
2002-12-17 19:00:43 +00:00
|
|
|
} else {
|
2003-01-07 01:02:08 +00:00
|
|
|
sprintf(buf, "Unrecognized arg: %s\n", argv[i]);
|
|
|
|
write_log(buf);
|
2002-12-17 19:00:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = config.parse_file();
|
|
|
|
if (retval) {
|
2003-01-07 01:02:08 +00:00
|
|
|
write_log("Can't parse config file\n");
|
2002-12-17 19:00:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asynch) {
|
|
|
|
if (fork()) {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-09 07:24:27 +00:00
|
|
|
retval = boinc_db_open(config.db_name, config.db_passwd);
|
2002-12-18 01:34:51 +00:00
|
|
|
if (retval) {
|
2003-01-07 01:02:08 +00:00
|
|
|
write_log("Can't open DB\n");
|
2002-12-18 01:34:51 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
retval = db_app_lookup_name(app);
|
|
|
|
if (retval) {
|
2003-01-07 01:02:08 +00:00
|
|
|
write_log("Can't find app\n");
|
2002-12-18 01:34:51 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2002-12-17 19:00:43 +00:00
|
|
|
if (one_pass) {
|
2002-12-18 01:34:51 +00:00
|
|
|
do_pass(app);
|
2002-12-17 19:00:43 +00:00
|
|
|
} else {
|
|
|
|
while (1) {
|
2002-12-18 01:34:51 +00:00
|
|
|
if (!do_pass(app)) sleep(10);
|
2002-12-17 19:00:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|