int main(int argc, const char ** argv) { bool do_test = true; init_config(0); // initialize the config defaults int ix = 1; while (ix < argc) { if (is_dash_arg_prefix(argv[ix], "check-if", -1)) { check_configif = use_next_arg("check-if", argv, ix); do_test = false; } else if (is_dash_arg_prefix(argv[ix], "verbose", 1)) { dash_verbose = true; } else if (is_dash_arg_prefix(argv[ix], "memory-snapshot")) { #ifdef LINUX const char * filename = "tool"; if (argv[ix+1]) filename = use_next_arg("memory-shapshot", argv, ix); char copy_smaps[300]; pid_t pid = getpid(); sprintf(copy_smaps, "cat /proc/%d/smaps > %s", pid, filename); int r = system(copy_smaps); if (r != 0) { fprintf(stdout, "%d return copy smaps", r); } //fprintf(stdout, "%s returned %d\n", copy_smaps, r); #endif } else { fprintf(stderr, "unknown argument: %s\n", argv[ix]); my_exit(1); } ++ix; } // handle check-if to valididate config's if/else parsing and help users to write // valid if conditions. if (check_configif) { std::string err_reason; bool bb = false; bool valid = config_test_if_expression(check_configif, bb, NULL, NULL, err_reason); fprintf(stdout, "# %s: \"%s\" %s\n", valid ? "ok" : "not supported", check_configif, valid ? (bb ? "\ntrue" : "\nfalse") : err_reason.c_str()); } if (do_test) { printf("running standard config if tests\n"); int cTests = 0; int cFail = do_iftest(cTests); printf("%d failures in %d tests\n", cFail, cTests); return cFail; } return 0; }
int main(int argc, char* argv[]) { Collectors = NULL; #ifdef HAVE_EXT_POSTGRESQL HistorySnapshot *historySnapshot; SQLQuery queryhor; SQLQuery queryver; QuillErrCode st; bool remotequill=false; char *quillName=NULL; AttrList *ad=0; int flag = 1; void **parameters; char *dbconn=NULL; char *completedsince = NULL; char *dbIpAddr=NULL, *dbName=NULL,*queryPassword=NULL; bool remoteread = false; #endif /* HAVE_EXT_POSTGRESQL */ const char *owner=NULL; bool readfromfile = true; bool fileisuserlog = false; char* JobHistoryFileName=NULL; const char * pcolon=NULL; GenericQuery constraint; // used to build a complex constraint. ExprTree *constraintExpr=NULL; std::string tmp; int i; myDistro->Init( argc, argv ); config(); #ifdef HAVE_EXT_POSTGRESQL parameters = (void **) malloc(NUM_PARAMETERS * sizeof(void *)); queryhor.setQuery(HISTORY_ALL_HOR, NULL); queryver.setQuery(HISTORY_ALL_VER, NULL); #endif /* HAVE_EXT_POSTGRESQL */ for(i=1; i<argc; i++) { if (is_dash_arg_prefix(argv[i],"long",1)) { longformat=TRUE; } else if (is_dash_arg_prefix(argv[i],"xml",3)) { use_xml = true; longformat = true; } else if (is_dash_arg_prefix(argv[i],"backwards",1)) { backwards=TRUE; } // must be at least -forw to avoid conflict with -f (for file) and -format else if (is_dash_arg_prefix(argv[i],"nobackwards",3) || is_dash_arg_prefix(argv[i],"forwards",4)) { backwards=FALSE; } else if (is_dash_arg_colon_prefix(argv[i],"wide", &pcolon, 1)) { wide_format=TRUE; if (pcolon) { wide_format_width = atoi(++pcolon); if ( ! mask.IsEmpty()) mask.SetOverallWidth(getDisplayWidth()-1); if (wide_format_width <= 80) wide_format = FALSE; } } else if (is_dash_arg_prefix(argv[i],"match",1) || is_dash_arg_prefix(argv[i],"limit",3)) { i++; if (argc <= i) { fprintf(stderr, "Error: Argument -match requires a number value " " as a parameter.\n"); exit(1); } specifiedMatch = atoi(argv[i]); } #ifdef HAVE_EXT_POSTGRESQL else if(is_dash_arg_prefix(argv[i], "dbname",1)) { i++; if (argc <= i) { fprintf( stderr, "Error: Argument -dbname requires the name of a quilld as a parameter\n" ); exit(1); } /* if( !(quillName = get_daemon_name(argv[i])) ) { fprintf( stderr, "Error: unknown host %s\n", get_host_part(argv[i]) ); printf("\n"); print_wrapped_text("Extra Info: The name given with the -dbname " "should be the name of a condor_quilld process. " "Normally it is either a hostname, or " "\"name@hostname\". " "In either case, the hostname should be the " "Internet host name, but it appears that it " "wasn't.", stderr); exit(1); } sprintf (tmp, "%s == \"%s\"", ATTR_NAME, quillName); quillQuery.addORConstraint (tmp); */ quillName = argv[i]; sprintf (tmp, "%s == \"%s\"", ATTR_SCHEDD_NAME, quillName); quillQuery.addORConstraint (tmp.c_str()); remotequill = false; readfromfile = false; } #endif /* HAVE_EXT_POSTGRESQL */ else if (is_dash_arg_prefix(argv[i],"file",2)) { if (i+1==argc || JobHistoryFileName) break; i++; JobHistoryFileName=argv[i]; readfromfile = true; } else if (is_dash_arg_prefix(argv[i],"userlog",1)) { if (i+1==argc || JobHistoryFileName) break; i++; JobHistoryFileName=argv[i]; readfromfile = true; fileisuserlog = true; } else if (is_dash_arg_prefix(argv[i],"help",1)) { Usage(argv[0],0); } else if (is_dash_arg_prefix(argv[i],"format",1)) { if (argc <= i + 2) { fprintf(stderr, "Error: Argument -format requires a spec and " "classad attribute name as parameters.\n"); fprintf(stderr, "\t\te.g. condor_history -format '%%d' ClusterId\n"); exit(1); } mask.registerFormat(argv[i + 1], argv[i + 2]); customFormat = true; i += 2; } else if (*(argv[i]) == '-' && (is_arg_colon_prefix(argv[i]+1,"af", &pcolon, 2) || is_arg_colon_prefix(argv[i]+1,"autoformat", &pcolon, 5))) { // make sure we have at least one argument to autoformat if (argc <= i+1 || *(argv[i+1]) == '-') { fprintf (stderr, "Error: Argument %s requires at last one attribute parameter\n", argv[i]); fprintf(stderr, "\t\te.g. condor_history %s ClusterId\n", argv[i]); exit(1); } if (pcolon) ++pcolon; // if there are options, skip over the colon to the options. int ixNext = parse_autoformat_args(argc, argv, i+1, pcolon, mask, diagnostic); if (ixNext > i) i = ixNext-1; customFormat = true; } else if (is_dash_arg_colon_prefix(argv[i], "print-format", &pcolon, 2)) { if ( (argc <= i+1) || (*(argv[i+1]) == '-' && (argv[i+1])[1] != 0)) { fprintf( stderr, "Error: Argument -print-format requires a filename argument\n"); exit( 1 ); } // hack allow -pr ! to disable use of user-default print format files. if (MATCH == strcmp(argv[i+1], "!")) { ++i; disable_user_print_files = true; continue; } if ( ! wide_format) mask.SetOverallWidth(getDisplayWidth()-1); customFormat = true; ++i; std::string where_expr; if (set_print_mask_from_stream(mask, where_expr, argv[i], true) < 0) { fprintf(stderr, "Error: cannot execute print-format file %s\n", argv[i]); exit (1); } if ( ! where_expr.empty()) { constraint.addCustomAND(where_expr.c_str()); } } else if (is_dash_arg_prefix(argv[i],"constraint",1)) { // make sure we have at least one more argument if (argc <= i+1) { fprintf( stderr, "Error: Argument %s requires another parameter\n", argv[i]); exit(1); } i++; constraint.addCustomAND(argv[i]); } #ifdef HAVE_EXT_POSTGRESQL else if (is_dash_arg_prefix(argv[i],"completedsince",3)) { i++; if (argc <= i) { fprintf(stderr, "Error: Argument -completedsince requires a date and " "optional timestamp as a parameter.\n"); fprintf(stderr, "\t\te.g. condor_history -completedsince \"2004-10-19 10:23:54\"\n"); exit(1); } if (constraint!="") break; completedsince = strdup(argv[i]); parameters[0] = completedsince; queryhor.setQuery(HISTORY_COMPLETEDSINCE_HOR,parameters); queryver.setQuery(HISTORY_COMPLETEDSINCE_VER,parameters); } #endif /* HAVE_EXT_POSTGRESQL */ else if (sscanf (argv[i], "%d.%d", &cluster, &proc) == 2) { std::string jobconst; formatstr (jobconst, "%s == %d && %s == %d", ATTR_CLUSTER_ID, cluster,ATTR_PROC_ID, proc); constraint.addCustomOR(jobconst.c_str()); #ifdef HAVE_EXT_POSTGRESQL parameters[0] = &cluster; parameters[1] = &proc; queryhor.setQuery(HISTORY_CLUSTER_PROC_HOR, parameters); queryver.setQuery(HISTORY_CLUSTER_PROC_VER, parameters); #endif /* HAVE_EXT_POSTGRESQL */ } else if (sscanf (argv[i], "%d", &cluster) == 1) { std::string jobconst; formatstr (jobconst, "%s == %d", ATTR_CLUSTER_ID, cluster); constraint.addCustomOR(jobconst.c_str()); #ifdef HAVE_EXT_POSTGRESQL parameters[0] = &cluster; queryhor.setQuery(HISTORY_CLUSTER_HOR, parameters); queryver.setQuery(HISTORY_CLUSTER_VER, parameters); #endif /* HAVE_EXT_POSTGRESQL */ } else if (is_dash_arg_prefix(argv[i],"debug",1)) { // dprintf to console dprintf_set_tool_debug("TOOL", 0); } else if (is_dash_arg_prefix(argv[i],"diagnostic",4)) { // dprintf to console diagnostic = true; } else if (is_dash_arg_prefix(argv[i], "name", 1)) { i++; if (argc <= i) { fprintf(stderr, "Error: Argument -name requires name of a remote schedd\n"); fprintf(stderr, "\t\te.g. condor_history -name submit.example.com \n"); exit(1); } g_name = argv[i]; readfromfile = false; #ifdef HAVE_EXT_POSTGRESQL remoteread = true; #endif } else if (is_dash_arg_prefix(argv[i], "pool", 1)) { i++; if (argc <= i) { fprintf(stderr, "Error: Argument -name requires name of a remote schedd\n"); fprintf(stderr, "\t\te.g. condor_history -name submit.example.com \n"); exit(1); } g_pool = argv[i]; readfromfile = false; #ifdef HAVE_EXT_POSTGRESQL remoteread = true; #endif } else { std::string ownerconst; owner = argv[i]; formatstr(ownerconst, "%s == \"%s\"", ATTR_OWNER, owner); constraint.addCustomOR(ownerconst.c_str()); #ifdef HAVE_EXT_POSTGRESQL parameters[0] = owner; queryhor.setQuery(HISTORY_OWNER_HOR, parameters); queryver.setQuery(HISTORY_OWNER_VER, parameters); #endif /* HAVE_EXT_POSTGRESQL */ } } if (i<argc) Usage(argv[0]); MyString my_constraint; constraint.makeQuery(my_constraint); if (diagnostic) { fprintf(stderr, "Using effective constraint: %s\n", my_constraint.c_str()); } if ( ! my_constraint.empty() && ParseClassAdRvalExpr( my_constraint.c_str(), constraintExpr ) ) { fprintf( stderr, "Error: could not parse constraint %s\n", my_constraint.c_str() ); exit( 1 ); } #ifdef HAVE_EXT_POSTGRESQL /* This call must happen AFTER config() is called */ if (checkDBconfig() == true && !readfromfile) { readfromfile = false; } else { readfromfile = true; } #endif /* HAVE_EXT_POSTGRESQL */ #ifdef HAVE_EXT_POSTGRESQL if(!readfromfile && !remoteread) { if(remotequill) { if (Collectors == NULL) { Collectors = CollectorList::create(); if(Collectors == NULL ) { printf("Error: Unable to get list of known collectors\n"); exit(1); } } result = Collectors->query ( quillQuery, quillList ); if(result != Q_OK) { printf("Fatal Error querying collectors\n"); exit(1); } if(quillList.MyLength() == 0) { printf("Error: Unknown quill server %s\n", quillName); exit(1); } quillList.Open(); while ((ad = quillList.Next())) { // get the address of the database dbIpAddr = dbName = queryPassword = NULL; if (!ad->LookupString(ATTR_QUILL_DB_IP_ADDR, &dbIpAddr) || !ad->LookupString(ATTR_QUILL_DB_NAME, &dbName) || !ad->LookupString(ATTR_QUILL_DB_QUERY_PASSWORD, &queryPassword) || (ad->LookupBool(ATTR_QUILL_IS_REMOTELY_QUERYABLE,flag) && !flag)) { printf("Error: The quill daemon \"%s\" is not set up " "for database queries\n", quillName); exit(1); } } } else { // they just typed 'condor_history' on the command line and want // to use quill, so get the schedd ad for the local machine if // we can, figure out the name of the schedd and the // jobqueuebirthdate Daemon schedd( DT_SCHEDD, 0, 0 ); if ( schedd.locate(Daemon::LOCATE_FULL) ) { char *scheddname = quillName; if (scheddname == NULL) { // none set explictly, look it up in the daemon ad scheddname = schedd.name(); ClassAd *daemonAd = schedd.daemonAd(); int scheddbirthdate; if(daemonAd) { if(daemonAd->LookupInteger( ATTR_JOB_QUEUE_BIRTHDATE, scheddbirthdate) ) { queryhor.setJobqueuebirthdate( (time_t)scheddbirthdate); queryver.setJobqueuebirthdate( (time_t)scheddbirthdate); } } } else { queryhor.setJobqueuebirthdate(0); queryver.setJobqueuebirthdate(0); } queryhor.setScheddname(scheddname); queryver.setScheddname(scheddname); } } dbconn = getDBConnStr(quillName,dbIpAddr,dbName,queryPassword); historySnapshot = new HistorySnapshot(dbconn); if (!customFormat) { printf ("\n\n-- Quill: %s : %s : %s\n", quillName, dbIpAddr, dbName); } queryhor.prepareQuery(); // create the query strings before sending off to historySnapshot queryver.prepareQuery(); st = historySnapshot->sendQuery(&queryhor, &queryver, longformat, false, customFormat, &mask, constraint.c_str()); //if there's a failure here and if we're not posing a query on a //remote quill daemon, we should instead query the local file if(st == QUILL_FAILURE) { printf( "-- Database at %s not reachable\n", dbIpAddr); if(!remotequill) { char *tmp_hist = param("HISTORY"); if (!customFormat) { printf( "--Failing over to the history file at %s instead --\n", tmp_hist ? tmp_hist : "(null)" ); } if(!tmp_hist) { free(tmp_hist); } readfromfile = true; } } // query history table if (historySnapshot->isHistoryEmpty()) { printf("No historical jobs in the database match your query\n"); } historySnapshot->release(); delete(historySnapshot); } #endif /* HAVE_EXT_POSTGRESQL */ if(readfromfile == true) { readHistoryFromFiles(fileisuserlog, JobHistoryFileName, my_constraint.c_str(), constraintExpr); } else { readHistoryRemote(constraintExpr); } #ifdef HAVE_EXT_POSTGRESQL if(completedsince) free(completedsince); if(parameters) free(parameters); if(dbIpAddr) free(dbIpAddr); if(dbName) free(dbName); if(queryPassword) free(queryPassword); if(dbconn) free(dbconn); #endif return 0; }
void parseArgv( int argc, char* argv[] ) { int i; my_name = strdup(argv[0]); cmd = DRAIN_JOBS; for( i=1; i<argc; i++ ) { if( match_prefix( argv[i], "-help" ) ) { usage(my_name); } else if( match_prefix( argv[i], "-version" ) ) { version(); } else if( is_dash_arg_prefix( argv[i], "verbose", 4 ) ) { dash_verbose = 1; } else if( match_prefix( argv[i], "-pool" ) ) { if( i+1 >= argc ) another(argv[i]); if (pool) { free(pool); } pool = strdup(argv[++i]); } else if( match_prefix( argv[i], "-cancel" ) ) { cmd = CANCEL_DRAIN_JOBS; } else if( match_prefix( argv[i], "-fast" ) ) { how_fast = DRAIN_FAST; } else if( match_prefix( argv[i], "-quick" ) ) { how_fast = DRAIN_QUICK; } else if( match_prefix( argv[i], "-graceful" ) ) { how_fast = DRAIN_GRACEFUL; } else if( match_prefix( argv[i], "-resume-on-completion" ) ) { resume_on_completion = true; } else if( match_prefix( argv[i], "-request-id" ) ) { if( i+1 >= argc ) another(argv[i]); if (cancel_request_id) { free(cancel_request_id); } cancel_request_id = strdup(argv[++i]); } else if( match_prefix( argv[i], "-check" ) ) { if( i+1 >= argc ) another(argv[i]); if (draining_check_expr) { free(draining_check_expr); } draining_check_expr = strdup(argv[++i]); } else if( argv[i][0] != '-' ) { break; } else { fprintf(stderr,"ERROR: unexpected argument: %s\n", argv[i]); exit(2); } } if( i != argc-1 ) { fprintf(stderr,"ERROR: must specify one target machine\n"); exit(2); } target = strdup(argv[i]); if( cmd == DRAIN_JOBS ) { if( cancel_request_id ) { fprintf(stderr,"ERROR: -request-id may only be used with -cancel\n"); exit(2); } } if( cmd == CANCEL_DRAIN_JOBS ) { if( draining_check_expr ) { fprintf(stderr,"ERROR: -check may not be used with -cancel\n"); exit(2); } } }
// runs all of the tests in non-verbose mode by default (i.e. printing only failures) // individual groups of tests can be run by using the -t:<tests> option where <tests> // is one or more of // l testing_lookups // $ testing_$_expand // [ testing_$$_expand // e testing_$ENV_expand // F testing_$F_expand and testing_$F_regressions // c testing_$CHOICE_expand // s testing_$SUBSTR_expand // i testing_$INT_expand // r testing_$REAL_expand // n testing_$INT_expand and testing_$REAL_expand // r testing_$RAND_expand (RANDOM_INTEGER and RANDOM_CHOICE) // P testing_parser config/submit/metaknob parser. // int main( int /*argc*/, const char ** argv) { int test_flags = 0; const char * pcolon; for (int ii = 1; argv[ii]; ++ii) { const char *arg = argv[ii]; if (is_dash_arg_prefix(arg, "verbose", 1)) { dash_verbose = 1; } else if (is_dash_arg_colon_prefix(arg, "test", &pcolon, 1)) { if (pcolon) { while (*++pcolon) { switch (*pcolon) { case 'l': test_flags |= 0x0001; break; // lookup case '$': test_flags |= 0x0002; break; // $ case '[': test_flags |= 0x0004; break; // $$ case 'e': test_flags |= 0x0008; break; // $ENV case 'F': test_flags |= 0x0010 | 0x0020; break; // $F case 'c': test_flags |= 0x0040; break; // $CHOICE case 's': test_flags |= 0x0080; break; // $SUBSTR case 'i': test_flags |= 0x0100; break; // $INT case 'f': test_flags |= 0x0200; break; // $REAL case 'n': test_flags |= 0x0100 | 0x0200; break; // $INT, $REAL case 'r': test_flags |= 0x0400; break; // $RANDOM_INTEGER and $RANDOM_CHOICE case 'p': test_flags |= 0x1000; break; // parse } } } else { test_flags = 3; } } else { fprintf(stderr, "unknown argument %s\n", arg); return 1; } } if ( ! test_flags) test_flags = -1; TestingMacroSet.defaults->size = param_info_init((const void**)&TestingMacroSet.defaults->table); TestingMacroSet.options |= CONFIG_OPT_DEFAULTS_ARE_PARAM_INFO; insert_testing_macros(NULL, "TEST"); optimize_macros(TestingMacroSet); if (test_flags & 0x0001) testing_lookups(dash_verbose); if (test_flags & 0x0002) testing_$_expand(dash_verbose); if (test_flags & 0x0004) testing_$$_expand(dash_verbose); if (test_flags & 0x0008) testing_$ENV_expand(dash_verbose); if (test_flags & 0x0010) testing_$F_expand(dash_verbose); if (test_flags & 0x0020) testing_$F_regressions(dash_verbose); if (test_flags & 0x0040) testing_$CHOICE_expand(dash_verbose); if (test_flags & 0x0080) testing_$SUBSTR_expand(dash_verbose); if (test_flags & 0x0100) testing_$INT_expand(dash_verbose); if (test_flags & 0x0200) testing_$REAL_expand(dash_verbose); if (test_flags & 0x0400) testing_$RAND_expand(dash_verbose); if (test_flags & 0x1000) testing_parser(dash_verbose); return fail_count > 0; }