From 16b1305db7368cafdda0d7f08daca2e737d3be22 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 2 Jul 2008 17:24:53 +0000 Subject: [PATCH] - server code: at some point I made a global var "SCHED_CONFIG config", mostly so that the parse function could assume that everything was initially zero. However, various back-end functions pass around SCHED_CONFIG& as an argument (also named "config"). This creates a shadow, which is always bad. Worse is the possibility that some projects have back-end programs that have a SCHED_CONFIG variable that's automatic, and therefore isn't zero initially, and therefore isn't parsing correctly. To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers, and have the parse routine zero the structure. I was tempted to remove the SCHED_CONFIG& args to back-end functions, but this would have broken some projects' code. I did, however, change the name from config to config_loc to avoid shadowing. Also fixed various other compiler warnings. svn path=/trunk/boinc/; revision=15541 --- api/boinc_api.C | 2 +- apps/upper_case.C | 2 +- checkin_notes | 38 ++++++++++++++++++++++++++++++++ lib/shmem.C | 4 ++-- lib/shmem.h | 4 ++-- sched/handle_request.C | 12 +++++----- sched/sched_array.C | 2 -- sched/sched_assign.C | 5 ++--- sched/sched_config.C | 17 +++++++------- sched/sched_config.h | 4 ++-- sched/sched_send.C | 11 +++++----- sched/server_types.C | 5 ++--- tools/backend_lib.C | 39 +++++++++++++++------------------ tools/backend_lib.h | 2 +- tools/process_result_template.C | 6 ++--- 15 files changed, 93 insertions(+), 60 deletions(-) diff --git a/api/boinc_api.C b/api/boinc_api.C index e0b552af55..65c44de558 100644 --- a/api/boinc_api.C +++ b/api/boinc_api.C @@ -185,7 +185,7 @@ static int setup_shared_mem() { #else if (aid.shmem_seg_name == -1) { // Version 6 Unix/Linux/Mac client - if (attach_shmem_mmap( MMAPPED_FILE_NAME, (void**)&app_client_shm->shm)) { + if (attach_shmem_mmap(MMAPPED_FILE_NAME, (void**)&app_client_shm->shm)) { delete app_client_shm; app_client_shm = NULL; } diff --git a/apps/upper_case.C b/apps/upper_case.C index e4db3c8690..2dea016c6d 100644 --- a/apps/upper_case.C +++ b/apps/upper_case.C @@ -178,7 +178,7 @@ int main(int argc, char **argv) { // main loop - read characters, convert to UC, write // - for (int i=0; ; i++) { + for (i=0; ; i++) { c = fgetc(infile); if (c == EOF) break; diff --git a/checkin_notes b/checkin_notes index 68aee5c905..4c2409ba07 100644 --- a/checkin_notes +++ b/checkin_notes @@ -5362,3 +5362,41 @@ Charlie 2 July 2008 project.pbxproj win_build/ boincmgr_curl.vcproj + +David 2 July 2008 + - server code: at some point I made a global var "SCHED_CONFIG config", + mostly so that the parse function could assume + that everything was initially zero. + However, various back-end functions pass around SCHED_CONFIG& + as an argument (also named "config"). + This creates a shadow, which is always bad. + Worse is the possibility that some projects have back-end programs + that have a SCHED_CONFIG variable that's automatic, + and therefore isn't zero initially, + and therefore isn't parsing correctly. + + To fix this, I changed the 2 vectors in SCHED_CONFIG into pointers, + and have the parse routine zero the structure. + I was tempted to remove the SCHED_CONFIG& args to back-end functions, + but this would have broken some projects' code. + I did, however, change the name from config to config_loc + to avoid shadowing. + + Also fixed various other compiler warnings. + + api/ + boinc_api.C + apps/ + upper_case.C + lib/ + shmem.C,h + sched/ + handle_request.C + sched_array.C + sched_assign.C + sched_config.C,h + sched_send.C + server_types.C + tools/ + backend_lib.C,h + process_result_template.C diff --git a/lib/shmem.C b/lib/shmem.C index dce1a3c17f..814f455a86 100644 --- a/lib/shmem.C +++ b/lib/shmem.C @@ -301,7 +301,7 @@ int detach_shmem(void* p) { // V6 mmap() shared memory for Unix/Linux/Mac // -int create_shmem_mmap(char *path, size_t size, void** pp) { +int create_shmem_mmap(const char *path, size_t size, void** pp) { int fd, retval; struct stat sbuf; @@ -347,7 +347,7 @@ int destroy_shmem_mmap(key_t key){ } -int attach_shmem_mmap(char *path, void** pp) { +int attach_shmem_mmap(const char *path, void** pp) { int fd, retval; struct stat sbuf; diff --git a/lib/shmem.h b/lib/shmem.h index 6bcbb7d3fa..19a028c18e 100644 --- a/lib/shmem.h +++ b/lib/shmem.h @@ -42,8 +42,8 @@ int detach_shmem(HANDLE hSharedMem, void* p); #else #ifndef __EMX__ #define MMAPPED_FILE_NAME "boinc_mmap_file" -extern int create_shmem_mmap(char *path, size_t size, void** pp); -extern int attach_shmem_mmap(char *path, void** pp); +extern int create_shmem_mmap(const char *path, size_t size, void** pp); +extern int attach_shmem_mmap(const char *path, void** pp); extern int detach_shmem_mmap(void* p, size_t size); #endif extern int create_shmem(key_t, int size, gid_t gid, void**); diff --git a/sched/handle_request.C b/sched/handle_request.C index ebc5e5bb39..6a7bd6665e 100644 --- a/sched/handle_request.C +++ b/sched/handle_request.C @@ -95,7 +95,7 @@ static void get_weak_auth(USER& user, char* buf) { sprintf(buf, "%d_%s", user.id, out); } -static void send_error_message(SCHEDULER_REPLY& reply, char* msg, int delay) { +static void send_error_message(SCHEDULER_REPLY& reply, const char* msg, int delay) { USER_MESSAGE um(msg, "low"); reply.insert_message(um); reply.set_delay(delay); @@ -189,7 +189,7 @@ static void mark_results_over(DB_HOST& host) { ); while (!result.enumerate(buf)) { sprintf(buf2, - "server_state=%d, outcome=%d, received_time = %d", + "server_state=%d, outcome=%d, received_time = %ld", RESULT_SERVER_STATE_OVER, RESULT_OUTCOME_CLIENT_DETACHED, time(0) @@ -999,8 +999,8 @@ bool unacceptable_os( unsigned int i; char buf[1024]; - for (i=0; isize(); i++) { + regex_t& re = (*config.ban_os)[i]; strcpy(buf, sreq.host.os_name); strcat(buf, "\t"); strcat(buf, sreq.host.os_version); @@ -1027,8 +1027,8 @@ bool unacceptable_cpu( unsigned int i; char buf[1024]; - for (i=0; isize(); i++) { + regex_t& re = (*config.ban_cpu)[i]; strcpy(buf, sreq.host.p_vendor); strcat(buf, "\t"); strcat(buf, sreq.host.p_model); diff --git a/sched/sched_array.C b/sched/sched_array.C index 0d751e6cb0..6cb5def0a3 100644 --- a/sched/sched_array.C +++ b/sched/sched_array.C @@ -52,8 +52,6 @@ void scan_work_array(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) { DB_RESULT result; char buf[256]; APP* app; - APP_VERSION* avp; - bool found; lock_sema(); diff --git a/sched/sched_assign.C b/sched/sched_assign.C index 49b623dafd..edb31efea2 100644 --- a/sched/sched_assign.C +++ b/sched/sched_assign.C @@ -40,7 +40,6 @@ static int send_assigned_job( static bool first=true; static int seqno=0; static R_RSA_PRIVATE_KEY key; - APP* app; BEST_APP_VERSION* bavp; if (first) { @@ -70,7 +69,7 @@ static int send_assigned_job( } sprintf(rtfpath, "../%s", wu.result_template_file); - sprintf(suffix, "%d_%d_%d", getpid(), time(0), seqno++); + sprintf(suffix, "%d_%d_%d", getpid(), (int)time(0), seqno++); retval = create_result(wu, rtfpath, suffix, key, config, 0, 0); if (retval) { log_messages.printf(MSG_CRITICAL, @@ -101,7 +100,7 @@ static int send_assigned_job( } log_messages.printf(MSG_DEBUG, "[WU#%d] [RESULT#%d] [HOST#%d] send assignment %d\n", - wu.id, result_id, reply.host.id + wu.id, result_id, reply.host.id, asg.id ); return 0; } diff --git a/sched/sched_config.C b/sched/sched_config.C index c4666b1692..45daf00a70 100644 --- a/sched/sched_config.C +++ b/sched/sched_config.C @@ -50,10 +50,11 @@ int SCHED_CONFIG::parse(FILE* f) { int retval; regex_t re; - // Don't bother to initialize to zero since it's a global. - // If this ever changes, need to initialize - // mf.init_file(f); + + memset(this, 0, sizeof(*this)); + ban_os = new vector; + ban_cpu = new vector; max_wus_to_send = 10; default_disk_max_used_gb = 100.; default_disk_max_used_pct = 50.; @@ -151,14 +152,14 @@ int SCHED_CONFIG::parse(FILE* f) { if (xp.parse_bool(tag, "no_darwin_6", no_darwin_6)) { if (no_darwin_6) { regcomp(&re, ".*Darwin.*\t.*(5\\.|6\\.).*", REG_EXTENDED|REG_NOSUB); - ban_os.push_back(re); + ban_os->push_back(re); } continue; } if (xp.parse_bool(tag, "no_amd_k6", no_amd_k6)) { if (no_amd_k6) { regcomp(&re, ".*AMD.*\t.*Family 5 Model 8 Stepping 0.*", REG_EXTENDED|REG_NOSUB); - ban_cpu.push_back(re); + ban_cpu->push_back(re); } continue; } @@ -172,7 +173,7 @@ int SCHED_CONFIG::parse(FILE* f) { if (retval) { log_messages.printf(MSG_CRITICAL, "BAD REGEXP: %s\n", buf); } else { - ban_os.push_back(re); + ban_os->push_back(re); } continue; } @@ -181,7 +182,7 @@ int SCHED_CONFIG::parse(FILE* f) { if (retval) { log_messages.printf(MSG_CRITICAL, "BAD REGEXP: %s\n", buf); } else { - ban_cpu.push_back(re); + ban_cpu->push_back(re); } continue; } @@ -233,7 +234,7 @@ int SCHED_CONFIG::download_path(const char* filename, char* path) { } void get_project_dir(char* p, int len) { - char* unused = getcwd(p, len); + getcwd(p, len); char* q = strrchr(p, '/'); if (q) *q = 0; } diff --git a/sched/sched_config.h b/sched/sched_config.h index 93bf1e9361..9504d07a09 100644 --- a/sched/sched_config.h +++ b/sched/sched_config.h @@ -118,8 +118,8 @@ public: bool request_time_stats_log; bool enable_assignment; int max_ncpus; - vector ban_os; - vector ban_cpu; + vector *ban_os; + vector *ban_cpu; bool matchmaker; int mm_min_slots; int mm_max_slots; diff --git a/sched/sched_send.C b/sched/sched_send.C index fdc18d40ee..4832bea34f 100644 --- a/sched/sched_send.C +++ b/sched/sched_send.C @@ -217,7 +217,7 @@ BEST_APP_VERSION* get_app_version( return bavp; } -static char* find_user_friendly_name(int appid) { +static const char* find_user_friendly_name(int appid) { APP* app = ssp->lookup_app(appid); if (app) return app->user_friendly_name; return "deprecated application"; @@ -1028,7 +1028,7 @@ int add_result_to_reply( result.update_field(buf); dbwu.id = wu.id; - sprintf(buf, "transition_time=%d", time(0)); + sprintf(buf, "transition_time=%ld", time(0)); dbwu.update_field(buf); } @@ -1039,7 +1039,7 @@ int add_result_to_reply( if (wu.target_nresults == 1 && app->target_nresults > 1 && !reply.wreq.trust) { DB_WORKUNIT dbwu; char buf[256]; - sprintf(buf, "target_nresults=%d and transition_time=%d", + sprintf(buf, "target_nresults=%d and transition_time=%ld", app->target_nresults, time(0) ); dbwu.id = wu.id; @@ -1064,6 +1064,7 @@ int add_result_to_reply( static void explain_to_user(SCHEDULER_REPLY& reply) { char helpful[512]; unsigned int i; + int j; // If work was sent from apps // the user did not select, explain // @@ -1090,8 +1091,8 @@ static void explain_to_user(SCHEDULER_REPLY& reply) { // Tell the user about applications they didn't qualify for // - for (i=0; i")) return "no start tag"; while (fgets(buf, sizeof(buf), fin)) { if (match_tag(buf, "")) return NULL; @@ -883,7 +883,6 @@ int APP_VERSION::write(FILE* fout) { int RESULT::write_to_client(FILE* fout) { char buf[BLOB_SIZE]; - unsigned int i; strcpy(buf, xml_doc_in); char* p = strstr(buf, ""); diff --git a/tools/backend_lib.C b/tools/backend_lib.C index 19fa193c2b..d37cf83d2d 100644 --- a/tools/backend_lib.C +++ b/tools/backend_lib.C @@ -169,7 +169,7 @@ static int process_wu_template( char* tmplate, const char** infiles, int ninfiles, - SCHED_CONFIG& config, + SCHED_CONFIG& config_loc, const char* command_line, const char* additional_xml ) { @@ -217,8 +217,8 @@ static int process_wu_template( ); } else { dir_hier_path( - infiles[file_number], config.download_dir, - config.uldl_dir_fanout, path, true + infiles[file_number], config_loc.download_dir, + config_loc.uldl_dir_fanout, path, true ); // if file isn't found in hierarchy, @@ -226,26 +226,26 @@ static int process_wu_template( // if (!boinc_file_exists(path)) { sprintf(top_download_path, - "%s/%s",config.download_dir, + "%s/%s",config_loc.download_dir, infiles[file_number] ); boinc_copy(top_download_path, path); } - if (!config.cache_md5_info || !got_md5_info(path, md5, &nbytes)) { + if (!config_loc.cache_md5_info || !got_md5_info(path, md5, &nbytes)) { retval = md5_file(path, md5, nbytes); if (retval) { fprintf(stderr, "process_wu_template: md5_file %d\n", retval); return retval; } - else if (config.cache_md5_info) { + else if (config_loc.cache_md5_info) { write_md5_info(path, md5, nbytes); } } dir_hier_url( - infiles[file_number], config.download_url, - config.uldl_dir_fanout, url + infiles[file_number], config_loc.download_url, + config_loc.uldl_dir_fanout, url ); sprintf(buf, " %s\n" @@ -403,7 +403,7 @@ int create_result_ti( char* result_template_filename, char* result_name_suffix, R_RSA_PRIVATE_KEY& key, - SCHED_CONFIG& config, + SCHED_CONFIG& config_loc, char* query_string, // if nonzero, write value list here; else do insert int priority_increase @@ -422,7 +422,7 @@ int create_result_ti( result_template_filename, result_name_suffix, key, - config, + config_loc, query_string, priority_increase ); @@ -436,7 +436,7 @@ int create_result( char* result_template_filename, char* result_name_suffix, R_RSA_PRIVATE_KEY& key, - SCHED_CONFIG& config, + SCHED_CONFIG& config_loc, char* query_string, // if nonzero, write value list here; else do insert int priority_increase @@ -463,10 +463,7 @@ int create_result( } retval = process_result_template( - result_template, - key, - base_outfile_name, - config + result_template, key, base_outfile_name, config_loc ); if (retval) { fprintf(stderr, "process_result_template() error: %d\n", retval); @@ -495,7 +492,7 @@ int create_result( // if using locality scheduling, advertise data file // associated with this newly-created result // - if (config.locality_scheduling) { + if (config_loc.locality_scheduling) { char datafilename[512]; char *last=strstr(result.name, "__"); if (result.name