Added debug code and error catching, fixed flaw in timekeeping, removed unused tests.

svn path=/trunk/boinc/; revision=174
This commit is contained in:
Michael Gary 2002-07-11 01:09:53 +00:00
parent 064cbf57bc
commit 35af4511d2
50 changed files with 972 additions and 246 deletions

View File

@ -5,7 +5,8 @@ VPATH = @srcdir@
VERSION = 1
CFLAGS = -g -Wall -I../lib/
CFLAGS = -g -Wall @DEFS@ \
-I@top_srcdir@/lib/
CC = @CC@ $(CFLAGS)

View File

@ -37,8 +37,17 @@
#include <sys/types.h>
#include "parse.h"
#include "api.h"
#include "error_numbers.h"
int MFILE::open(char* path, char* mode) {
if(path==NULL) {
fprintf(stderr, "error: MFILE.open: unexpected NULL pointer path\n");
return ERR_NULL;
}
if(mode==NULL) {
fprintf(stderr, "error: MFILE.open: unexpected NULL pointer mode\n");
return ERR_NULL;
}
buf = 0;
len = 0;
f = fopen(path, mode);
@ -50,7 +59,10 @@ int MFILE::printf(char* format, ...) {
va_list ap;
char buf2[4096];
int n, k;
if(format==NULL) {
fprintf(stderr, "error: MFILE.printf: unexpected NULL pointer format\n");
return ERR_NULL;
}
va_start(ap, format);
k = vsprintf(buf2, format, ap);
va_end(ap);
@ -76,6 +88,10 @@ int MFILE::_putchar(char c) {
}
int MFILE::puts(char* p) {
if(p==NULL) {
fprintf(stderr, "error: MFILE.puts: unexpected NULL pointer p\n");
return ERR_NULL;
}
int n = strlen(p);
buf = (char*)realloc(buf, len+n);
strncpy(buf+len, p, n);
@ -97,6 +113,9 @@ int MFILE::flush() {
}
void write_core_file(FILE* f, APP_IN& ai) {
if(f==NULL) {
fprintf(stderr, "error: write_core_file: unexpected NULL pointer f\n");
}
fprintf(f,
"<graphics_xsize>%d</graphics_xsize>\n"
"<graphics_ysize>%d</graphics_ysize>\n"
@ -117,7 +136,9 @@ void write_core_file(FILE* f, APP_IN& ai) {
void parse_core_file(FILE* f, APP_IN& ai) {
char buf[256];
if(f==NULL) {
fprintf(stderr, "error: parse_core_file: unexpected NULL pointer f\n");
}
while (fgets(buf, 256, f)) {
if (match_tag(buf, "<app_specific_prefs>")) {
strcpy(ai.app_preferences, "");
@ -139,6 +160,9 @@ void parse_core_file(FILE* f, APP_IN& ai) {
}
void write_app_file(FILE* f, APP_OUT& ao) {
if(f==NULL) {
fprintf(stderr, "error: write_app_file: unexpected NULL pointer f\n");
}
fprintf(f,
"<percent_done>%f</percent_done>\n"
"<cpu_time_at_checkpoint>%f</cpu_time_at_checkpoint>\n",
@ -152,6 +176,9 @@ void write_app_file(FILE* f, APP_OUT& ao) {
void parse_app_file(FILE* f, APP_OUT& ao) {
char buf[256];
if(f==NULL) {
fprintf(stderr, "error: parse_app_file: unexpected NULL pointer f\n");
}
while (fgets(buf, 256, f)) {
if (parse_double(buf, "<percent_done>", ao.percent_done)) continue;
else if (parse_double(buf, "<cpu_time_at_checkpoint>",
@ -162,6 +189,12 @@ void parse_app_file(FILE* f, APP_OUT& ao) {
}
void write_init_file(FILE* f, char *file_name, int fdesc, int input_file ) {
if(f==NULL) {
fprintf(stderr, "error: write_init_file: unexpected NULL pointer f\n");
}
if(file_name==NULL) {
fprintf(stderr, "error: write_init_file: unexpected NULL pointer file_name\n");
}
if( input_file ) {
fprintf( f, "<fdesc_dup_infile>%s</fdesc_dup_infile>\n", file_name );
fprintf( f, "<fdesc_dup_innum>%d</fdesc_dup_innum>\n", fdesc );
@ -174,7 +207,9 @@ void write_init_file(FILE* f, char *file_name, int fdesc, int input_file ) {
void parse_init_file(FILE* f) {
char buf[256],filename[256];
int filedesc,fd,retval;
if(f==NULL) {
fprintf(stderr, "error: parse_init_file: unexpected NULL pointer f\n");
}
while (fgets(buf, 256, f)) {
if (parse_str(buf, "<fdesc_dup_infile>", filename)) {
if (fgets(buf, 256, f)) {
@ -247,7 +282,14 @@ int boinc_resolve_link(char *file_name, char *resolved_name)
{
FILE *fp;
char buf[512];
if(file_name==NULL) {
fprintf(stderr, "error: boinc_resolve_link: unexpected NULL pointer file_name\n");
return ERR_NULL;
}
if(resolved_name==NULL) {
fprintf(stderr, "error: boinc_resolve_link: unexpected NULL pointer resolved_name\n");
return ERR_NULL;
}
// Open the file and load the first line
fp = fopen( file_name, "r" );
if (!fp) {
@ -327,16 +369,22 @@ void on_timer(int a) {
int set_timer(double period) {
int retval=0;
if(period<0) {
fprintf(stderr, "error: set_timer: negative period\n");
return ERR_NEG;
}
#if HAVE_SIGNAL_H
#if HAVE_SYS_TIME_H
struct sigaction sa;
sa.sa_handler = on_timer;
sa.sa_flags = 0;
sigaction(SIGVTALRM, &sa, NULL);
#ifdef HAVE_SYS_TIME_H
itimerval value;
value.it_value.tv_sec = (int)period;
value.it_value.tv_usec = ((int)(period*1000000))%1000000;
value.it_interval = value.it_value;
retval = setitimer(ITIMER_VIRTUAL, &value, NULL);
#endif
#endif
return retval;
}

View File

@ -22,6 +22,7 @@
// Shouldn't depend on CLIENT_STATE.
#include "windows_cpp.h"
#include "error_numbers.h"
#ifdef _WIN32
#include <io.h>
@ -73,7 +74,12 @@
void parse_command_line(char* p, char** argv) {
char** pp = argv;
bool space = true;
if(p==NULL) {
fprintf(stderr, "error: parse_command_line: unexpected NULL pointer p\n");
}
if(argv==NULL) {
fprintf(stderr, "error: parse_command_line: unexpected NULL pointer argv\n");
}
while (*p) {
if (isspace(*p)) {
*p = 0;
@ -91,6 +97,9 @@ void parse_command_line(char* p, char** argv) {
static void print_argv(char** argv) {
int i;
if(argv==NULL) {
fprintf(stderr, "error: print_argv: unexpected NULL pointer argv\n");
}
for (i=0; argv[i]; i++) {
fprintf(stderr, "argv[%d]: %s\n", i, argv[i]);
}
@ -104,10 +113,14 @@ ACTIVE_TASK::ACTIVE_TASK() {
exit_status = 0;
signal = 0;
strcpy(dirname, "");
cpu_time = 0;
prev_cpu_time = 0;
}
int ACTIVE_TASK::init(RESULT* rp) {
if(rp==NULL) {
fprintf(stderr, "error: ACTIVE_TASK.init: unexpected NULL pointer rp\n");
return ERR_NULL;
}
result = rp;
wup = rp->wup;
app_version = wup->avp;
@ -125,15 +138,13 @@ int ACTIVE_TASK::start(bool first_time) {
FILE *prefs_fd,*init_file;
APP_IN app_prefs;
if(first_time) prev_cpu_time = 0;
cpu_time = 0;
prev_cpu_time = 0;
// These should be chosen in a better manner
app_prefs.graphics.xsize = 640;
app_prefs.graphics.ysize = 480;
app_prefs.graphics.refresh_period = 5;
app_prefs.checkpoint_period = 5;
app_prefs.poll_period = 5;
app_prefs.cpu_time = prev_cpu_time;
// Write out the app prefs
sprintf( prefs_path, "%s/%s", dirname, CORE_TO_APP_FILE );
@ -315,7 +326,6 @@ int ACTIVE_TASK::start(bool first_time) {
}
pid_handle = process_info.hProcess;
#endif
#ifdef macintosh
@ -327,23 +337,30 @@ int ACTIVE_TASK::start(bool first_time) {
void ACTIVE_TASK::request_exit(int seconds) {
int retval;
if(seconds<0) {
fprintf(stderr, "error: ACTIVE_TASK.request_exit: negative seconds\n");
seconds=0;
}
#if HAVE_SIGNAL_H
#if HAVE_SYS_TYPES_H
retval = kill(pid, SIGTERM);
sleep(seconds);
if(retval) kill(pid, SIGKILL);
while(retval) retval=kill(pid, SIGKILL);
#endif
#endif
#ifdef _WIN32
//retval = ExitProcess();
retval = TerminateProcess(pid_handle, -1);//exit codes should be changed
sleep(seconds);
//if(retval) TerminateProcess();
while(retval) retval=TerminateProcess(pid_handle, -1);
#endif
}
int ACTIVE_TASK_SET::insert(ACTIVE_TASK* atp) {
int retval;
if(atp==NULL) {
fprintf(stderr, "error: ACTIVE_TASK.insert: unexpected NULL pointer atp\n");
return ERR_NULL;
}
get_slot_dir(atp->slot, atp->dirname);
clean_out_dir(atp->dirname);
retval = atp->start(true);
@ -451,7 +468,10 @@ bool ACTIVE_TASK_SET::poll() {
ACTIVE_TASK* ACTIVE_TASK_SET::lookup_pid(int pid) {
unsigned int i;
ACTIVE_TASK* atp;
if(pid<0) {
fprintf(stderr, "error: ACTIVE_TASK_SET.lookup_pid: negatvie pid\n");
return 0;
}
for (i=0; i<active_tasks.size(); i++) {
atp = active_tasks[i];
if (atp->pid == pid) return atp;
@ -479,10 +499,11 @@ void ACTIVE_TASK_SET::unsuspend_all() {
void ACTIVE_TASK_SET::exit_tasks() {
unsigned int i;
ACTIVE_TASK* atp;
ACTIVE_TASK *atp;
for (i=0; i<active_tasks.size(); i++) {
atp = active_tasks[i];
atp->request_exit(0);
atp->update_time();
}
}
@ -499,7 +520,6 @@ void ACTIVE_TASK::unsuspend() {
}
#else
void ACTIVE_TASK::suspend() {
prev_cpu_time = cpu_time;
kill(this->pid, SIGSTOP);
}
@ -510,7 +530,10 @@ void ACTIVE_TASK::unsuspend() {
int ACTIVE_TASK_SET::remove(ACTIVE_TASK* atp) {
vector<ACTIVE_TASK*>::iterator iter;
if(atp==NULL) {
fprintf(stderr, "error: ACTIVE_TASK_SET.remove: unexpected NULL pointer atp\n");
return ERR_NULL;
}
iter = active_tasks.begin();
while (iter != active_tasks.end()) {
if (*iter == atp) {
@ -556,7 +579,8 @@ bool ACTIVE_TASK::update_time() {
if(!app_fp) return false;
parse_app_file(app_fp, ao);
if(!ao.checkpointed) return false;
cpu_time = ao.cpu_time_at_checkpoint + prev_cpu_time;
result->cpu_time += ao.cpu_time_at_checkpoint - prev_cpu_time;
prev_cpu_time = ao.cpu_time_at_checkpoint;
return true;
}
@ -572,20 +596,22 @@ bool ACTIVE_TASK_SET::poll_time() {
}
int ACTIVE_TASK::write(FILE* fout) {
if(fout==NULL) {
fprintf(stderr, "error: ACTIVE_TASK.write: unexpected NULL pointer fout\n");
return ERR_NULL;
}
fprintf(fout,
"<active_task>\n"
" <project_master_url>%s</project_master_url>\n"
" <result_name>%s</result_name>\n"
" <app_version_num>%d</app_version_num>\n"
" <slot>%d</slot>\n"
" <cpu_time>%f</cpu_time>\n"
" <prev_cpu_time>%f</prev_cpu_time>\n"
"</active_task>\n",
result->project->master_url,
result->name,
app_version->version_num,
slot,
cpu_time,
prev_cpu_time
);
return 0;
@ -595,10 +621,16 @@ int ACTIVE_TASK::parse(FILE* fin, CLIENT_STATE* cs) {
char buf[256], result_name[256], project_master_url[256];
int app_version_num=0;
PROJECT* project;
if(fin==NULL) {
fprintf(stderr, "error: ACTIVE_TASK.parse: unexpected NULL pointer fin\n");
return ERR_NULL;
}
if(cs==NULL) {
fprintf(stderr, "error: ACTIVE_TASK.parse: unexpected NULL pointer cs\n");
return ERR_NULL;
}
strcpy(result_name, "");
strcpy(project_master_url, "");
cpu_time = 0;
while (fgets(buf, 256, fin)) {
if (match_tag(buf, "</active_task>")) {
project = cs->lookup_project(project_master_url);
@ -628,7 +660,6 @@ int ACTIVE_TASK::parse(FILE* fin, CLIENT_STATE* cs) {
else if (parse_str(buf, "<project_master_url>", project_master_url)) continue;
else if (parse_int(buf, "<app_version_num>", app_version_num)) continue;
else if (parse_int(buf, "<slot>", slot)) continue;
else if (parse_double(buf, "<cpu_time>", cpu_time)) continue;
else if (parse_double(buf, "<prev_cpu_time>", prev_cpu_time)) continue;
else fprintf(stderr, "ACTIVE_TASK::parse(): unrecognized %s\n", buf);
}
@ -637,6 +668,10 @@ int ACTIVE_TASK::parse(FILE* fin, CLIENT_STATE* cs) {
int ACTIVE_TASK_SET::write(FILE* fout) {
unsigned int i;
if(fout==NULL) {
fprintf(stderr, "error: ACTIVE_TASK_SET.write: unexpected NULL pointer fout\n");
return ERR_NULL;
}
fprintf(fout, "<active_task_set>\n");
for (i=0; i<active_tasks.size(); i++) {
active_tasks[i]->write(fout);
@ -649,7 +684,14 @@ int ACTIVE_TASK_SET::parse(FILE* fin, CLIENT_STATE* cs) {
ACTIVE_TASK* atp;
char buf[256];
int retval;
if(fin==NULL) {
fprintf(stderr, "error: ACTIVE_TASK_SET.parse: unexpected NULL pointer fin\n");
return ERR_NULL;
}
if(cs==NULL) {
fprintf(stderr, "error: ACTIVE_TASK_SET.parse: unexpected NULL pointer cs\n");
return ERR_NULL;
}
while (fgets(buf, 256, fin)) {
if (match_tag(buf, "</active_task_set>")) return 0;
else if (match_tag(buf, "<active_task>")) {

View File

@ -62,8 +62,7 @@ public:
int exit_status;
int signal;
char dirname[256]; // directory where process runs
double cpu_time; // total CPU time
double prev_cpu_time; // CPU time from previous processes
double prev_cpu_time;
ACTIVE_TASK();
int init(RESULT*);

View File

@ -18,6 +18,7 @@
//
#include "windows_cpp.h"
#include "error_numbers.h"
#include <stdio.h>
#include <time.h>
@ -52,7 +53,10 @@ CLIENT_STATE::CLIENT_STATE() {
int CLIENT_STATE::init(PREFS* p) {
nslots = 1;
unsigned int i;
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.init: unexpected NULL pointer p\n");
return ERR_NULL;
}
prefs = p;
// copy all PROJECTs from the prefs to the client state.
@ -267,6 +271,7 @@ int CLIENT_STATE::make_slot_dirs() {
int CLIENT_STATE::exit_tasks() {
active_tasks.exit_tasks();
active_tasks.poll_time();
return 0;
}
@ -325,6 +330,10 @@ int CLIENT_STATE::write_state_file() {
}
PROJECT* CLIENT_STATE::lookup_project(char* master_url) {
if(master_url==NULL) {
fprintf(stderr, "error: CLIENT_STATE.lookup_project: unexpected NULL pointer master_url\n");
return 0;
}
for (unsigned int i=0; i<projects.size(); i++) {
if (!strcmp(master_url, projects[i]->master_url)) {
return projects[i];
@ -334,6 +343,14 @@ PROJECT* CLIENT_STATE::lookup_project(char* master_url) {
}
APP* CLIENT_STATE::lookup_app(PROJECT* p, char* name) {
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.lookup_app: unexpected NULL pointer p\n");
return 0;
}
if(name==NULL) {
fprintf(stderr, "error: CLIENT_STATE.lookup_app: unexpected NULL pointer name\n");
return 0;
}
for (unsigned int i=0; i<apps.size(); i++) {
APP* app = apps[i];
if (app->project == p && !strcmp(name, app->name)) return app;
@ -342,6 +359,14 @@ APP* CLIENT_STATE::lookup_app(PROJECT* p, char* name) {
}
RESULT* CLIENT_STATE::lookup_result(PROJECT* p, char* name) {
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.lookup_result: unexpected NULL pointer p\n");
return 0;
}
if(name==NULL) {
fprintf(stderr, "error: CLIENT_STATE.lookup_result: unexpected NULL pointer name\n");
return 0;
}
for (unsigned int i=0; i<results.size(); i++) {
RESULT* rp = results[i];
if (rp->project == p && !strcmp(name, rp->name)) return rp;
@ -350,6 +375,14 @@ RESULT* CLIENT_STATE::lookup_result(PROJECT* p, char* name) {
}
WORKUNIT* CLIENT_STATE::lookup_workunit(PROJECT* p, char* name) {
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.lookup_workunit: unexpected NULL pointer p\n");
return 0;
}
if(name==NULL) {
fprintf(stderr, "error: CLIENT_STATE.lookup_workunit: unexpected NULL pointer name\n");
return 0;
}
for (unsigned int i=0; i<workunits.size(); i++) {
WORKUNIT* wup = workunits[i];
if (wup->project == p && !strcmp(name, wup->name)) return wup;
@ -358,6 +391,14 @@ WORKUNIT* CLIENT_STATE::lookup_workunit(PROJECT* p, char* name) {
}
APP_VERSION* CLIENT_STATE::lookup_app_version(APP* app, int version_num) {
if(app==NULL) {
fprintf(stderr, "error: CLIENT_STATE.lookup_app_version: unexpected NULL pointer app\n");
return 0;
}
if(version_num<0) {
fprintf(stderr, "error: CLIENT_STATE.lookup_app_version: negative version_num\n");
return 0;
}
for (unsigned int i=0; i<app_versions.size(); i++) {
APP_VERSION* avp = app_versions[i];
if (avp->app == app && version_num==avp->version_num) {
@ -368,6 +409,14 @@ APP_VERSION* CLIENT_STATE::lookup_app_version(APP* app, int version_num) {
}
FILE_INFO* CLIENT_STATE::lookup_file_info(PROJECT* p, char* name) {
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.lookup_file_info: unexpected NULL pointer p\n");
return 0;
}
if(name==NULL) {
fprintf(stderr, "error: CLIENT_STATE.lookup_file_info: unexpected NULL pointer p\n");
return 0;
}
for (unsigned int i=0; i<file_infos.size(); i++) {
FILE_INFO* fip = file_infos[i];
if (fip->project == p && !strcmp(fip->name, name)) {
@ -381,11 +430,27 @@ FILE_INFO* CLIENT_STATE::lookup_file_info(PROJECT* p, char* name) {
// (which, in their XML form, reference one another by name)
//
int CLIENT_STATE::link_app(PROJECT* p, APP* app) {
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_app: unexpected NULL pointer p\n");
return ERR_NULL;
}
if(app==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_app: unexpected NULL pointer app\n");
return ERR_NULL;
}
app->project = p;
return 0;
}
int CLIENT_STATE::link_file_info(PROJECT* p, FILE_INFO* fip) {
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_file_info: unexpected NULL pointer p\n");
return ERR_NULL;
}
if(fip==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_file_info: unexpected NULL pointer fip\n");
return ERR_NULL;
}
fip->project = p;
return 0;
}
@ -395,9 +460,15 @@ int CLIENT_STATE::link_app_version(PROJECT* p, APP_VERSION* avp) {
FILE_INFO* fip;
FILE_REF file_ref;
unsigned int i;
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_app_version: unexpected NULL pointer fip\n");
return ERR_NULL;
}
if(avp==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_app_version: unexpected NULL pointer fip\n");
return ERR_NULL;
}
avp->project = p;
app = lookup_app(p, avp->app_name);
if (!app) {
fprintf(stderr,
@ -428,7 +499,14 @@ int CLIENT_STATE::link_app_version(PROJECT* p, APP_VERSION* avp) {
int CLIENT_STATE::link_file_ref(PROJECT* p, FILE_REF* file_refp) {
FILE_INFO* fip;
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_file_ref: unexpected NULL pointer p\n");
return ERR_NULL;
}
if(file_refp==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_file_ref: unexpected NULL pointer file_refp\n");
return ERR_NULL;
}
fip = lookup_file_info(p, file_refp->file_name);
if (!fip) {
fprintf(stderr,
@ -445,7 +523,14 @@ int CLIENT_STATE::link_workunit(PROJECT* p, WORKUNIT* wup) {
APP_VERSION* avp;
unsigned int i;
int retval;
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_workunit: unexpected NULL pointer p\n");
return ERR_NULL;
}
if(wup==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_workunit: unexpected NULL pointer wup\n");
return ERR_NULL;
}
app = lookup_app(p, wup->app_name);
if (!app) {
fprintf(stderr,
@ -474,7 +559,14 @@ int CLIENT_STATE::link_result(PROJECT* p, RESULT* rp) {
WORKUNIT* wup;
unsigned int i;
int retval;
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_result: unexpected NULL pointer p\n");
return ERR_NULL;
}
if(rp==NULL) {
fprintf(stderr, "error: CLIENT_STATE.link_result: unexpected NULL pointer rp\n");
return ERR_NULL;
}
wup = lookup_workunit(p, rp->wu_name);
if (!wup) {
fprintf(stderr, "result refers to nonexistent WU: %s\n", rp->wu_name);
@ -608,6 +700,12 @@ int CLIENT_STATE::write_state_file_if_needed() {
void CLIENT_STATE::parse_cmdline(int argc, char** argv) {
int i;
if(argc<0) {
fprintf(stderr, "error: CLIENT_STATE.parse_cmdline: negative argc\n");
}
if(argv==NULL) {
fprintf(stderr, "error: CLIENT_STATE.parse_cmdline: unexpected NULL pointer argv\n");
}
for (i=1; i<argc; i++) {
if (!strcmp(argv[i], "-exit_when_idle")) {
exit_when_idle = true;

View File

@ -40,7 +40,10 @@ PROJECT::~PROJECT() {
int PROJECT::parse_prefs(FILE* in) {
char buf[256], *p;
int retval;
if(in==NULL) {
fprintf(stderr, "error: PROJECT.parse_prefs: unexpected NULL pointer in\n");
return ERR_NULL;
}
strcpy(master_url, "");
strcpy(authenticator, "");
while (fgets(buf, 256, in)) {
@ -64,7 +67,10 @@ int PROJECT::parse_prefs(FILE* in) {
int PROJECT::parse_state(FILE* in) {
char buf[256];
STRING256 string;
if(in==NULL) {
fprintf(stderr, "error: PROJECT.parse_state: unexpected NULL pointer in\n");
return ERR_NULL;
}
strcpy(project_name, "");
strcpy(user_name, "");
next_request_time = 0;
@ -87,6 +93,7 @@ int PROJECT::parse_state(FILE* in) {
else if (parse_int(buf, "<exp_avg_mod_time>", exp_avg_mod_time)) continue;
else if (match_tag(buf, "<code_sign_key>")) {
dup_element_contents(in, "</code_sign_key>", &code_sign_key);
//fprintf(stderr, "code_sign_key: %s\n", code_sign_key);
}
else fprintf(stderr, "PROJECT::parse_state(): unrecognized: %s\n", buf);
}
@ -95,7 +102,10 @@ int PROJECT::parse_state(FILE* in) {
int PROJECT::write_state(FILE* out) {
unsigned int i;
if(out==NULL) {
fprintf(stderr, "error: PROJECT.write_state: unexpected NULL pointer out\n");
return ERR_NULL;
}
fprintf(out,
"<project>\n"
);
@ -155,7 +165,10 @@ void PROJECT::copy_prefs_fields(PROJECT& p) {
int APP::parse(FILE* in) {
char buf[256];
if(in==NULL) {
fprintf(stderr, "error: APP.parse: unexpected NULL pointer in\n");
return ERR_NULL;
}
strcpy(name, "");
project = NULL;
while (fgets(buf, 256, in)) {
@ -168,6 +181,10 @@ int APP::parse(FILE* in) {
}
int APP::write(FILE* out) {
if(out==NULL) {
fprintf(stderr, "error: APP.write: unexpected NULL pointer out\n");
return ERR_NULL;
}
fprintf(out,
"<app>\n"
" <name>%s</name>\n"
@ -191,7 +208,10 @@ FILE_INFO::~FILE_INFO() {
int FILE_INFO::parse(FILE* in, bool from_server) {
char buf[256];
STRING256 url;
if(in==NULL) {
fprintf(stderr, "error: FILE_INFO.parse: unexpected NULL pointer in\n");
return ERR_NULL;
}
strcpy(name, "");
strcpy(md5_cksum, "");
nbytes = 0;
@ -228,6 +248,7 @@ int FILE_INFO::parse(FILE* in, bool from_server) {
}
else if (match_tag(buf, "<file_signature>")) {
dup_element_contents(in, "</file_signature>", &file_signature);
fprintf(stderr, "file_signature %s being copied\n", file_signature);
continue;
}
else if (parse_str(buf, "<md5_cksum>", md5_cksum)) continue;
@ -251,6 +272,10 @@ int FILE_INFO::parse(FILE* in, bool from_server) {
int FILE_INFO::write(FILE* out, bool to_server) {
unsigned int i;
if(out==NULL) {
fprintf(stderr, "error: FILE_INFO.write: unexpected NULL pointer out\n");
return ERR_NULL;
}
fprintf(out,
"<file_info>\n"
" <name>%s</name>\n"
@ -295,7 +320,10 @@ int FILE_INFO::delete_file() {
int APP_VERSION::parse(FILE* in) {
char buf[256];
FILE_REF file_ref;
if(in==NULL) {
fprintf(stderr, "error: APP_VERSION.parse: unexpected NULL poiner in\n");
return ERR_NULL;
}
strcpy(app_name, "");
version_num = 0;
app = NULL;
@ -316,6 +344,10 @@ int APP_VERSION::parse(FILE* in) {
int APP_VERSION::write(FILE* out) {
unsigned int i;
if(out==NULL) {
fprintf(stderr, "error: APP_VERSION.write: unexpected NULL pointer out\n");
return ERR_NULL;
}
fprintf(out,
"<app_version>\n"
" <app_name>%s</app_name>\n"
@ -334,7 +366,10 @@ int APP_VERSION::write(FILE* out) {
int FILE_REF::parse(FILE* in) {
char buf[256];
if(in==NULL) {
fprintf(stderr, "error: FILE_REF.parse: unexpected NULL pointer in\n");
return ERR_NULL;
}
strcpy(file_name, "");
strcpy(open_name, "");
fd = -1;
@ -351,6 +386,10 @@ int FILE_REF::parse(FILE* in) {
}
int FILE_REF::write(FILE* out) {
if(out==NULL) {
fprintf(stderr, "error: FILE_REF.write: unexpected NULL pointer out\n");
return ERR_NULL;
}
if (strlen(open_name)) {
fprintf(out, " <open_name>%s</open_name>\n", open_name);
}
@ -372,7 +411,10 @@ int FILE_REF::write(FILE* out) {
int WORKUNIT::parse(FILE* in) {
char buf[256];
FILE_REF file_ref;
if(in==NULL) {
fprintf(stderr, "error: WORKUNIT.parse: unexpected NULL pointer in\n");
return ERR_NULL;
}
strcpy(name, "");
strcpy(app_name, "");
version_num = 0;
@ -401,6 +443,10 @@ int WORKUNIT::parse(FILE* in) {
int WORKUNIT::write(FILE* out) {
unsigned int i;
if(out==NULL) {
fprintf(stderr, "error: WORKUNIT.write: unexpected NULL pointer out\n");
return ERR_NULL;
}
fprintf(out,
"<workunit>\n"
" <name>%s</name>\n"
@ -419,6 +465,10 @@ int WORKUNIT::write(FILE* out) {
int RESULT::parse_ack(FILE* in) {
char buf[256];
if(in==NULL) {
fprintf(stderr, "error: RESULT.parse_ack: unexpected NULL pointer in\n");
return ERR_NULL;
}
strcpy(name, "");
while (fgets(buf, 256, in)) {
if (match_tag(buf, "</result_ack>")) return 0;
@ -448,7 +498,10 @@ void RESULT::clear() {
int RESULT::parse_server(FILE* in) {
char buf[256];
FILE_REF file_ref;
if(in==NULL) {
fprintf(stderr, "error: RESULT.parse_server: unexpected NULL pointer in\n");
return ERR_NULL;
}
while (fgets(buf, 256, in)) {
if (match_tag(buf, "</result>")) return 0;
if (parse_str(buf, "<name>", name)) continue;
@ -468,7 +521,10 @@ int RESULT::parse_server(FILE* in) {
int RESULT::parse_state(FILE* in) {
char buf[256];
FILE_REF file_ref;
if(in==NULL) {
fprintf(stderr, "error: RESULT.parse_state: unexpected NULL pointer in\n");
return ERR_NULL;
}
while (fgets(buf, 256, in)) {
if (match_tag(buf, "</result>")) return 0;
if (parse_str(buf, "<name>", name)) continue;
@ -496,7 +552,10 @@ int RESULT::write(FILE* out, bool to_server) {
unsigned int i;
FILE_INFO* fip;
int n;
if(out==NULL) {
fprintf(stderr, "error: RESULT.write: unexpected NULL pointer out\n");
return ERR_NULL;
}
fprintf(out,
"<result>\n"
" <name>%s</name>\n"

View File

@ -81,11 +81,14 @@ bool CLIENT_STATE::handle_running_apps() {
}
bool CLIENT_STATE::input_files_available(RESULT* rp) {
if(rp==NULL) {
fprintf(stderr, "error: CLIENT_STATE.input_files_available: unexpected NULL pointer rp\n");
return false;
}
WORKUNIT* wup = rp->wup;
FILE_INFO* fip;
unsigned int i;
APP_VERSION* avp;
avp = wup->avp;
for (i=0; i<avp->app_files.size(); i++) {
fip = avp->app_files[i].file_info;

View File

@ -37,6 +37,7 @@
#include "client_types.h"
#include "log_flags.h"
#include "client_state.h"
#include "error_numbers.h"
int verify_downloaded_file(char* pathname, FILE_INFO& file_info) {
char cksum[64];
@ -44,13 +45,31 @@ int verify_downloaded_file(char* pathname, FILE_INFO& file_info) {
bool verified;
int retval;
if(pathname==NULL) {
fprintf(stderr, "error: verify_downloaded_file: unexpected NULL pointer pathname\n");
return ERR_NULL;
}
if (file_info.signature_required) {
if (!file_info.file_signature) return -1;
if (!file_info.file_signature) {
fprintf(stderr, "error: verify_downloaded_file: unexpected NULL pointer file_signature\n");
return -1;
}
project = file_info.project;
retval = verify_file2(
pathname, file_info.file_signature, project->code_sign_key, verified
);
if (retval || !verified) return -1;
if(retval) {
fprintf(stderr, "error: verify_file2: internal error\n");
//return -1;
}
if(!verified) {
fprintf(stderr, "error: verify_file2: file not verified\n");
//return -1;
}
if (retval || !verified) {
fprintf(stderr, "error: verify_file2: could not verify file\n");
return -1;
}
} else if (file_info.md5_cksum) {
md5_file(pathname, cksum, file_info.nbytes);
if (strcmp(cksum, file_info.md5_cksum)) return -1;

View File

@ -35,7 +35,6 @@
#endif
#include "crypt.h"
#include "error_numbers.h"
#include "file_names.h"
#include "parse.h"
@ -47,6 +46,7 @@
// quantities like avg CPU time decay by a factor of e every week
#define EXP_DECAY_RATE (1./(3600*24*7))
#define SECONDS_IN_DAY 86400
//estimates the number of days of work remaining
//
@ -61,7 +61,7 @@ double CLIENT_STATE::current_water_days() {
else
seconds_remaining += rp->wup->seconds_to_complete;
}
return (seconds_remaining * 86400);
return (seconds_remaining * SECONDS_IN_DAY);
}
bool CLIENT_STATE::need_work() {
@ -76,6 +76,9 @@ bool CLIENT_STATE::need_work() {
void CLIENT_STATE::update_avg_cpu(PROJECT* p) {
int now = time(0);
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.update_avg_cpu: unexpected NULL pointer p\n");
}
double deltat = now - p->exp_avg_mod_time;
if (deltat > 0) {
if (p->exp_avg_cpu != 0) {
@ -120,7 +123,14 @@ int CLIENT_STATE::make_scheduler_request(PROJECT* p, int work_req) {
FILE* f = fopen(SCHED_OP_REQUEST_FILE, "wb");
unsigned int i;
RESULT* rp;
if(p==NULL) {
fprintf(stderr, "error: CLIENT_STATE.make_scheduler_request: unexpected NULL pointer p\n");
return ERR_NULL;
}
if(work_req<0) {
fprintf(stderr, "error: CLIENT_STATE.make_scheduler_request: negative work_req\n");
return ERR_NEG;
}
if (!f) return ERR_FOPEN;
fprintf(f,
"<scheduler_request>\n"

View File

@ -28,6 +28,7 @@
#include <ctype.h>
#include "file_names.h"
#include "error_numbers.h"
static void c2x(char *what) {
char buf[3];
@ -35,6 +36,9 @@ static void c2x(char *what) {
char d1 = num / 16;
char d2 = num % 16;
int abase1, abase2;
if(what==NULL) {
fprintf(stderr, "error: c2x: unexpected NULL pointer what\n");
}
if (d1 < 10) abase1 = 48;
else abase1 = 55;
if (d2 < 10) abase2 = 48;
@ -48,6 +52,12 @@ static void c2x(char *what) {
static void escape_url(char *in, char* out) {
int x, y;
if(in==NULL) {
fprintf(stderr, "error: escape_url: unexpected NULL pointer in\n");
}
if(out==NULL) {
fprintf(stderr, "error: escape_url: unexpected NULL pointer out\n");
}
for (x=0, y=0; in[x]; ++x) {
if (isalnum(in[x])) {
out[y] = in[x];
@ -68,9 +78,14 @@ static void escape_url(char *in, char* out) {
}
void get_pathname(FILE_INFO* fip, char* path) {
if(fip==NULL) {
fprintf(stderr, "error: get_pathname: unexpected NULL pointer fip\n");
}
if(path==NULL) {
fprintf(stderr, "error: get_pathname: unexpected NULL pointer path\n");
}
PROJECT* p = fip->project;
char buf[256];
// for testing purposes, it's handy to allow a FILE_INFO without
// an associated PROJECT.
//
@ -83,6 +98,12 @@ void get_pathname(FILE_INFO* fip, char* path) {
}
void get_slot_dir(int slot, char* path) {
if(path==NULL) {
fprintf(stderr, "error: get_slot_dir: unexpected NULL pointer path\n");
}
if(slot<0) {
fprintf(stderr, "error: get_slot_dir: negative slot\n");
}
sprintf(path, "slots/%d", slot);
}
@ -99,6 +120,10 @@ int make_project_dir(PROJECT& p) {
}
int make_slot_dir(int slot) {
if(slot<0) {
fprintf(stderr, "error: make_slot_dir: negative slot\n");
return ERR_NEG;
}
char buf[256];
CreateDirectory("slots", NULL);
get_slot_dir(slot, buf);
@ -118,6 +143,10 @@ int make_project_dir(PROJECT& p) {
int make_slot_dir(int slot) {
char buf[256];
if(slot<0) {
fprintf(stderr, "error: make_slot_dir: negative slot\n");
return ERR_NEG;
}
mkdir("slots", 0777);
get_slot_dir(slot, buf);
mkdir(buf, 0777);
@ -125,6 +154,10 @@ int make_slot_dir(int slot) {
}
int make_prefs_backup_name(PREFS& prefs, char* name) {
if(name==NULL) {
fprintf(stderr, "error: make_prefs_backup_name: unexpected NULL pointer name\n");
return ERR_NULL;
}
sprintf(name, "prefs_backup_%d", prefs.mod_time);
return 0;
}

View File

@ -23,6 +23,7 @@
#include "file_names.h"
#include "log_flags.h"
#include "file_xfer.h"
#include "error_numbers.h"
FILE_XFER::FILE_XFER() {
file_xfer_done = false;
@ -34,10 +35,26 @@ FILE_XFER::~FILE_XFER() {
#if 0
int FILE_XFER::init_download(char* url, char* outfile) {
if(url==NULL) {
fprintf(stderr, "error: FILE_XFER.init_download: unexpected NULL pointer url\n");
return ERR_NULL;
}
if(outfile==NULL) {
fprintf(stderr, "error: FILE_XFER.init_download: unexpected NULL pointer outfile\n");
return ERR_NULL;
}
return HTTP_OP::init_get(url, outfile);
}
int FILE_XFER::init_upload(char* url, char* infile) {
if(url==NULL) {
fprintf(stderr, "error: FILE_XFER.init_upload: unexpected NULL pointer url\n");
return ERR_NULL;
}
if(outfile==NULL) {
fprintf(stderr, "error: FILE_XFER.init_upload: unexpected NULL pointer infile\n");
return ERR_NULL;
}
return HTTP_OP::init_put(url, infile);
}
#endif
@ -77,12 +94,18 @@ double FILE_XFER::elapsed_time() {
}
FILE_XFER_SET::FILE_XFER_SET(HTTP_OP_SET* p) {
if(p==NULL) {
fprintf(stderr, "error: FILE_XFER_SET: unexpected NULL pointer p\n");
}
http_ops = p;
}
int FILE_XFER_SET::insert(FILE_XFER* fxp) {
int retval;
if(fxp==NULL) {
fprintf(stderr, "error: FILE_XFER_SET.insert: unexpected NULL pointer fxp\n");
return ERR_NULL;
}
// record start time.
// This could be made more accurate by omitting the connection
// setup and initial request times.
@ -96,7 +119,10 @@ int FILE_XFER_SET::insert(FILE_XFER* fxp) {
int FILE_XFER_SET::remove(FILE_XFER* fxp) {
vector<FILE_XFER*>::iterator iter;
if(fxp==NULL) {
fprintf(stderr, "error: FILE_XFER_SET.remove: unexpected NULL pointer fxp\n");
return ERR_NULL;
}
http_ops->remove(fxp);
iter = file_xfers.begin();

View File

@ -74,6 +74,10 @@ char failed_file[256];
// routines for enumerating the entries in a directory
int dir_open(char* p) {
if(p==NULL) {
fprintf(stderr, "error: dir_open: unexpected NULL pointer p\n");
return ERR_NULL;
}
#ifdef HAVE_DIRENT_H
dirp = opendir(p);
if (!dirp) return ERR_OPENDIR;
@ -91,6 +95,10 @@ int dir_open(char* p) {
}
int dir_scan(char* p) {
if(p==NULL) {
fprintf(stderr, "error: dir_scan: unexpected NULL pointer p\n");
return ERR_NULL;
}
#ifdef HAVE_DIRENT_H
while (1) {
dirent* dp = readdir(dirp);
@ -157,7 +165,10 @@ void dir_close() {
int file_delete(char* path) {
int retval,i;
if(path==NULL) {
fprintf(stderr, "error: file_delete: unexpected NULL pointer path\n");
return ERR_NULL;
}
for (i=0; i<2; i++) {
#ifdef HAVE_UNISTD_H
retval = unlink(path);
@ -179,7 +190,10 @@ int file_delete(char* path) {
int file_size(char* path, int& size) {
struct stat sbuf;
int retval;
if(path==NULL) {
fprintf(stderr, "error: file_size: unexpected NULL pointer path\n");
return ERR_NULL;
}
retval = stat(path, &sbuf);
if (retval) return retval;
size = sbuf.st_size;
@ -191,20 +205,30 @@ int file_size(char* path, int& size) {
int boinc_link( char *existing, char *new_link ) {
FILE *fp;
if(existing==NULL) {
fprintf(stderr, "error: boinc_link: unexpected NULL pointer existing\n");
return ERR_NULL;
}
if(new_link==NULL) {
fprintf(stderr, "error: boinc_link: unexpected NULL pointer new_link\n");
return ERR_NULL;
}
fp = fopen( new_link, "wb" );
if (!fp) return ERR_FOPEN;
rewind( fp );
fprintf( fp, "<soft_link>%s</soft_link>\n", existing );
fclose( fp );
fp = fopen( new_link, "wb" );
if (!fp) return ERR_FOPEN;
rewind( fp );
fprintf( fp, "<soft_link>%s</soft_link>\n", existing );
fclose( fp );
return 0;
return 0;
}
int clean_out_dir(char* dirpath) {
char filename[256], path[256];
int retval;
if(dirpath==NULL) {
fprintf(stderr, "error: clean_out_dir: unexpected NULL pointer dirpath\n");
return ERR_NULL;
}
retval = dir_open(dirpath);
if (retval) return retval;
while (1) {

View File

@ -22,10 +22,14 @@
#include "parse.h"
#include "hostinfo.h"
#include "error_numbers.h"
int HOST_INFO::parse(FILE* in) {
char buf[256];
if(in==NULL) {
fprintf(stderr, "error: HOST_INFO.parse: unexpected NULL pointer in\n");
return ERR_NULL;
}
memset(this, 0, sizeof(HOST_INFO));
while (fgets(buf, 256, in)) {
if (match_tag(buf, "</host_info>")) return 0;
@ -52,6 +56,10 @@ int HOST_INFO::parse(FILE* in) {
}
int HOST_INFO::write(FILE* out) {
if(out==NULL) {
fprintf(stderr, "error: HOST_INFO.write: unexpected NULL pointer out\n");
return ERR_NULL;
}
fprintf(out,
"<host_info>\n"
" <timezone>%d</timezone>\n"

View File

@ -57,12 +57,16 @@
#endif
#include "client_types.h"
#include "error_numbers.h"
// functions to get name/addr of local host
int get_local_domain_name(char* p) {
char buf[256];
if(p==NULL) {
fprintf(stderr, "error: get_local_domain_name: unexpected NULL pointer p\n");
return ERR_NULL;
}
gethostname(buf, 256);
struct hostent* he = gethostbyname(buf);
strcpy(p, he->h_name);
@ -83,6 +87,10 @@ int get_local_ip_addr(int& p) {
int get_local_ip_addr_str(char* p) {
char buf[256];
if(p==NULL) {
fprintf(stderr, "error: get_local_ip_addr_str: unexpected NULL pointer p\n");
return ERR_NULL;
}
#if HAVE_NETDB_H
struct in_addr addr;
gethostname(buf, 256);
@ -227,10 +235,10 @@ int get_host_info(HOST_INFO& host) {
#endif
get_local_domain_name(host.domain_name);
get_local_ip_addr_str(host.ip_addr);
get_timezone(host.timezone);
#ifdef HAVE_SYS_UTSNAME_H
get_osinfo(host);
#endif
get_timezone(host.timezone);
return 0;
}

View File

@ -39,7 +39,15 @@
static void parse_url(char* url, char* host, char* file) {
char* p;
char buf[256];
if(url==NULL) {
fprintf(stderr, "error: parse_url: unexpected NULL pointer url\n");
}
if(host==NULL) {
fprintf(stderr, "error: parse_url: unexpected NULL pointer host\n");
}
if(file==NULL) {
fprintf(stderr, "error: parse_url: unexpected NULL pointer file\n");
}
if (strncmp(url, "http://", 7) == 0) strcpy(buf, url+7);
else strcpy(buf, url);
p = strchr(buf, '/');
@ -59,6 +67,18 @@ static void parse_url(char* url, char* host, char* file) {
static void http_get_request_header(
char* buf, char* host, char* file, int offset
) {
if(buf==NULL) {
fprintf(stderr, "error: http_get_request_header: unexpected NULL pointer buf\n");
}
if(host==NULL) {
fprintf(stderr, "error: http_get_request_header: unexpected NULL pointer host\n");
}
if(file==NULL) {
fprintf(stderr, "error: http_get_request_header: unexpected NULL pointer file\n");
}
if(offset<0) {
fprintf(stderr, "error: http_get_request_header: negative offset\n");
}
if (offset) {
sprintf(buf,
"GET /%s;byte-range %d- HTTP/1.0\015\012"
@ -83,6 +103,15 @@ static void http_get_request_header(
}
static void http_head_request_header(char* buf, char* host, char* file) {
if(buf==NULL) {
fprintf(stderr, "error: http_head_request_header: unexpected NULL pointer buf\n");
}
if(host==NULL) {
fprintf(stderr, "error: http_head_request_header: unexpected NULL pointer host\n");
}
if(file==NULL) {
fprintf(stderr, "error: http_head_request_header: unexpected NULL pointer file\n");
}
sprintf(buf,
"HEAD /%s HTTP/1.0\015\012"
"User-Agent: BOINC client\015\012"
@ -96,6 +125,18 @@ static void http_head_request_header(char* buf, char* host, char* file) {
static void http_post_request_header(
char* buf, char* host, char* file, int size
) {
if(buf==NULL) {
fprintf(stderr, "error: http_post_request_header: unexpected NULL pointer buf\n");
}
if(host==NULL) {
fprintf(stderr, "error: http_post_request_header: unexpected NULL pointer host\n");
}
if(file==NULL) {
fprintf(stderr, "error: http_post_request_header: unexpected NULL pointer file\n");
}
if(size<0) {
fprintf(stderr, "error: http_post_request_header: negative size\n");
}
sprintf(buf,
"POST /%s HTTP/1.0\015\012"
"Pragma: no-cache\015\012"
@ -112,6 +153,21 @@ static void http_post_request_header(
void http_put_request_header(
char* buf, char* host, char* file, int size, int offset
) {
if(buf==NULL) {
fprintf(stderr, "error: http_put_request_header: unexpected NULL pointer buf\n");
}
if(host==NULL) {
fprintf(stderr, "error: http_put_request_header: unexpected NULL pointer host\n");
}
if(file==NULL) {
fprintf(stderr, "error: http_put_request_header: unexpected NULL pointer file\n");
}
if(size<0) {
fprintf(stderr, "error: http_put_request_header: negative size\n");
}
if(offset<0) {
fprintf(stderr, "error: http_put_request_header: negative offset\n");
}
if (offset) {
sprintf(buf,
"PUT /%s;byte-range %d- HTTP/1.0\015\012"
@ -143,7 +199,10 @@ void http_put_request_header(
int read_http_reply_header(int socket, HTTP_REPLY_HEADER& header) {
int i, n;
char buf[1024], *p;
if(socket<0) {
fprintf(stderr, "error: read_http_reply_header: negative socket\n");
return ERR_NEG;
}
memset(buf, 0, sizeof(buf));
header.content_length = 0;
header.status = 404; // default to failure
@ -167,6 +226,18 @@ int read_http_reply_header(int socket, HTTP_REPLY_HEADER& header) {
static int read_reply(int socket, char* buf, int len) {
int i, n;
if(socket<0) {
fprintf(stderr, "error: read_reply: negative socket\n");
return ERR_NEG;
}
if(buf==NULL) {
fprintf(stderr, "error: read_reply: unexpected NULL pointer buf\n");
return ERR_NULL;
}
if(len<0) {
fprintf(stderr, "error: read_reply: negative len\n");
return ERR_NEG;
}
for (i=0; i<len-1; i++) {
n = recv(socket, buf+i, 1, 0);
if (n != 1) break;
@ -183,6 +254,10 @@ HTTP_OP::~HTTP_OP() {
}
int HTTP_OP::init_head(char* url) {
if(url==NULL) {
fprintf(stderr, "error: HTTP_OP.init_head: unexpected NULL pointer url\n");
return ERR_NULL;
}
parse_url(url, hostname, filename);
NET_XFER::init(hostname, 80, HTTP_BLOCKSIZE);
http_op_type = HTTP_OP_HEAD;
@ -192,6 +267,18 @@ int HTTP_OP::init_head(char* url) {
}
int HTTP_OP::init_get(char* url, char* out, int off) {
if(url==NULL) {
fprintf(stderr, "error: HTTP_OP.init_get: unexpected NULL pointer url\n");
return ERR_NULL;
}
if(out==NULL) {
fprintf(stderr, "error: HTTP_OP.init_get: unexpected NULL pointer out\n");
return ERR_NULL;
}
if(off<0) {
fprintf(stderr, "error: HTTP_OP.init_get: negative off\n");
return ERR_NEG;
}
file_offset = off;
parse_url(url, hostname, filename);
NET_XFER::init(hostname, 80, HTTP_BLOCKSIZE);
@ -204,7 +291,18 @@ int HTTP_OP::init_get(char* url, char* out, int off) {
int HTTP_OP::init_post(char* url, char* in, char* out) {
int retval;
if(url==NULL) {
fprintf(stderr, "error: HTTP_OP.init_post: unexpected NULL pointer url\n");
return ERR_NULL;
}
if(in==NULL) {
fprintf(stderr, "error: HTTP_OP.init_post: unexpected NULL pointer in\n");
return ERR_NULL;
}
if(out==NULL) {
fprintf(stderr, "error: HTTP_OP.init_post: unexpected NULL pointer out\n");
return ERR_NULL;
}
parse_url(url, hostname, filename);
NET_XFER::init(hostname, 80, HTTP_BLOCKSIZE);
strcpy(infile, in);
@ -223,7 +321,22 @@ int HTTP_OP::init_post2(
char* url, char* r1, char* in, double offset
) {
int retval;
if(url==NULL) {
fprintf(stderr, "error: HTTP_OP.init_post2: unexpected NULL pointer url\n");
return ERR_NULL;
}
if(r1==NULL) {
fprintf(stderr, "error: HTTP_OP.init_post2: unexpected NULL pointer r1\n");
return ERR_NULL;
}
if(in==NULL) {
fprintf(stderr, "error: HTTP_OP.init_post2: unexpected NULL pointer in\n");
return ERR_NULL;
}
if(offset<0) {
fprintf(stderr, "error: HTTP_OP.init_post2: negative offset\n");
return ERR_NEG;
}
parse_url(url, hostname, filename);
NET_XFER::init(hostname, 80, HTTP_BLOCKSIZE);
req1 = r1;
@ -265,11 +378,18 @@ bool HTTP_OP::http_op_done() {
}
HTTP_OP_SET::HTTP_OP_SET(NET_XFER_SET* p) {
if(p==NULL) {
fprintf(stderr, "error: HTTP_OP_SET: unexpected NULL pointer p\n");
}
net_xfers = p;
}
int HTTP_OP_SET::insert(HTTP_OP* ho) {
int retval;
if(ho==NULL) {
fprintf(stderr, "error: HTTP_OP_SET.insert: unexpected NULL pointer ho\n");
return ERR_NULL;
}
retval = net_xfers->insert(ho);
if (retval) return retval;
http_ops.push_back(ho);
@ -429,7 +549,10 @@ bool HTTP_OP_SET::poll() {
int HTTP_OP_SET::remove(HTTP_OP* p) {
vector<HTTP_OP*>::iterator iter;
if(p==NULL) {
fprintf(stderr, "error: HTTP_OP_SET.remove: unexpected NULL pointer p\n");
return ERR_NULL;
}
net_xfers->remove(p);
iter = http_ops.begin();

View File

@ -33,7 +33,10 @@ LOG_FLAGS::LOG_FLAGS() {
int LOG_FLAGS::parse(FILE* in) {
char buf[256];
if(in==NULL) {
fprintf(stderr, "error: LOG_FLAGS.parse: unexpected NULL pointer in\n");
return ERR_NULL;
}
fgets(buf, 256, in);
if (!match_tag(buf, "<log_flags>")) return ERR_XML_PARSE;
while (fgets(buf, 256, in)) {

View File

@ -31,6 +31,12 @@
#include "util.h"
void show_message(char* message, char* priority) {
if(message==NULL) {
fprintf(stderr, "error: show_message: unexpected NULL pointer message\n");
}
if(priority==NULL) {
fprintf(stderr, "error: show_message: unexpected NULL pointer priority\n");
}
if (!strcmp(priority, "high")) {
fprintf(stderr, "BOINC core client: %s\n", message);
} else {

View File

@ -23,6 +23,7 @@
#include "parse.h"
#include "time.h"
#include "error_numbers.h"
#include "net_stats.h"
#define SMALL_FILE_CUTOFF 32000
@ -66,6 +67,10 @@ void NET_STATS::update(bool is_upload, double nbytes, double nsecs) {
}
int NET_STATS::write(FILE* out, bool to_server) {
if(out==NULL) {
fprintf(stderr, "error: NET_STATS.write: unexpected NULL pointer out\n");
return ERR_NULL;
}
fprintf(out,
"<net_stats>\n"
" <bwup>%f</bwup>\n"
@ -86,7 +91,10 @@ int NET_STATS::write(FILE* out, bool to_server) {
int NET_STATS::parse(FILE* in) {
char buf[256];
if(in==NULL) {
fprintf(stderr, "error: NET_STATS.parse: unexpected NULL pointer in\n");
return ERR_NULL;
}
memset(this, 0, sizeof(NET_STATS));
while (fgets(buf, 256, in)) {
if (match_tag(buf, "</net_stats>")) return 0;

View File

@ -27,6 +27,9 @@
#include "scheduler_op.h"
SCHEDULER_OP::SCHEDULER_OP(HTTP_OP_SET* h) {
if(h==NULL) {
fprintf(stderr, "error: SCHEDULER_OP: unexpected NULL pointer h\n");
}
state = SCHEDULER_OP_STATE_IDLE;
http_op.http_op_state = HTTP_STATE_IDLE;
http_ops = h;
@ -59,6 +62,10 @@ int SCHEDULER_OP::start_rpc() {
}
int SCHEDULER_OP::start_op(PROJECT* p) {
if(p==NULL) {
fprintf(stderr, "error: SCHEDULER_OP.start_op: unexpected NULL pointer p\n");
return ERR_NULL;
}
project = p;
if (project->scheduler_urls.size() == 0) {
http_op.init_get(project->master_url, MASTER_FILE_NAME);
@ -143,7 +150,10 @@ SCHEDULER_REPLY::~SCHEDULER_REPLY() {
int SCHEDULER_REPLY::parse(FILE* in) {
char buf[256];
int retval;
if(in==NULL) {
fprintf(stderr, "error: SCHEDULER_REPLY.parse: unexpected NULL pointer in\n");
return ERR_NULL;
}
strcpy(message, "");
strcpy(message_priority, "");
request_delay = 0;
@ -172,7 +182,11 @@ int SCHEDULER_REPLY::parse(FILE* in) {
if (retval) return ERR_XML_PARSE;
} else if (match_tag(buf, "<code_sign_key>")) {
retval = dup_element_contents(in, "</code_sign_key>", &code_sign_key);
if (retval) return ERR_XML_PARSE;
//fprintf(stderr, "code_sign_key: %s\n", code_sign_key);
if (retval) {
fprintf(stderr, "error: SCHEDULER_REPLY.parse: xml parsing error\n");
return ERR_XML_PARSE;
}
} else if (match_tag(buf, "<code_sign_key_signature>")) {
retval = dup_element_contents(in, "</code_sign_key_signature>", &code_sign_key_signature);
if (retval) return ERR_XML_PARSE;

View File

@ -4,6 +4,7 @@
#include <time.h>
#include "speed_stats.h"
#include "error_numbers.h"
#define D_FLOP_ITERS 1
#define I_OP_ITERS 1
@ -32,7 +33,10 @@ int check_cache_size( int mem_size ) {
clock_t total_sec, sec;
double secs, nanosecs, temp2;
int not_found;
if(mem_size<0) {
fprintf(stderr, "error: check_cache_size: negative mem_size\n");
return ERR_NEG;
}
logStride = (int)(log(STRIDE_MAX/STRIDE_MIN)/log(2))+1;
logCache = (int)(log(CACHE_MAX/CACHE_MIN)/log(2))+1;
@ -162,7 +166,10 @@ int check_cache_size( int mem_size ) {
double run_double_prec_test( double num_secs ) {
int df_test_time, df_iters;
double df_secs;
if(num_secs<0) {
fprintf(stderr, "error: run_double_prec_test: negatvie num_secs\n");
return ERR_NEG;
}
// Start by doing some quick timing tests for rough calibration
df_test_time = (int)double_flop_test( D_FLOP_ITERS, 0 );
if( df_test_time <= 0 ) df_test_time = 1;
@ -185,7 +192,10 @@ double run_double_prec_test( double num_secs ) {
double run_int_test( double num_secs ) {
int int_test_time, int_iters;
double int_secs;
if(num_secs<0) {
fprintf(stderr, "error: run_int_test: negative num_secs\n");
return ERR_NEG;
}
// Start by doing some quick timing tests for rough calibration
int_test_time = (int)int_op_test( I_OP_ITERS, 0 );
if( int_test_time <= 0 ) int_test_time = 1;
@ -209,7 +219,10 @@ double run_mem_bandwidth_test( double num_secs ) {
int bw_test_time;
double bw_secs;
int bw_iters;
if(num_secs<0) {
fprintf(stderr, "error: run_mem_bandwidth_test: negative num_secs\n");
return ERR_NEG;
}
// Start by doing some quick timing tests for rough calibration
bw_test_time = (int)bandwidth_test( BANDWIDTH_ITERS, 0 );
if( bw_test_time <= 0 ) bw_test_time = 1;
@ -229,6 +242,9 @@ double run_mem_bandwidth_test( double num_secs ) {
}
void run_test_suite( double num_secs_per_test ) {
if(num_secs_per_test<0) {
fprintf(stderr, "error: run_test_suite: negative num_seconds_per_test\n");
}
printf(
"Running tests. This will take about %.1lf seconds.\n\n",
num_secs_per_test*3
@ -255,7 +271,10 @@ clock_t double_flop_test( int iterations, int print_debug ) {
double temp;
clock_t time_start, time_total;
int i,j,k,calc_error;
if(iterations<0) {
fprintf(stderr, "error: double_flop_test: negative iterations\n");
return ERR_NEG;
}
// Initialize the array
a[0] = 1;
for( i=1;i<NUM_DOUBLES;i++ )
@ -315,7 +334,10 @@ clock_t int_op_test( int iterations, int print_debug ) {
int a[NUM_INTS], temp;
clock_t time_start, time_total;
int i,j,k,calc_error;
if(iterations<0) {
fprintf(stderr, "error: int_op_test: negative iterations\n");
return ERR_NEG;
}
a[0] = 1;
for( i=1;i<NUM_INTS;i++ ) {
a[i] = 2*a[i-1];
@ -390,7 +412,10 @@ clock_t bandwidth_test( int iterations, int print_debug ) {
// Start and stop times for the clock
clock_t time_start, time_total;
int i,j,copy_error;
if(iterations<0) {
fprintf(stderr, "error: bandwidth_test: negative iterations\n");
return ERR_NEG;
}
// These are doubles in order to make full use of bus and instruction bandwidth
a = (double *)malloc( MEM_SIZE * sizeof( double ) );
b = (double *)malloc( MEM_SIZE * sizeof( double ) );

View File

@ -100,7 +100,10 @@ int TIME_STATS::write(FILE* out, bool to_server) {
int TIME_STATS::parse(FILE* in) {
char buf[256];
if(in==NULL) {
fprintf(stderr, "error: TIME_STATS.parse: unexpected NULL pointer in\n");
return ERR_NULL;
}
while (fgets(buf, 256, in)) {
if (match_tag(buf, "</time_stats>")) return 0;
else if (parse_int(buf, "<last_update>", last_update)) continue;

View File

@ -16,6 +16,7 @@
//
// Contributor(s):
//
#include <stdio.h>
#ifndef _WIN32
#include <sys/time.h>
@ -24,11 +25,19 @@
#include <time.h>
#include <windows.h>
#include "error_numbers.h"
/* Replacement gettimeofday
Sets the microseconds to clock() * 1000 which is microseconds in Windows */
void gettimeofday(timeval *t, void *tz) {
t->tv_sec = time(NULL);
t->tv_usec = 1000 * (long)(clock());
if(t==NULL) {
fprintf(stderr, "error: gettimeofday: unexpected NULL pointer t\n");
}
if(tz==NULL) {
fprintf(stderr, "error: gettimeofday: unexpected NULL pointer tz\n");
}
t->tv_sec = time(NULL);
t->tv_usec = 1000 * (long)(clock());
}
#endif
@ -45,13 +54,21 @@ double dtime() {
#ifdef _WIN32
void boinc_sleep( int seconds ) {
::Sleep( 1000*seconds );
if(seconds<0) {
fprintf(stderr, "error: boinc_sleep: negative seconds\n");
seconds=0;
}
::Sleep( 1000*seconds );
}
#else
void boinc_sleep( int seconds ) {
sleep( seconds );
if(seconds<0) {
fprintf(stderr,"error: boinc_sleep: negative seconds\n");
seconds=0;
}
sleep( seconds );
}
#endif

2
configure vendored
View File

@ -1386,7 +1386,7 @@ EOF
fi
for ac_hdr in fcntl.h strings.h sys/time.h unistd.h sys/systeminfo.h sys/resource.h sys/types.h dirent.h sys/utsname.h netdb.h netinet/in.h arpa/inet.h
for ac_hdr in fcntl.h strings.h sys/time.h unistd.h sys/systeminfo.h sys/resource.h sys/types.h dirent.h sys/utsname.h netdb.h netinet/in.h arpa/inet.h signal.h sys/wait.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6

View File

@ -23,7 +23,7 @@ dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h strings.h sys/time.h unistd.h sys/systeminfo.h sys/resource.h sys/types.h dirent.h sys/utsname.h netdb.h netinet/in.h arpa/inet.h)
AC_CHECK_HEADERS(fcntl.h strings.h sys/time.h unistd.h sys/systeminfo.h sys/resource.h sys/types.h dirent.h sys/utsname.h netdb.h netinet/in.h arpa/inet.h signal.h sys/wait.h)
AC_CHECK_HEADERS(mysql/include/mysql_com.h mysql/mysql_com.h)
dnl Checks for typedefs, structures, and compiler characteristics.

View File

@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "mysql_util.h"
@ -52,7 +53,8 @@ void struct_to_str(void* vp, char* q, int type) {
HOST* hp;
WORKUNIT* wup;
RESULT* rp;
assert(vp!=NULL);
assert(q!=NULL);
switch(type) {
case TYPE_PLATFORM:
pp = (PLATFORM*)vp;
@ -198,7 +200,7 @@ void row_to_struct(MYSQL_ROW& r, void* vp, int type) {
RESULT* rp;
int i=0;
assert(vp!=NULL);
switch(type) {
case TYPE_PLATFORM:
pp = (PLATFORM*)vp;
@ -381,7 +383,7 @@ int db_app_version_lookup(
int appid, int platformid, int version_num, APP_VERSION& p
) {
char buf[256];
assert(version_num>=0);
sprintf(buf,
"appid=%d and platformid=%d and version_num=%d",
appid, platformid, version_num

View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "mysql.h"
#include "mysql_util.h"
@ -39,6 +40,7 @@ static MYSQL_ROW row;
#define MAX_QUERY_LEN 8192
int db_open(char* name) {
//assert(name!=NULL);
mp = mysql_init(0);
if (!mp) return -1;
mp = mysql_real_connect(mp, 0, 0, "", name, 0, 0, 0);
@ -52,6 +54,7 @@ int db_close() {
}
void db_print_error(char* p) {
assert(p!=NULL);
if (mp) {
printf("<br>%s: Database error: %s\n", p, mysql_error(mp));
}
@ -59,6 +62,7 @@ void db_print_error(char* p) {
// convert ' to \' in place
void escape(char* field) {
assert(field!=NULL);
char buf[MAX_QUERY_LEN];
char* q = buf, *p = field;
while (*p) {
@ -76,6 +80,7 @@ void escape(char* field) {
void unescape(char* p) {
char* q;
assert(p!=NULL);
while (1) {
q = strstr(p, "\\'");
if (!q) break;
@ -85,11 +90,13 @@ void unescape(char* p) {
// assumes ID is first
static int* id(void* vp, int type) {
assert(vp!=NULL);
return (int*) vp;
}
int db_new(void* vp, int type) {
char buf[MAX_QUERY_LEN], sbuf[MAX_QUERY_LEN];
assert(vp!=NULL);
struct_to_str(vp, sbuf, type);
sprintf(buf, "insert into %s set %s", table_name[type], sbuf);
return mysql_query(mp, buf);
@ -111,6 +118,7 @@ int db_delete(int id, int type) {
int db_lookup_id(int i, void* vp, int type) {
char buf[MAX_QUERY_LEN];
assert(vp!=NULL);
sprintf(buf, "select * from %s where id=%d", table_name[type], i);
mysql_query(mp, buf);
rp = mysql_store_result(mp);
@ -123,6 +131,8 @@ int db_lookup_id(int i, void* vp, int type) {
int db_lookup(void* vp, int type, char* clause) {
char buf[MAX_QUERY_LEN];
assert(vp!=NULL);
assert(clause!=NULL);
sprintf(buf, "select * from %s where %s", table_name[type], clause);
mysql_query(mp, buf);
rp = mysql_store_result(mp);
@ -135,6 +145,7 @@ int db_lookup(void* vp, int type, char* clause) {
int db_update(void* vp, int type) {
char buf[MAX_QUERY_LEN], sbuf[MAX_QUERY_LEN];
assert(vp!=NULL);
struct_to_str(vp, sbuf, type);
sprintf(
buf,
@ -145,7 +156,9 @@ int db_update(void* vp, int type) {
}
int db_enum(ENUM& e, void* p, int type, char* clause, int limit) {
char buf[MAX_QUERY_LEN], buf2[256];;
char buf[MAX_QUERY_LEN], buf2[256];
//assert(p!=NULL);
//assert(clause!=NULL);
if (!e.active) {
e.active = 1;
sprintf(buf, "select * from %s %s", table_name[type], clause?clause:"");
@ -170,6 +183,8 @@ int db_enum(ENUM& e, void* p, int type, char* clause, int limit) {
int db_enum_field(ENUM& e, int type, char* field, char* clause) {
char buf[MAX_QUERY_LEN];
assert(field!=NULL);
assert(clause!=NULL);
if (!e.active) {
e.active = 1;
sprintf(buf, "select %s from %s %s", field, table_name[type], clause);
@ -188,6 +203,8 @@ int db_enum_field(ENUM& e, int type, char* field, char* clause) {
}
int db_query_int(int* ip, char* query) {
assert(ip!=NULL);
assert(query!=NULL);
mysql_query(mp, query);
rp = mysql_store_result(mp);
if (!rp) return -1;
@ -200,6 +217,9 @@ int db_query_int(int* ip, char* query) {
int db_count(int* np, char* what, int type, char* clause) {
char buf[MAX_QUERY_LEN];
assert(np!=NULL);
assert(what!=NULL);
assert(clause!=NULL);
sprintf(buf, "select count(%s) from %s %s", what, table_name[type], clause);
return db_query_int(np, buf);
}

View File

@ -3,6 +3,7 @@
#include "md5_file.h"
#include "crypt.h"
#include "error_numbers.h"
// NOTE: the fast CGI I/O library doesn't have fscanf(),
// so some of the following have been modified to use
@ -13,22 +14,29 @@
// we follow the data with a non-hex character '.'
//
int print_hex_data(FILE* f, DATA_BLOCK& x) {
int i;
unsigned int i;
if(f==NULL) {
fprintf(stderr, "error: print_hex_data: unexpected NULL pointer f\n");
return ERR_NULL;
}
for (i=0; i<x.len; i++) {
fprintf(f, "%02x", x.data[i]);
if (i%32==31) fprintf(f, "\n");
}
if (x.len%32 != 0) fprintf(f, "\n");
fprintf(f, ".\n");
return 0;
}
// same, but write to buffer
//
int sprint_hex_data(char* p, DATA_BLOCK& x) {
int i;
unsigned int i;
char buf[16];
if(p==NULL) {
fprintf(stderr, "error: sprint_hex_data: unexpected NULL pointer p\n");
return ERR_NULL;
}
strcpy(p, "");
for (i=0; i<x.len; i++) {
sprintf(buf, "%02x", x.data[i]);
@ -37,6 +45,7 @@ int sprint_hex_data(char* p, DATA_BLOCK& x) {
}
if (x.len%32 != 0) strcat(p, "\n");
strcat(p, ".\n");
return 0;
}
// scan data in hex notation.
@ -46,9 +55,13 @@ int sprint_hex_data(char* p, DATA_BLOCK& x) {
int scan_hex_data(FILE* f, DATA_BLOCK& x) {
int n;
x.len = 0;
if(f==NULL) {
fprintf(stderr, "error: scan_hex_data: unexpected NULL pointer f\n");
return ERR_NULL;
}
#if _USING_FCGI_
char *p, buf[256];
int i, j, n;
int i, j;
while (1) {
p = fgets(buf, 256, f);
if (!p) return -1;
@ -73,6 +86,14 @@ int scan_hex_data(FILE* f, DATA_BLOCK& x) {
// same, but read from buffer
//
int sscan_hex_data(char* p, DATA_BLOCK& x) {
if(p==NULL) {
fprintf(stderr, "error: sscan_hex_data: unexpected NULL pointer p\n");
return ERR_NULL;
}
if(x.len<0) {
fprintf(stderr, "error: sscan_hex_data: negative x.len\n");
return ERR_NEG;
}
int m, n, nleft=x.len;
x.len = 0;
while (1) {
@ -93,9 +114,20 @@ int sscan_hex_data(char* p, DATA_BLOCK& x) {
// print a key in ASCII form
//
int print_key_hex(FILE* f, KEY* key, int size) {
int len, i;
int len;
DATA_BLOCK x;
if(f==NULL) {
fprintf(stderr, "error: print_key_hex: unexpected NULL pointer f\n");
return ERR_NULL;
}
if(key==NULL) {
fprintf(stderr, "error: print_key_hex: unexpected NULL pointer key\n");
return ERR_NULL;
}
if(size<0) {
fprintf(stderr, "error: print_key_hex: negative size\n");
return ERR_NEG;
}
fprintf(f, "%d\n", key->bits);
len = size - sizeof(key->bits);
x.data = key->data;
@ -106,9 +138,21 @@ int print_key_hex(FILE* f, KEY* key, int size) {
int scan_key_hex(FILE* f, KEY* key, int size) {
int len, i, n;
int num_bits;
if(f==NULL) {
fprintf(stderr, "error: scan_key_hex: unexpected NULL pointer f\n");
return ERR_NULL;
}
if(key==NULL) {
fprintf(stderr, "error: scan_key_hex: unexpected NULL pointer key\n");
return ERR_NULL;
}
if(size<=0) {
fprintf(stderr, "error: scan_key_hex: size = %d\n", size);
return ERR_NEG;
}
#if _USING_FCGI_
char buf[256];
#if 0
char *p, buf[256];
int j = 0, b;
fgets(buf, 256, f);
sscanf(buf, "%d", &num_bits);
@ -127,6 +171,7 @@ int scan_key_hex(FILE* f, KEY* key, int size) {
}
fgets(buf, size, f);
sscanf(buf, ".");
#endif
#else
fscanf(f, "%d", &num_bits);
key->bits = num_bits;
@ -143,16 +188,30 @@ int scan_key_hex(FILE* f, KEY* key, int size) {
// parse a text-encoded key from a memory buffer
//
int sscan_key_hex(char* buf, KEY* key, int size) {
int n, retval;
int n, retval,num_bits;
DATA_BLOCK db;
n = sscanf(buf, "%d", &key->bits);
if(buf==NULL) {
fprintf(stderr, "error: sscan_key_hex: unexpected NULL pointer buf\n");
return ERR_NULL;
}
if(key==NULL) {
fprintf(stderr, "error: sscan_key_hex: unexpected NULL pointer key\n");
return ERR_NULL;
}
if(size<=0) {
fprintf(stderr, "error: sscan_key_hex: size = %d\n", size);
return ERR_NEG;
}
//fprintf(stderr, "buf = %s\n", buf);
n = sscanf(buf, "%d", &num_bits);
key->bits = num_bits; //key->bits is a short
//fprintf(stderr, "key->bits = %d\n", key->bits);
if (n != 1) return -1;
buf = strchr(buf, '\n');
if (!buf) return -1;
buf += 1;
db.data = key->data;
db.len = size - sizeof(key->bits);
db.len = size - sizeof(key->bits); //huh???
retval = sscan_hex_data(buf, db);
return retval;
}
@ -179,6 +238,10 @@ int encrypt_private(
}
int decrypt_public(R_RSA_PUBLIC_KEY& key, DATA_BLOCK& in, DATA_BLOCK& out) {
if(key.bits<=0) {
fprintf(stderr, "error: decrypt_public: key.bits = %d\n", key.bits);
return ERR_NEG;
}
return RSAPublicDecrypt(out.data, &out.len, in.data, in.len, &key);
}
@ -187,7 +250,10 @@ int sign_file(char* path, R_RSA_PRIVATE_KEY& key, DATA_BLOCK& signature) {
double file_length;
DATA_BLOCK in_block;
int retval, n;
if(path==NULL) {
fprintf(stderr, "error: sign_file: unexpected NULL pointer path\n");
return ERR_NULL;
}
retval = md5_file(path, md5_buf, file_length);
if (retval) return retval;
in_block.data = (unsigned char*)md5_buf;
@ -220,14 +286,23 @@ int verify_file(
double file_length;
int n, retval;
DATA_BLOCK clear_signature;
if(path==NULL) {
fprintf(stderr, "error: verify_file: unexpected NULL pointer path\n");
return ERR_NULL;
}
retval = md5_file(path, md5_buf, file_length);
if (retval) return retval;
if (retval) {
fprintf(stderr, "error: verify_file: md5_file error %d\n", retval);
return retval;
}
n = strlen(md5_buf);
clear_signature.data = (unsigned char*)clear_buf;
clear_signature.len = MD5_LEN;
retval = decrypt_public(key, signature, clear_signature);
if (retval) return retval;
if (retval) {
fprintf(stderr, "error: verify_file: decrypt_public error %d\n", retval);
return retval;
}
answer = !strncmp(md5_buf, clear_buf, n);
return 0;
}
@ -239,9 +314,23 @@ int verify_file2(
unsigned char signature_buf[SIGNATURE_SIZE_BINARY];
int retval;
DATA_BLOCK signature;
if(path==NULL) {
fprintf(stderr, "error: verify_file2: unexpected NULL pointer path\n");
return ERR_NULL;
}
if(signature_text==NULL) {
fprintf(stderr, "error: verify_file2: unexpected NULL pointer signature_text\n");
return ERR_NULL;
}
if(key_text==NULL) {
fprintf(stderr, "error: verify_file2: unexpected NULL pointer key_text\n");
return ERR_NULL;
}
retval = sscan_key_hex(key_text, (KEY*)&key, sizeof(key));
if (retval) return retval;
if (retval) {
fprintf(stderr, "error: verify_file2: sscan_key_hex did not work\n");
return retval;
}
signature.data = signature_buf;
signature.len = sizeof(signature_buf);
sscan_hex_data(signature_text, signature);
@ -258,7 +347,14 @@ int verify_string(
char clear_buf[MD5_LEN];
int retval, n;
DATA_BLOCK signature, clear_signature;
if(text==NULL) {
fprintf(stderr, "error: verify_string: unexpected NULL pointer text\n");
return ERR_NULL;
}
if(signature_text==NULL) {
fprintf(stderr, "error: verify_string: unexpected NULL pointer signature_text\n");
return ERR_NULL;
}
retval = md5_block((unsigned char*)text, strlen(text), md5_buf);
if (retval) return retval;
n = strlen(md5_buf);

4
client/error_numbers.h → lib/error_numbers.h Normal file → Executable file
View File

@ -33,3 +33,7 @@
#define ERR_GETHOSTBYNAME -113
#define ERR_GIVEUP -114
// too much time has elapsed without progress on file xfer
#define ERR_NULL -115
// unexpected NULL pointer
#define ERR_NEG -116
// unexpected negative value

View File

@ -2,6 +2,7 @@
#include "md5.h"
#include "md5_file.h"
#include "error_numbers.h"
int md5_file(char* path, char* output, double& nbytes) {
unsigned char buf[4096];
@ -9,7 +10,14 @@ int md5_file(char* path, char* output, double& nbytes) {
FILE* f;
md5_state_t state;
int i, n;
if(path==NULL) {
fprintf(stderr, "error: md5_file: unexpected NULL pointer path\n");
return ERR_NULL;
}
if(output==NULL) {
fprintf(stderr, "error: md5_file: unexpected NULL pointer output\n");
return ERR_NULL;
}
nbytes = 0;
f = fopen(path, "rb");
if (!f) {
@ -36,7 +44,18 @@ int md5_file(char* path, char* output, double& nbytes) {
int md5_block(unsigned char* data, int nbytes, char* output) {
unsigned char binout[16];
int i;
if(data==NULL) {
fprintf(stderr, "error: md5_block: unexpected NULL pointer data\n");
return ERR_NULL;
}
if(nbytes<0) {
fprintf(stderr, "error: md5_block: negative nbytes\n");
return ERR_NEG;
}
if(output==NULL) {
fprintf(stderr, "error: md5_block: unexpected NULL pointer output\n");
return ERR_NULL;
}
md5_state_t state;
md5_init(&state);
md5_append(&state, data, nbytes);

View File

@ -32,13 +32,30 @@
#include <stdlib.h>
#include "parse.h"
#include "error_numbers.h"
bool match_tag(char* buf, char* tag) {
if(buf==NULL) {
fprintf(stderr, "error: match_tag: unexpected NULL pointer buf\n");
return false;
}
if(tag==NULL) {
fprintf(stderr, "error: match_tag: unexpected NULL pointer tag\n");
return false;
}
if (strstr(buf, tag)) return true;
return false;
}
bool parse_int(char* buf, char* tag, int& x) {
if(buf==NULL) {
fprintf(stderr, "error: parse_int: unexpected NULL pointer buf\n");
return false;
}
if(tag==NULL) {
fprintf(stderr, "error: parse_int: unexpected NULL pointer tag\n");
return false;
}
char* p = strstr(buf, tag);
if (!p) return false;
x = atoi(p+strlen(tag));
@ -46,6 +63,14 @@ bool parse_int(char* buf, char* tag, int& x) {
}
bool parse_double(char* buf, char* tag, double& x) {
if(buf==NULL) {
fprintf(stderr, "error: parse_double: unexpected NULL pointer buf\n");
return false;
}
if(tag==NULL) {
fprintf(stderr, "error: parse_double: unexpected NULL pointer tag\n");
return false;
}
char* p = strstr(buf, tag);
if (!p) return false;
x = atof(p+strlen(tag));
@ -53,6 +78,18 @@ bool parse_double(char* buf, char* tag, double& x) {
}
bool parse_str(char* buf, char* tag, char* x) {
if(buf==NULL) {
fprintf(stderr, "error: parse_str: unexpected NULL pointer buf\n");
return false;
}
if(tag==NULL) {
fprintf(stderr, "error: parse_str: unexpected NULL pointer tag\n");
return false;
}
if(x==NULL) {
fprintf(stderr, "error: parse_str: unexpected NULL pointer x\n");
return false;
}
char* p = strstr(buf, tag);
if (!p) return false;
p = strchr(p, '>');
@ -64,7 +101,15 @@ bool parse_str(char* buf, char* tag, char* x) {
void parse_attr(char* buf, char* name, char* out) {
char* p, *q;
if(buf==NULL) {
fprintf(stderr, "error: parse_attr: unexpected NULL pointer buf\n");
}
if(name==NULL) {
fprintf(stderr, "error: parse_attr: unexpected NULL pointer name\n");
}
if(out==NULL) {
fprintf(stderr, "error: parse_attr: unexpected NULL pointer out\n");
}
strcpy(out, "");
p = strstr(buf, name);
if (!p) return;
@ -79,7 +124,12 @@ void parse_attr(char* buf, char* name, char* out) {
void copy_stream(FILE* in, FILE* out) {
char buf[1024];
int n, m;
if(in==NULL) {
fprintf(stderr, "error: copy_stream: unexpected NULL pointer in\n");
}
if(out==NULL) {
fprintf(stderr, "error: copy_stream: unexpected NULL pointer out\n");
}
while (1) {
n = fread(buf, 1, 1024, in);
m = fwrite(buf, 1, n, out);
@ -88,6 +138,9 @@ void copy_stream(FILE* in, FILE* out) {
}
void strcatdup(char*& p, char* buf) {
if(buf==NULL) {
fprintf(stderr, "error: strcatdup: unexpected NULL pointer buf\n");
}
p = (char*)realloc(p, strlen(p) + strlen(buf)+1);
if (!p) {
fprintf(stderr, "strcatdup: realloc failed\n");
@ -98,7 +151,18 @@ void strcatdup(char*& p, char* buf) {
int dup_element_contents(FILE* in, char* end_tag, char** pp) {
char buf[256];
if(in==NULL) {
fprintf(stderr, "error: dup_element_contents: unexpected NULL pointer in\n");
return ERR_NULL;
}
if(end_tag==NULL) {
fprintf(stderr, "error: dup_element_contents: unexpected NULL pointer end_tag\n");
return ERR_NULL;
}
if(pp==NULL) {
fprintf(stderr, "error: dup_element_contents: unexpected NULL pointer pp\n");
return ERR_NULL;
}
char* p = strdup("");
while (fgets(buf, 256, in)) {
if (strstr(buf, end_tag)) {

View File

@ -1,11 +1,13 @@
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <assert.h>
#include "shmem.h"
int create_shmem(key_t key, int size, void** pp){
int id;
assert(pp!=NULL);
id = shmget(key, size, IPC_CREAT|0777);
if (id < 0) {
perror("create_shmem: shmget");
@ -41,7 +43,7 @@ int destroy_shmem(key_t key){
int attach_shmem(key_t key, void** pp){
void* p;
int id;
assert(pp!=NULL);
id = shmget(key, 0, 0);
if (id < 0) {
perror("attach_shmem: shmget");
@ -58,7 +60,7 @@ int attach_shmem(key_t key, void** pp){
int detach_shmem(void* p) {
int retval;
assert(p!=NULL);
retval = shmdt((char *)p);
if (retval) perror("detach_shmem: shmdt");
return retval;

View File

@ -5,12 +5,18 @@ VPATH = @srcdir@
all: cgi
ifndef BOINC_KEY
BOINC_KEY = 0xdadacafe
endif
CFLAGS = -g -Wall @DEFS@ \
-I@top_srcdir@/db \
-I@top_srcdir@/lib \
-I@top_srcdir@/RSAEuro/source \
-I@top_srcdir@/tools \
-I/usr/local/mysql/include
-I/usr/local/mysql/include \
-DBOINC_KEY_DIR=\"$(BOINC_KEY_DIR)\" \
-DBOINC_KEY=$(BOINC_KEY)
CC = g++ $(CFLAGS)

View File

@ -42,6 +42,7 @@
// has completed the request.
#include <stdio.h>
#include <assert.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
@ -56,7 +57,7 @@
int check_trigger(SCHED_SHMEM* ssp) {
FILE* f;
char buf[256];
assert(ssp!=NULL);
f = fopen(TRIGGER_FILENAME, "r");
if (!f) return 0;
fread(buf, 1, 256, f);
@ -97,7 +98,7 @@ void feeder_loop(SCHED_SHMEM* ssp) {
RESULT result;
WORKUNIT wu;
bool no_wus, collision, restarted_enum;
assert(ssp!=NULL);
while (1) {
nadditions = 0;
ncollisions = 0;

View File

@ -20,6 +20,7 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "parse.h"
#include "crypt.h"
@ -40,7 +41,7 @@ struct FILE_INFO {
int FILE_INFO::parse(FILE* in) {
char buf[256];
int retval;
assert(in!=NULL);
memset(this, 0, sizeof(FILE_INFO));
signed_xml = strdup("");
while (fgets(buf, 256, in)) {
@ -59,6 +60,7 @@ int FILE_INFO::parse(FILE* in) {
}
int print_status(int status, char* message) {
assert(message!=NULL);
printf("Content-type: text/plain\n\n<status>%d</status>\n", status);
if (message) printf("<error>%s</error>\n", message);
#if 0
@ -77,7 +79,10 @@ int copy_socket_to_file(FILE* in, char* path, double offset, double nbytes) {
FILE* out;
int retval, n, m;
double bytes_left;
assert(in!=NULL);
assert(path!=NULL);
assert(offset>=0);
assert(nbytes>=0);
out = fopen(path, "wb");
if (!out) {
print_status(-1, "can't open file");
@ -119,7 +124,7 @@ int handle_request(FILE* in, R_RSA_PUBLIC_KEY& key) {
FILE_INFO file_info;
int retval;
bool is_valid;
assert(in!=NULL);
while (fgets(buf, 256, in)) {
if (match_tag(buf, "<file_info>")) {
retval = file_info.parse(in);

View File

@ -21,6 +21,7 @@
#include <unistd.h>
#include <sys/wait.h>
#include <time.h>
#include <assert.h>
#include "db.h"
#include "backend_lib.h"
@ -48,6 +49,7 @@ double estimate_duration(WORKUNIT& wu, HOST& host) {
//inserts an xml tag in xml_doc with an estimation of how many seconds
//a workunit will take to complete
int insert_time_tag(WORKUNIT& wu, double seconds) {
assert(seconds>=0);
char *location;
location = strstr(wu.xml_doc, "</workunit>");
if ((location - wu.xml_doc) > (MAX_BLOB_SIZE - 64)) {
@ -72,7 +74,7 @@ int add_wu_to_reply(
APP* app;
APP_VERSION* app_version;
int retval;
assert(seconds_to_complete>=0);
app = ss.lookup_app(wu.appid);
if (!app) return -1;
app_version = ss.lookup_app_version(app->id, platform.id, app->prod_vers);
@ -448,7 +450,8 @@ void handle_request(
) {
SCHEDULER_REQUEST sreq;
SCHEDULER_REPLY sreply;
assert(fin!=NULL);
assert(fout!=NULL);
memset(&sreq, 0, sizeof(sreq));
sreq.parse(fin);

View File

@ -20,6 +20,7 @@
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include "db.h"
#include "parse.h"
@ -29,9 +30,9 @@
#define REQ_FILE_PREFIX "/tmp/boinc_req_"
#define REPLY_FILE_PREFIX "/tmp/boinc_reply_"
#define BOINC_KEY_DIR "/home/david/boinc_keys"
int return_error(char* p) {
assert(p!=NULL);
fprintf(stderr, "BOINC server: %s\n", p);
printf("<error_msg>%s</error_msg>\n", p);
return 1;

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "db.h"
@ -33,6 +34,7 @@ int SCHED_SHMEM::verify() {
}
static void overflow(char* table) {
assert(table!=NULL);
fprintf(stderr,
"The SCHED_SHMEM structure is too small for table %s.\n"
"Increase the size and restart feeder and fcgi.\n",
@ -72,7 +74,7 @@ int SCHED_SHMEM::scan_tables() {
PLATFORM* SCHED_SHMEM::lookup_platform(char* name) {
int i;
assert(name!=NULL);
for (i=0; i<nplatforms; i++) {
if (!strcmp(platforms[i].name, name)) {
return &platforms[i];
@ -97,7 +99,7 @@ APP_VERSION* SCHED_SHMEM::lookup_app_version(
) {
int i;
APP_VERSION* avp;
assert(version>=0);
for (i=0; i<napp_versions; i++) {
avp = &app_versions[i];
if (avp->appid == appid && avp->platformid == platformid && avp->version_num == version) {

View File

@ -1,6 +1,8 @@
#include "db.h"
#ifndef BOINC_KEY
#define BOINC_KEY 0xdadacafe
#endif
#define MAX_PLATFORMS 50
#define MAX_APPS 10

View File

@ -18,6 +18,7 @@
//
#include <strings.h>
#include <assert.h>
#include "parse.h"
#include "server_types.h"
@ -35,7 +36,7 @@ SCHEDULER_REQUEST::~SCHEDULER_REQUEST() {
int SCHEDULER_REQUEST::parse(FILE* fin) {
char buf[256];
RESULT result;
assert(fin!=NULL);
prefs_mod_time = 0;
strcpy(authenticator, "");
hostid = 0;
@ -105,7 +106,7 @@ SCHEDULER_REPLY::~SCHEDULER_REPLY() {
int SCHEDULER_REPLY::write(FILE* fout) {
unsigned int i, j;
assert(fout!=NULL);
fprintf(fout,
"<scheduler_reply>\n"
);
@ -223,7 +224,7 @@ int APP_VERSION::write(FILE* fout, APP& app) {
int RESULT::parse_from_client(FILE* fin) {
char buf[256];
assert(fin!=NULL);
memset(this, 0, sizeof(RESULT));
while (fgets(buf, 256, fin)) {
if (match_tag(buf, "</result>")) return 0;
@ -257,7 +258,7 @@ int RESULT::parse_from_client(FILE* fin) {
int HOST::parse(FILE* fin) {
char buf[256];
assert(fin!=NULL);
while (fgets(buf, 256, fin)) {
if (match_tag(buf, "</host_info>")) return 0;
else if (parse_int(buf, "<timezone>", timezone)) continue;
@ -288,7 +289,7 @@ int HOST::parse(FILE* fin) {
int HOST::parse_time_stats(FILE* fin) {
char buf[256];
assert(fin!=NULL);
while (fgets(buf, 256, fin)) {
if (match_tag(buf, "</time_stats>")) return 0;
else if (parse_double(buf, "<on_frac>", on_frac)) continue;
@ -334,7 +335,7 @@ int DB_CACHE::read_db() {
PLATFORM* DB_CACHE::lookup_platform(char* name) {
unsigned int i;
assert(name!=NULL);
for (i=0; i<platforms.size(); i++) {
if (!strcmp(platforms[i].name, name)) {
return &platforms[i];
@ -359,7 +360,7 @@ APP_VERSION* DB_CACHE::lookup_app_version(
) {
unsigned int i;
APP_VERSION* avp;
assert(version>=0);
for (i=0; i<app_versions.size(); i++) {
avp = &app_versions[i];
if (avp->appid == appid && avp->platformid == platformid && avp->version_num == version) {

View File

@ -1,3 +1 @@
<h3>Test BOINC Project</h3>
<scheduler>http://localhost/boinc-cgi/cgi</scheduler>
<scheduler>http://maggie.ssl.berkeley.edu/cgi-bin/boinc-cgi/mgary/fcgi</scheduler>

View File

@ -1,2 +0,0 @@
<hi_water_secs>2592000</hi_water_secs>
<lo_water_secs>1</lo_water_secs>

View File

@ -1,2 +0,0 @@
<hi_water_secs>172800</hi_water_secs>
<lo_water_secs>300</lo_water_secs>

View File

@ -1,2 +0,0 @@
<hi_water_secs>172800</hi_water_secs>
<lo_water_secs>300</lo_water_secs>

View File

@ -4,7 +4,7 @@
<low_water_days>1</low_water_days>
<resource_share>1</resource_share>
<project>
<master_url>http://localhost/index.html</master_url>
<master_url>http://maggie.ssl.berkeley.edu/mgary_fcgi.html</master_url>
<authenticator>3f7b90793a0175ad0bda68684e8bd136</authenticator>
</project>
</preferences>

View File

@ -1,30 +0,0 @@
#! /usr/local/bin/php
<?php
// test preferences
//
include_once("init.inc");
clear_db();
clear_data_dirs();
create_keys();
init_client_dirs("prefs1.xml");
copy_to_download_dir("small_input");
add_platform();
add_core_client();
add_user("max_water_prefs.xml");
add_app("uc_slow");
create_work("-appname uc_slow -wu_name ucs_wu -wu_template ucs_wu -result_template ucs_result -nresults 1 small_input");
//will automatically run client instead
//echo "Now run the client manually; start and stop it a few times.\n";
//run_client();
//compare_file("ucs_wu_0_0", "uc_small_correct_output");
echo "starting feeder\n";
start_feeder();
echo "started feeder\n";
run_client();
echo "ran client\n";
stop_feeder();
//not sure what correct results should be, so will have to figure
//this out so can run diff
?>

View File

@ -1,30 +0,0 @@
#! /usr/local/bin/php
<?php
// test preferences
//
include_once("init.inc");
clear_db();
clear_data_dirs();
create_keys();
init_client_dirs("prefs1.xml");
copy_to_download_dir("small_input");
add_platform();
add_core_client();
add_user("min_water_prefs.xml");
add_app("uc_slow");
create_work("-appname uc_slow -wu_name ucs_wu -wu_template ucs_wu -result_template ucs_result -nresults 1 small_input");
//will automatically run client instead
//echo "Now run the client manually; start and stop it a few times.\n";
//run_client();
//compare_file("ucs_wu_0_0", "uc_small_correct_output");
echo "starting feeder\n";
start_feeder();
echo "started feeder\n";
run_client();
echo "ran client\n";
stop_feeder();
//not sure what correct results should be, so will have to figure
//this out so can run diff
?>

View File

@ -1,31 +0,0 @@
#! /usr/local/bin/php
<?php
// test preferences
//
include_once("init.inc");
clear_db();
clear_data_dirs();
create_keys();
init_client_dirs("prefs1.xml");
copy_to_download_dir("small_input");
add_platform();
add_core_client();
add_user("normal_water_prefs.xml");
add_app("upper_case");
create_work("-appname uc_slow -wu_name ucs_wu -wu_template ucs_wu -result_template ucs_result -nresults 1 small_input");
//echo "Now run the client manually; start and stop it a few times.\n";
//run_client();
//compare_file("ucs_wu_0_0", "uc_small_correct_output");
//This is so that the client will automatically run, instead of
//manually running
echo "starting feeder\n";
start_feeder();
echo "started feeder\n";
run_client();
echo "ran client\n";
stop_feeder();
//not sure what correct results should be, so will have to figure
//this out so can run diff
?>

View File

@ -40,6 +40,7 @@
#include "db.h"
#include "backend_lib.h"
#include "md5_file.h"
#include "crypt.h"
APP app;
PLATFORM platform;

View File

@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include "db.h"
#include "crypt.h"
@ -38,6 +39,8 @@
#define DOWNLOAD_URL "http://localhost/download/"
int read_file(FILE* f, char* buf) {
assert(f!=NULL);
assert(buf!=NULL);
int n = fread(buf, 1, MAX_BLOB_SIZE, f);
buf[n] = 0;
return 0;
@ -45,7 +48,8 @@ int read_file(FILE* f, char* buf) {
int read_filename(char* path, char* buf) {
int retval;
assert(path!=NULL);
assert(buf!=NULL);
FILE* f = fopen(path, "r");
if (!f) return -1;
retval = read_file(f, buf);
@ -66,7 +70,12 @@ static int process_wu_template(
bool found;
int i;
double nbytes;
assert(wu_name!=NULL);
assert(tmplate!=NULL);
assert(out!=NULL);
assert(dirpath!=NULL);
assert(infiles!=NULL);
assert(n>=0);
strcpy(out, tmplate);
while (1) {
found = false;
@ -129,7 +138,7 @@ int create_result(
char base_outfile_name[256];
int retval;
FILE* result_template_file, *tempfile;
assert(result_template_filename!=NULL);
memset(&r, 0, sizeof(r));
r.create_time = time(0);
r.workunitid = wu.id;
@ -167,7 +176,12 @@ int create_work(
R_RSA_PRIVATE_KEY& key
) {
int i, retval;
assert(wu_template!=NULL);
assert(result_template_file!=NULL);
assert(nresults>=0);
assert(infile_dir!=NULL);
assert(infiles!=NULL);
assert(ninfiles>=0);
wu.create_time = time(0);
retval = process_wu_template(
wu.name, wu_template, wu.xml_doc, infile_dir, infiles, ninfiles

View File

@ -26,6 +26,7 @@
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "db.h"
#include "parse.h"
@ -52,7 +53,11 @@ int process_result_template(
int i;
bool found;
assert(in!=NULL);
assert(out!=NULL);
assert(base_filename!=NULL);
assert(wu_name!=NULL);
assert(result_name!=NULL);
while (fgets(buf, 256, in)) {
// when we reach the end of a <file_info> element,