2003-09-27 23:20:40 +00:00
|
|
|
// The contents of this file are subject to the BOINC 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://boinc.berkeley.edu/license_1.0.txt
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2003-09-27 23:20:40 +00:00
|
|
|
// 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
|
2004-07-13 13:54:09 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2003-09-27 23:20:40 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2004-07-13 13:54:09 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2003-09-27 23:20:40 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2003-10-07 04:47:00 +00:00
|
|
|
// wu_check [-repair]
|
|
|
|
// look for results with missing input files
|
|
|
|
// -repair change them to server_state OVER, outcome COULDNT_SEND
|
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
2003-09-27 23:20:40 +00:00
|
|
|
|
|
|
|
#include "parse.h"
|
2004-08-06 11:42:41 +00:00
|
|
|
#include "util.h"
|
2003-10-21 05:49:00 +00:00
|
|
|
#include "error_numbers.h"
|
2003-09-27 23:20:40 +00:00
|
|
|
#include "boinc_db.h"
|
|
|
|
#include "sched_config.h"
|
|
|
|
|
2003-10-07 04:47:00 +00:00
|
|
|
bool repair = false;
|
|
|
|
|
2003-09-27 23:20:40 +00:00
|
|
|
// wu_checker
|
|
|
|
// See whether input files that should be present, are
|
|
|
|
|
|
|
|
SCHED_CONFIG config;
|
|
|
|
|
|
|
|
// get the path a WU's input file
|
|
|
|
//
|
|
|
|
int get_file_path(WORKUNIT& wu, char* path) {
|
|
|
|
char buf[256];
|
|
|
|
bool flag;
|
|
|
|
flag = parse_str(wu.xml_doc, "<name>", buf, sizeof(buf));
|
2003-10-21 04:06:55 +00:00
|
|
|
if (!flag) return ERR_XML_PARSE;
|
2004-08-06 11:42:41 +00:00
|
|
|
dir_hier_path(buf, config.download_dir, config.uldl_dir_fanout, path);
|
2003-09-27 23:20:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-10 22:55:29 +00:00
|
|
|
int handle_result(DB_RESULT& result) {
|
2003-09-27 23:20:40 +00:00
|
|
|
DB_WORKUNIT wu;
|
|
|
|
int retval;
|
|
|
|
char path[256];
|
2004-10-04 23:59:51 +00:00
|
|
|
char buf[256];
|
2003-09-27 23:20:40 +00:00
|
|
|
FILE* f;
|
|
|
|
|
|
|
|
retval = wu.lookup_id(result.workunitid);
|
|
|
|
if (retval) {
|
|
|
|
printf(
|
|
|
|
"ERROR: can't find WU %d for result %d\n",
|
|
|
|
result.workunitid, result.id
|
|
|
|
);
|
2003-10-10 22:55:29 +00:00
|
|
|
return 1;
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
|
|
|
get_file_path(wu, path);
|
|
|
|
f = fopen(path, "r");
|
|
|
|
if (f) {
|
|
|
|
fclose(f);
|
|
|
|
} else {
|
2003-10-10 22:55:29 +00:00
|
|
|
printf("no file %s for result %d\n",
|
2003-09-27 23:20:40 +00:00
|
|
|
path, result.id
|
|
|
|
);
|
2003-10-07 04:47:00 +00:00
|
|
|
if (repair) {
|
|
|
|
if (result.server_state == RESULT_SERVER_STATE_UNSENT) {
|
|
|
|
result.server_state = RESULT_SERVER_STATE_OVER;
|
|
|
|
result.outcome = RESULT_OUTCOME_COULDNT_SEND;
|
2004-10-04 23:59:51 +00:00
|
|
|
sprintf(
|
|
|
|
buf,"server_state=%d, outcome=%d",
|
|
|
|
result.server_state, result.outcome
|
|
|
|
);
|
|
|
|
retval = result.update_field(buf);
|
|
|
|
if (retval) {
|
|
|
|
printf(
|
|
|
|
"ERROR: can't update result %d\n",
|
|
|
|
result.id
|
|
|
|
);
|
|
|
|
return 1;
|
|
|
|
}
|
2003-10-07 04:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-10 22:55:29 +00:00
|
|
|
return 1;
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
2003-10-10 22:55:29 +00:00
|
|
|
return 0;
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
|
|
|
|
2003-10-07 04:47:00 +00:00
|
|
|
int main(int argc, char** argv) {
|
2003-09-27 23:20:40 +00:00
|
|
|
DB_RESULT result;
|
|
|
|
char clause[256];
|
2003-10-10 22:55:29 +00:00
|
|
|
int retval, n, nerr;
|
2003-10-07 04:47:00 +00:00
|
|
|
|
|
|
|
retval = config.parse_file();
|
|
|
|
if (retval) exit(1);
|
2003-09-27 23:20:40 +00:00
|
|
|
|
2004-01-15 23:53:13 +00:00
|
|
|
retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd);
|
2003-10-10 22:55:29 +00:00
|
|
|
if (retval) {
|
|
|
|
printf("boinc_db.open: %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (argc > 1 && !strcmp(argv[1], "-repair")) repair = true;
|
2003-09-27 23:20:40 +00:00
|
|
|
|
2003-10-10 22:55:29 +00:00
|
|
|
n = nerr = 0;
|
|
|
|
printf("Unsent results:\n");
|
2003-09-27 23:20:40 +00:00
|
|
|
sprintf(clause, "where server_state=%d", RESULT_SERVER_STATE_UNSENT);
|
|
|
|
while (!result.enumerate(clause)) {
|
2003-10-10 22:55:29 +00:00
|
|
|
retval = handle_result(result);
|
|
|
|
n++;
|
|
|
|
if (retval) nerr++;
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
2003-10-10 22:55:29 +00:00
|
|
|
printf("%d out of %d errors\n", nerr, n);
|
|
|
|
n = nerr = 0;
|
|
|
|
printf("In progress results:\n");
|
2003-09-27 23:20:40 +00:00
|
|
|
sprintf(clause, "where server_state=%d", RESULT_SERVER_STATE_IN_PROGRESS);
|
|
|
|
while (!result.enumerate(clause)) {
|
2003-10-10 22:55:29 +00:00
|
|
|
retval = handle_result(result);
|
|
|
|
n++;
|
|
|
|
if (retval) nerr++;
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|
2003-10-10 22:55:29 +00:00
|
|
|
printf("%d out of %d errors\n", nerr, n);
|
2003-09-27 23:20:40 +00:00
|
|
|
}
|