From 75d2a45491fbf7526fc27f4f108e9dd0fbb879b1 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 17 Sep 2009 17:56:59 +0000 Subject: [PATCH] - server programs: add --help and --version cmdline options to all. From Nils Chr. Brause. svn path=/trunk/boinc/; revision=19079 --- Makefile.am | 10 ++- checkin_notes | 9 +++ generate_svn_version.sh | 27 +++++++ sched/census.cpp | 27 +++++-- sched/db_dump.cpp | 52 ++++++++++---- sched/db_purge.cpp | 78 ++++++++++++++------ sched/delete_file.cpp | 43 +++++++++--- sched/feeder.cpp | 114 +++++++++++++++++++++++------- sched/file_deleter.cpp | 121 +++++++++++++++++--------------- sched/file_upload_handler.cpp | 32 ++++++++- sched/get_file.cpp | 53 ++++++++++---- sched/make_work.cpp | 62 ++++++++++++++-- sched/message_handler.cpp | 38 +++++++--- sched/request_file_list.cpp | 41 ++++++++--- sched/sample_work_generator.cpp | 42 +++++++++-- sched/sched_driver.cpp | 55 +++++++++++++-- sched/sched_main.cpp | 39 ++++++---- sched/send_file.cpp | 57 ++++++++++----- sched/show_shmem.cpp | 29 +++++++- sched/start | 5 +- sched/transitioner.cpp | 103 +++++++++++++++++++-------- sched/trickle_handler.cpp | 44 ++++++++++-- sched/update_stats.cpp | 38 +++++++++- sched/wu_check.cpp | 32 ++++++++- 24 files changed, 897 insertions(+), 254 deletions(-) create mode 100644 generate_svn_version.sh diff --git a/Makefile.am b/Makefile.am index 2c70a9fb11..062ba97942 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,9 +39,17 @@ EXTRA_DIST = \ if INSTALL_HEADERS pkginclude_HEADERS = \ - version.h + version.h \ + svn_version.h endif +# svn_version.h should always be rebuilt. + +BUILT_SOURCES = svn_version.h +svn_version.h: generate_svn_version.sh + sh generate_svn_version.sh +.PHONY: svn_version.h + # Add a stage target for staging a distribution clean-generic: diff --git a/checkin_notes b/checkin_notes index 90dc925359..a637a58a68 100644 --- a/checkin_notes +++ b/checkin_notes @@ -7792,3 +7792,12 @@ David 17 Sept 2009 client/ scheduler_op.cpp + +David 17 Sept 2009 + - server programs: add --help and --version cmdline options to all. + From Nils Chr. Brause. + + Makefile.am + generate_svn_version.sh + sched/ + (most).cpp diff --git a/generate_svn_version.sh b/generate_svn_version.sh new file mode 100644 index 0000000000..c6ecb88f25 --- /dev/null +++ b/generate_svn_version.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env sh + +echo "#ifndef SVN_VERSION_H" > svn_version.h +echo "#define SVN_VERSION_H" >> svn_version.h +echo "" >> svn_version.h + +if [ -d .git ]; then + CMD="git svn info" +elif [ -d .svn ]; then + CMD="svn info" +else + CMD="" +fi + +if [ "x$CMD" != "x" ]; then + $CMD | awk '/^URL/ { url = $2; }; \ + /^Rev/ { rev = $2; }; \ + END { print "#define SVN_VERSION \"Repository: " url \ + " Revision: " rev "\""; };' \ + >> svn_version.h +else + echo "#include \"version.h\"" >> svn_version.h + echo "#define SVN_VERSION BOINC_VERSION_STRING" >> svn_version.h +fi + +echo "" >> svn_version.h +echo "#endif" >> svn_version.h diff --git a/sched/census.cpp b/sched/census.cpp index f8e5b33cf6..53d306d3cd 100644 --- a/sched/census.cpp +++ b/sched/census.cpp @@ -28,8 +28,9 @@ #include "sched_util.h" #include "sched_msgs.h" #include "hr_info.h" +#include "svn_version.h" -void usage(char** argv) { +void usage(char *name) { fprintf(stderr, "This program scans the 'host' DB table and creates two files:\n\n" "%s: how much RAC each HR class is getting\n" @@ -38,19 +39,33 @@ void usage(char** argv) { " (needed if you use the 'job_size_matching' scheduling option).\n\n" "This should be run as a periodic task (about once a day) from config.xml.\n" "For more info, see http://boinc.berkeley.edu/trac/wiki/HomogeneousRedundancy\n\n" - "Usage: %s [--help]\n", - HR_INFO_FILENAME, PERF_INFO_FILENAME, argv[0] + "Usage: %s [OPTION]...\n\n" + "Options:\n" + " -h --help shows this help text.\n" + " -v --version shows version information.\n", + HR_INFO_FILENAME, PERF_INFO_FILENAME, name ); - exit(0); } int main(int argc, char** argv) { HR_INFO hri; int retval; - for (int i=0; i #include - #include "boinc_db.h" #include "util.h" #include "filesys.h" @@ -50,6 +49,7 @@ #include "sched_config.h" #include "sched_util.h" #include "sched_msgs.h" +#include "svn_version.h" #include "error_numbers.h" #include "str_util.h" @@ -554,22 +554,23 @@ bool do_pass() { } } -void usage(char** argv) { +void usage(char* name) { fprintf(stderr, "Purge workunit and result records that are no longer needed.\n\n" "Usage: %s [options]\n" - " [-d N] Set verbosity level (1, 2, 3=most verbose)\n" - " [-min_age_days N] Purge Wus w/ mod time at least N days ago\n" - " [-max N] Purge at more N WUs\n" - " [-zip] Compuress output files using zip\n" - " [-gzip] Compuress output files using gzip\n" - " [-no_archive] Don't write output files, just purge\n" - " [-max_wu_per_file N] Write at most N WUs per output file\n" - " [-sleep N] Sleep N sec after DB scan\n" - " [-one_pass] Make one DB scan, then exit\n", - argv[0] + " [-d N] Set verbosity level (1, 2, 3=most verbose)\n" + " [-min_age_days N] Purge Wus w/ mod time at least N days ago\n" + " [-max N] Purge at more N WUs\n" + " [-zip] Compuress output files using zip\n" + " [-gzip] uress output files using gzip\n" + " [-no_archive] Don't write output files, just purge\n" + " [-max_wu_per_file N] Write at most N WUs per output file\n" + " [-sleep N] Sleep N sec after DB scan\n" + " [-one_pass] Make one DB scan, then exit\n" + " [-h | -help | --help] Show this help text\n" + " [-v | -version | --version] Show version information\n", + name ); - exit(0); } int main(int argc, char** argv) { @@ -583,35 +584,66 @@ int main(int argc, char** argv) { if (!strcmp(argv[i], "-one_pass")) { one_pass = true; } else if (!strcmp(argv[i], "-d")) { - log_messages.set_debug_level(atoi(argv[++i])); + if(!argv[++i]) { + log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); + usage(argv[0]); + exit(1); + } + log_messages.set_debug_level(atoi(argv[i])); } else if (!strcmp(argv[i], "-min_age_days")) { - min_age_days = atoi(argv[++i]); + if(!argv[++i]) { + log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); + usage(argv[0]); + exit(1); + } + min_age_days = atoi(argv[i]); } else if (!strcmp(argv[i], "-max")) { - max_number_workunits_to_purge= atoi(argv[++i]); + if(!argv[++i]) { + log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); + usage(argv[0]); + exit(1); + } + max_number_workunits_to_purge= atoi(argv[i]); } else if (!strcmp(argv[i], "-zip")) { compression_type=COMPRESSION_ZIP; } else if (!strcmp(argv[i], "-gzip")) { compression_type=COMPRESSION_GZIP; } else if (!strcmp(argv[i], "-max_wu_per_file")) { - max_wu_per_file = atoi(argv[++i]); + if(!argv[++i]) { + log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); + usage(argv[0]); + exit(1); + } + max_wu_per_file = atoi(argv[i]); } else if (!strcmp(argv[i], "-no_archive")) { no_archive = true; } else if (!strcmp(argv[i], "-sleep")) { - sleep_sec = atoi(argv[++i]); + if(!argv[++i]) { + log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); + usage(argv[0]); + exit(1); + } + sleep_sec = atoi(argv[i]); if (sleep_sec < 1 || sleep_sec > 86400) { log_messages.printf(MSG_CRITICAL, "Unreasonable value of sleep interval: %d seconds\n", sleep_sec ); - usage(argv); + usage(argv[0]); + exit(1); } - } else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { - usage(argv); + } else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "-h")) { + usage(argv[0]); + return 0; + } else if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-version")) { + printf("%s\n", SVN_VERSION); + exit(0); } else { log_messages.printf(MSG_CRITICAL, - "Unrecognized arg: %s\n", argv[i] + "unknown command line argument: %s\n\n", argv[i] ); - usage(argv); + usage(argv[0]); + exit(1); } } diff --git a/sched/delete_file.cpp b/sched/delete_file.cpp index 0a0938b421..1cb1dcdc92 100644 --- a/sched/delete_file.cpp +++ b/sched/delete_file.cpp @@ -31,20 +31,26 @@ #endif #include #include +#include #include "boinc_db.h" #include "str_util.h" +#include "svn_version.h" #include "sched_config.h" #include "sched_util.h" -void usage(char** argv) { +void usage(char* name) { fprintf(stderr, "Arrange to delete a file from a host.\n\n" - "Usage: %s -host_id H -file_name F\n", - argv[0] + "Usage: %s OPTION...\n\n" + "Options:\n" + " -file_name F Specify te file to delete.\n" + " -host_id H Specify the coresponding host\n" + " [-h | -help | --help] Show this help text.\n" + " [-v | -version | --version] Show version information.\n", + name ); - exit(0); } int delete_host_file(int host_id, const char* file_name) { @@ -76,20 +82,35 @@ int main(int argc, char** argv) { for (i=1; i #include #include +#include #ifdef _USING_FCGI_ #include "boinc_fcgi.h" @@ -42,6 +43,7 @@ #include "error_numbers.h" #include "str_util.h" #include "filesys.h" +#include "svn_version.h" #include "sched_config.h" #include "sched_util.h" @@ -611,7 +613,20 @@ void installer() { signal(SIGTERM, boinc_catch_signal); // terminate process } -int main() { +void usage(char *name) { + fprintf(stderr, + "This is the boinc file upload handler.\n" + "It receives the results from the clients\n" + "and puts them on the file server.\n\n" + "Usage: %s [OPTION]...\n\n" + "Options:\n" + " [ -h | -help | --help ] Show this help text.\n" + " [ -v | -version | --version ] Show version information.\n", + name + ); +} + +int main(int argc, char *argv[]) { int retval; R_RSA_PUBLIC_KEY key; char log_path[256]; @@ -619,6 +634,21 @@ int main() { unsigned int counter=0; #endif + for(int c = 1; c < argc; c++) { + std::string option(argv[c]); + if(option == "-v" || option == "-version" || option == "--version") { + printf("%s\n", SVN_VERSION); + exit(0); + } else if(option == "-h" || option == "-help" || option == "--help") { + usage(argv[0]); + exit(0); + } else { + fprintf(stderr, "unknown command line argument: %s\n\n", argv[c]); + usage(argv[0]); + exit(1); + } + } + installer(); get_log_path(log_path, "file_upload_handler.log"); diff --git a/sched/get_file.cpp b/sched/get_file.cpp index 4097a5b95e..9d2b2a66b7 100644 --- a/sched/get_file.cpp +++ b/sched/get_file.cpp @@ -40,6 +40,7 @@ #include "sched_config.h" #include "sched_util.h" #include "md5_file.h" +#include "svn_version.h" void init_xfer_result(DB_RESULT& result) { result.id = 0; @@ -139,6 +140,22 @@ int get_file(int host_id, const char* file_name) { return retval; } +void usage(char *name) { + fprintf(stderr, "Gets a file to a specific host.\n" + "Creates a result entry, initialized to sent, and corresponding\n" + "messages to the host that is assumed to have the file.\n" + "Run from the project root dir.\n\n" + "Usage: %s [OPTION]...\n\n" + "Options:\n" + " -host_id id " + "Specify numerical id of host to upload from.\n" + " -file_name name " + "Specify name of specific file, dominates workunit.\n" + " [ -v | -version | --version ] Show version information.\n" + " [ -h | -help | --help ] Show this help text.\n", + name + ); +} int main(int argc, char** argv) { int i, retval; @@ -152,23 +169,29 @@ int main(int argc, char** argv) { for(i=1; i &wu_names) { } } +void usage(char *name) { + fprintf(stderr, + "Create WU and result records as needed to maintain a pool of work\n" + "(for testing purposes).\n" + "Clones the WU of the given name.\n\n" + "Usage: %s [OPTION]...\n\n" + "Options:\n" + " -wu_name name the name for the WU\n" + " (can be repeated)\n" + " [ -cushion N ] " + "make work if fewer than N unsent results\n" + " [ -max_wus n ] " + "don't make work if more than N total WUs\n" + " [ -one_pass ] quit after one pass\n" + " [ -d X ] set debug level to X.\n" + " [ -h | -help | --help ] shows this help text.\n" + " [ -v | -version | --version ] shows version information\n", + name + ); +} + int main(int argc, char** argv) { int i; vector wu_names; for (i=1; i. -// sample_work_generator.C: an example BOINC work generator. +// sample_work_generator.cpp: an example BOINC work generator. // This work generator has the following properties // (you may need to change some or all of these): // @@ -37,6 +37,7 @@ #include "backend_lib.h" #include "parse.h" #include "util.h" +#include "svn_version.h" #include "sched_config.h" #include "sched_util.h" @@ -137,16 +138,47 @@ void main_loop() { } } +void usage(char *name) { + fprintf(stderr, "This is an example BOINC work generator.\n" + "This work generator has the following properties\n" + "(you may need to change some or all of these):\n" + "- Runs as a daemon, and creates an unbounded supply of work.\n" + " It attempts to maintain a \"cushion\" of 100 unsent job instances.\n" + " (your app may not work this way; e.g. you might create work in batches)\n" + "- Creates work for the application \"uppercase\".\n" + "- Creates a new input file for each job;\n" + " the file (and the workunit names) contain a timestamp\n" + " and sequence number, so that they're unique.\n\n" + "Usage: %s [OPTION]...\n\n" + "Options:\n" + " [ -d X ] Sets debug level to X.\n" + " [ -h | -help | --help ] Shows this help text.\n" + " [ -v | --version | --version ] Shows version information.\n", + name + ); +} + int main(int argc, char** argv) { int i, retval; for (i=1; i #include #include "util.h" +#include "svn_version.h" using std::vector; @@ -117,17 +118,63 @@ void make_request(int i) { ); } +void usage(char *name) { + fprintf(stderr, + "This program generates a stream of scheduler requests;\n" + "it acts as a \"driver\" for the scheduler when used as:\n" + "%s | cgi --batch --mark_jobs_done\n\n" + "This was written to test the homogeneous redundancy features\n" + "of the feeder and scheduler,\n" + "but it could be used for a variety of other purposes.\n\n" + "Each request asks for a uniformly-distributed random amount of work.\n" + "The OS and CPU info is taken from the successive lines of a file of the form\n" + "| os_name | p_vendor | p_model |\n" + "Generate this file with a SQL query, trimming off the start and end.\n\n" + "Notes:\n" + "1) Use sample_trivial_validator and sample_dummy_assimilator\n" + "2) Edit the following to something in your DB\n\n" + "Usage: %s [OPTION]...\n\n" + "Options: \n" + " --nrequests N Sets the total nukmer of requests to N\n" + " --reqs_per_second X Sets the number of requests per second to X\n" + " [ -h | -help | --help ] Show this help text.\n" + " [ -v | -version | --version ] Show version information\n", + name + ); +} + int main(int argc, char** argv) { int i, nrequests = 1; double reqs_per_second = 1; for (i=1; i>sys.stderr, "Based on the invocation name as `start', the default action is --enable." elif program_name == 'stop': print >>sys.stderr, "Based on the invocation name as `stop', the default action is --disable." + elif program_name == 'status': + print >>sys.stderr, "Based on the invocation name as `status', the default action is --status." sys.exit(1) config_filename = boinc_project_path.config_xml_filename diff --git a/sched/transitioner.cpp b/sched/transitioner.cpp index 9091c53c5b..6f60f2c372 100644 --- a/sched/transitioner.cpp +++ b/sched/transitioner.cpp @@ -42,6 +42,7 @@ #include "common_defs.h" #include "error_numbers.h" #include "str_util.h" +#include "svn_version.h" #include "sched_config.h" #include "sched_util.h" @@ -434,23 +435,23 @@ int handle_wu( // all_over_and_validated = true; bool all_over_and_ready_to_assimilate = true; // used for the defer assmilation - int most_recently_returned = 0; + int most_recently_returned = 0; for (i=0; i most_recently_returned ) { - most_recently_returned = res_item.res_received_time; - } + if ( res_item.res_received_time > most_recently_returned ) { + most_recently_returned = res_item.res_received_time; + } if (res_item.res_outcome == RESULT_OUTCOME_SUCCESS) { if (res_item.res_validate_state == VALIDATE_STATE_INIT) { all_over_and_validated = false; all_over_and_ready_to_assimilate = false; } } else if ( res_item.res_outcome == RESULT_OUTCOME_NO_REPLY ) { - if ( ( res_item.res_report_deadline + config.grace_period_hours*60*60 ) > now ) { - all_over_and_validated = false; - } + if ( ( res_item.res_report_deadline + config.grace_period_hours*60*60 ) > now ) { + all_over_and_validated = false; + } } } else { all_over_and_validated = false; @@ -466,7 +467,7 @@ int handle_wu( // if (all_over_and_ready_to_assimilate == true && wu_item.assimilate_state == ASSIMILATE_INIT && items.size() > 0 && wu_item.canonical_resultid > 0 ) { - wu_item.assimilate_state = ASSIMILATE_READY; + wu_item.assimilate_state = ASSIMILATE_READY; log_messages.printf(MSG_NORMAL, "[WU#%d %s] Deferred assimililation now set to ASSIMILATE_STATE_READY\n", wu_item.id, wu_item.name @@ -526,7 +527,7 @@ int handle_wu( } } } else if ( wu_item.assimilate_state == ASSIMILATE_DONE ) { - log_messages.printf(MSG_DEBUG, + log_messages.printf(MSG_DEBUG, "[WU#%d %s] not checking for items to be ready for delete because the deferred delete time has not expired. That will occur in %d seconds\n", wu_item.id, wu_item.name, @@ -566,30 +567,33 @@ int handle_wu( wu_item.transition_time = x; } } else if ( res_item.res_server_state == RESULT_SERVER_STATE_OVER ) { - if ( res_item.res_outcome == RESULT_OUTCOME_NO_REPLY ) { - // Transition again after the grace period has expired - if ( ( res_item.res_report_deadline + config.grace_period_hours*60*60 ) > now ) { - x = res_item.res_report_deadline + config.grace_period_hours*60*60; - if (x > max_grace_or_delay_time) { - max_grace_or_delay_time = x; - } - } - } else if ( res_item.res_outcome == RESULT_OUTCOME_SUCCESS || res_item.res_outcome == RESULT_OUTCOME_CLIENT_ERROR || res_item.res_outcome == RESULT_OUTCOME_VALIDATE_ERROR) { - // Transition again after deferred delete period has experied - if ( (res_item.res_received_time + config.delete_delay_hours*60*60) > now ) { - x = res_item.res_received_time + config.delete_delay_hours*60*60; - if (x > max_grace_or_delay_time && res_item.res_received_time > 0) { - max_grace_or_delay_time = x; - } - } + if ( res_item.res_outcome == RESULT_OUTCOME_NO_REPLY ) { + // Transition again after the grace period has expired + // + if ((res_item.res_report_deadline + config.grace_period_hours*60*60) > now) { + x = res_item.res_report_deadline + config.grace_period_hours*60*60; + if (x > max_grace_or_delay_time) { + max_grace_or_delay_time = x; + } + } + } else if (res_item.res_outcome == RESULT_OUTCOME_SUCCESS || res_item.res_outcome == RESULT_OUTCOME_CLIENT_ERROR || res_item.res_outcome == RESULT_OUTCOME_VALIDATE_ERROR) { + // Transition again after deferred delete period has experied + // + if ((res_item.res_received_time + config.delete_delay_hours*60*60) > now) { + x = res_item.res_received_time + config.delete_delay_hours*60*60; + if (x > max_grace_or_delay_time && res_item.res_received_time > 0) { + max_grace_or_delay_time = x; + } + } } } } } + // If either of the grace period or delete delay is less than // the next transition time then use that value // - if ( max_grace_or_delay_time < wu_item.transition_time && max_grace_or_delay_time > now && ninprogress == 0) { + if (max_grace_or_delay_time < wu_item.transition_time && max_grace_or_delay_time > now && ninprogress == 0) { wu_item.transition_time = max_grace_or_delay_time; log_messages.printf(MSG_NORMAL, "[WU#%d %s] Delaying transition due to grace period or delete day. New transition time = %d sec\n", @@ -693,6 +697,24 @@ void main_loop() { } } +void usage(char *name) { + fprintf(stderr, + "Handles transitions in the state of a WU\n" + " - a result has become DONE (via timeout or client reply)\n" + " - the WU error mask is set (e.g. by validater)\n" + " - assimilation is finished\n\n" + "Usage: %s [OPTION]...\n\n" + "Options: \n" + " [ -one_pass ] do one pass, then exit\n" + " [ -d x ] debug level x\n" + " [ -mod n i ] process only WUs with (id mod n) == i\n" + " [ -sleep_interval x ] sleep x seconds if nothing to do\n" + " [ -h | -help | --help ] Show this help text.\n" + " [ -v | -version | --version ] Shows version information.\n", + name + ); +} + int main(int argc, char** argv) { int i, retval; char path[256]; @@ -702,13 +724,38 @@ int main(int argc, char** argv) { if (!strcmp(argv[i], "-one_pass")) { one_pass = true; } else if (!strcmp(argv[i], "-d")) { - log_messages.set_debug_level(atoi(argv[++i])); + if(!argv[++i]) { + log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); + usage(argv[0]); + exit(1); + } + log_messages.set_debug_level(atoi(argv[i])); } else if (!strcmp(argv[i], "-mod")) { + if(!argv[i+1] || !argv[i+2]) { + log_messages.printf(MSG_CRITICAL, "%s requires two arguments\n\n", argv[i]); + usage(argv[0]); + exit(1); + } mod_n = atoi(argv[++i]); mod_i = atoi(argv[++i]); do_mod = true; } else if (!strcmp(argv[i], "-sleep_interval")) { - sleep_interval = atoi(argv[++i]); + if(!argv[++i]) { + log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); + usage(argv[0]); + exit(1); + } + sleep_interval = atoi(argv[i]); + } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) { + usage(argv[0]); + exit(0); + } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "-version") || !strcmp(argv[i], "--version")) { + printf("%s\n", SVN_VERSION); + exit(0); + } else { + log_messages.printf(MSG_CRITICAL, "unknown command line argument: %s\n\n", argv[i]); + usage(argv[0]); + exit(1); } } if (!one_pass) check_stop_daemons(); diff --git a/sched/trickle_handler.cpp b/sched/trickle_handler.cpp index 31108dca3b..73b047debe 100644 --- a/sched/trickle_handler.cpp +++ b/sched/trickle_handler.cpp @@ -35,6 +35,7 @@ #include "util.h" #include "error_numbers.h" #include "str_util.h" +#include "svn_version.h" #include "sched_config.h" #include "sched_util.h" @@ -137,6 +138,23 @@ int main_loop(bool one_pass) { return 0; } +void usage(char *name) { + fprintf(stderr, + "Framework for trickle-up message handler\n" + "This program must be linked with an app-specific function:\n\n" + "int handle_trickle(MSG_FROM_HOST&)\n" + " - handle a trickle message\n\n" + "return nonzero on error\n\n" + "Usage: %s [OPTION]...\n\n" + "Options:\n" + " -variety X Set Variety to X\n" + " [ -d X ] Set debug level to X\n" + " [ -one_pass ] Make one pass through table, then exit\n" + " [ -h | -help | --help ] Show this help text\n" + " [ -v | -version | --version ] Shows version information\n", + name + ); +} int main(int argc, char** argv) { int i, retval; @@ -148,13 +166,29 @@ int main(int argc, char** argv) { if (!strcmp(argv[i], "-one_pass")) { one_pass = true; } else if (!strcmp(argv[i], "-variety")) { - strcpy(variety, argv[++i]); + if (!argv[++i]) { + log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); + usage(argv[0]); + exit(1); + } + strcpy(variety, argv[i]); } else if (!strcmp(argv[i], "-d")) { - log_messages.set_debug_level(atoi(argv[++i])); + if (!argv[++i]) { + log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); + usage(argv[0]); + exit(1); + } + log_messages.set_debug_level(atoi(argv[i])); + } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "-version") || !strcmp(argv[i], "--version")) { + printf("%s\n", SVN_VERSION); + exit(0); + } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) { + usage(argv[0]); + exit(0); } else { - log_messages.printf(MSG_CRITICAL, - "unrecognized arg: %s\n", argv[i] - ); + log_messages.printf(MSG_CRITICAL, "unknown command line argument: %s\n\n", argv[i]); + usage(argv[0]); + exit(1); } } diff --git a/sched/update_stats.cpp b/sched/update_stats.cpp index c2d9099b04..d1e49824b5 100644 --- a/sched/update_stats.cpp +++ b/sched/update_stats.cpp @@ -36,6 +36,7 @@ #include "util.h" #include "str_util.h" #include "error_numbers.h" +#include "svn_version.h" #include "sched_config.h" #include "sched_util.h" @@ -177,6 +178,26 @@ int update_teams() { return 0; } +void usage(char *name) { + fprintf(stderr, + "Update average credit for idle users, hosts and teams.\n" + "These fields are updates as new credit is granted;\n" + "the purpose of this program is to decay credit of entities\n" + "that are inactive for long periods.\n" + "Hence it should be run about once a day at most.\n\n" + "Also updates the nusers field of teams\n\n" + "Usage: %s [OPTION]...\n\n" + "Options:\n" + " [ -d X ] Set debug level to X\n" + " [ -update_teams ] Updates teams.\n" + " [ -update_users ] Updates users.\n" + " [ -update_hosts ] Updates hosts.\n" + " [ -h | -help | --help ] Shows this help text\n" + " [ -v | -version | --version ] Shows version information\n", + name + ); +} + int main(int argc, char** argv) { int retval, i; bool do_update_teams = false, do_update_users = false; @@ -194,9 +215,22 @@ int main(int argc, char** argv) { } else if (!strcmp(argv[i], "-update_hosts")) { do_update_hosts = true; } else if (!strcmp(argv[i], "-d")) { - log_messages.set_debug_level(atoi(argv[++i])); + if (!argv[++i]) { + log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]); + usage(argv[0]); + exit(1); + } + log_messages.set_debug_level(atoi(argv[i])); + } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "-version") || !strcmp(argv[i], "--version")) { + printf("%s\n", SVN_VERSION); + exit(0); + } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) { + usage(argv[0]); + exit(0); } else { - log_messages.printf(MSG_CRITICAL, "Unrecognized arg: %s\n", argv[i]); + log_messages.printf(MSG_CRITICAL, "unknown command line argument: %s\n\n", argv[i]); + usage(argv[0]); + exit(1); } } diff --git a/sched/wu_check.cpp b/sched/wu_check.cpp index 80466500d2..8b508b35fa 100644 --- a/sched/wu_check.cpp +++ b/sched/wu_check.cpp @@ -29,6 +29,7 @@ #include #include "boinc_db.h" +#include "svn_version.h" #include "parse.h" #include "util.h" @@ -99,11 +100,41 @@ int handle_result(DB_RESULT& result) { return 0; } +void usage(char *name) { + fprintf(stderr, + "Looks for results with missing input files\n\n" + "Usage: %s [OPTION]\n\n" + "Options:\n" + " [ -repair ] change them to server_state OVER,\n" + " outcome COULDNT_SEND\n" + " [ -h | -help | --help ] Shows this help text\n" + " [ -v | -version | --version ] Shows version information\n", + name + ); +} + int main(int argc, char** argv) { DB_RESULT result; char clause[256]; int retval, n, nerr; + for(int c = 1; c < argc; c++) { + std::string option(argv[c]); + if(option == "-h" || option == "-help" || option == "--help") { + usage(argv[0]); + exit(0); + } else if(option == "-v" || option == "-version" || option == "--version") { + printf("%s\n", SVN_VERSION); + exit(0); + } else if (option == "-repair") { + repair = true; + } else { + fprintf(stderr, "unknown command line argument: %s\n\n", argv[c]); + usage(argv[0]); + exit(1); + } + } + retval = config.parse_file(); if (retval) exit(1); @@ -112,7 +143,6 @@ int main(int argc, char** argv) { printf("boinc_db.open: %d\n", retval); exit(1); } - if (argc > 1 && !strcmp(argv[1], "-repair")) repair = true; n = nerr = 0; printf("Unsent results:\n");