static void enable_debug( void ) { param_functions *p_funcs = get_param_functions(); Termlog = 1; dprintf_config ( "TOOL", p_funcs ); }
int main(int argc, char **argv) { // Set up the dprintf stuff... Termlog = true; dprintf_config("test_write_term", get_param_functions()); set_debug_flags(NULL, D_ALWAYS); int result = 0; Arguments args; Status tmpStatus = CheckArgs(argc, argv, args); if ( tmpStatus == STATUS_OK ) { result = WriteTermEvent(args); } else if ( tmpStatus == STATUS_ERROR ) { result = 1; } if ( args.writeExec && (tmpStatus == STATUS_OK) && (result == 0) ) { result = WriteExecEvent(args); } if ( result != 0 ) { fprintf(stderr, "test_write_term FAILED\n"); } return result; }
/* some pretty lame, but useful test code */ int main(int argc, char **argv) { WindowsFirewallHelper wfh; int result; bool isOn; const char* app; param_functions *p_funcs = NULL; result = 0; Termlog = 1; p_funcs = get_param_functions(); dprintf_config ("TOOL", p_funcs ); isOn = wfh.firewallIsOn(); printf("firewall is %s.\n", (isOn) ? "On" : "Off"); if ( argc <= 1 ) { app = "C:\\Condor\\bin\\condor_master.exe"; } else { app = argv[1]; } isOn = wfh.applicationIsTrusted(app); printf("%s is %s by the firewall.\n", app, (isOn) ? "Trusted" : "Not Trusted"); wfh.removeTrusted(app); // wfh.addTrusted(app); if ( ! wfh.addTrusted("C:\\Condor\\bin\\condor_master.exe") ) { printf("first addTrusted() failed\n"); result = 1; } if ( ! wfh.addTrusted("C:\\Condor\\condor_master.exe") ) { printf("second addTrusted() failed\n"); result = 1; } if ( ! wfh.removeTrusted("C:\\Condor\\bin\\condor_master.exe") ) { printf("first removeTrusted() failed\n"); result = 1; } if ( ! wfh.removeTrusted("C:\\Condor\\bin\\condor_master.exe") ) { printf("second removeTrusted() failed\n"); result = 1; } printf("tests are done!\n"); return result; }
int main(int argc, char** argv) { int retval = 0; Termlog = 1; dprintf_config("TOOL", get_param_functions()); set_debug_flags(0, D_ALWAYS); config(); retval = sysapi_test_dump_all(argc, argv); printf("Failed tests = %d\n",retval); return (retval); }
int main() { Termlog = 1; dprintf_config("TOOL", get_param_functions()); LocalServer* server = new LocalServer; ASSERT(server != NULL); if (!server->initialize(PIPE_ADDR)) { EXCEPT("unable to initialize LocalServer\n"); } while (true) { bool ready; if (!server->accept_connection(10, ready)) { EXCEPT("error in LocalServer::accept_connection\n"); } if (ready) { char c; if (!server->read_data(&c, sizeof(char))) { EXCEPT("error in LocalServer::read_data"); } if (!server->write_data(&c, sizeof(char))) { EXCEPT("error in LocalServer::write_data"); } if (!server->close_connection()) { EXCEPT("error in LocalServer::close_connection"); } printf("received: %c\n", c); if (c == 'q') { break; } } else { printf("timeout!\n"); } } return 0; }
int main(int argc, char* argv[]) { char *procd_address = NULL; myDistro->Init(argc, argv); if (argc < 2) { fprintf(stderr, "Usage: %s <options w/arguments> <command> [<arg> ...]\n", argv[0]); list_commands(); return 1; } config(); Termlog = 1; dprintf_config("TOOL", get_param_functions()); int cmd_argc = argc - 1; char** cmd_argv = argv + 1; // Process the first set of options. while(cmd_argv[0] != NULL && cmd_argv[0][0] == '-') { if (strcmp(cmd_argv[0], "-A") == MATCH) { cmd_argc--; cmd_argv++; if (cmd_argc == 0) { fprintf(stderr, "error: -A needs an argument\n"); list_commands(); return 1; } // store the argument to -A as the file we'll use. procd_address = cmd_argv[0]; cmd_argc--; cmd_argv++; continue; } else if (strcmp(cmd_argv[0], "-h") == MATCH) { cmd_argc--; cmd_argv++; fprintf(stderr, "Usage: %s <options w/arguments> <command> [<arg> ...]\n", argv[0]); list_commands(); return 1; continue; } // This is the failure case if we manage to pass all checks above. fprintf(stderr, "error: Don't understand option %s\n", cmd_argv[0]); list_commands(); return 1; } // If there are no command line arguments left, then there is no // command specified after the options, which is a failure. if (cmd_argc == 0) { fprintf(stderr, "Please specify a command.\n" "Usage: %s <options w/arguments> <command> [<arg> ...]\n", argv[0]); list_commands(); return 1; } // If a procd address wasn't specified on the command line, see if we // have an entry in a config file to use. if (procd_address == NULL) { procd_address = param("PROCD_ADDRESS"); if (procd_address == NULL) { fprintf(stderr, "error: PROCD_ADDRESS not defined\n"); return 1; } } ProcFamilyClient pfc; if (!pfc.initialize(procd_address)) { fprintf(stderr, "error: failed to initialize ProcD client\n"); return 1; } // Process this single command we should be performing if (strcasecmp(cmd_argv[0], "REGISTER_FAMILY") == 0) { return register_family(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "TRACK_BY_ASSOCIATED_GID") == 0) { return track_by_associated_gid(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "TRACK_BY_ASSOCIATED_CGROUP") == 0) { return track_by_associated_cgroup(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "GET_USAGE") == 0) { return get_usage(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "DUMP") == 0) { return dump(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "LIST") == 0) { return list(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "SIGNAL_PROCESS") == 0) { return signal_process(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "SUSPEND_FAMILY") == 0) { return suspend_family(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "CONTINUE_FAMILY") == 0) { return continue_family(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "KILL_FAMILY") == 0) { return kill_family(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "UNREGISTER_FAMILY") == 0) { return unregister_family(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "SNAPSHOT") == 0) { return snapshot(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "QUIT") == 0) { return quit(pfc, cmd_argc, cmd_argv); } else { fprintf(stderr, "error: invalid command: %s\n", cmd_argv[0]); list_commands(); return 1; } }
int main(int argc, char **argv) { ClassAd ad, context; char *str; int i; float f; bool b; myDistro->Init(argc, argv); config(); Termlog = true; dprintf_config("TEST", get_param_functions()); ad.Assign("REEVALUATE_ATTRIBUTES", "INTEGER, FLOAT, STRING, BOOL, REF"); ad.AssignExpr("REEVALUATE_INTEGER_EXPR", "MY.INTEGER + 1"); ad.AssignExpr("REEVALUATE_FLOAT_EXPR", "MY.FLOAT + 0.1"); ad.AssignExpr("REEVALUATE_STRING_EXPR", "strcat(MY.STRING, \",\", MY.STRING)"); ad.AssignExpr("REEVALUATE_BOOL_EXPR", "MY.BOOL && FALSE"); ad.AssignExpr("REEVALUATE_REF_EXPR", "MY.REF + TARGET.REF"); ad.Assign("INTEGER", 1); ad.Assign("FLOAT", 1.0); ad.Assign("STRING", "Hello"); ad.Assign("BOOL", true); ad.Assign("REF", 3); context.Assign("REF", 2); dprintf(D_FULLDEBUG, "context ad:\n"); context.dPrint(D_FULLDEBUG); dprintf(D_FULLDEBUG, "ad to update:\n"); ad.dPrint(D_FULLDEBUG); if (!classad_reevaluate(&ad, &context)) { return 1; } dprintf(D_FULLDEBUG, "updated ad:\n"); ad.dPrint(D_FULLDEBUG); if (ad.LookupInteger("INTEGER", i)) { if (2 != i) { return 2; } } else { return 3; } if (ad.LookupFloat("FLOAT", f)) { if (1.1f != f) { return 4; } } else { return 5; } if (ad.LookupString("STRING", &str)) { if (strcmp(str, "Hello,Hello")) { free(str); return 6; } free(str); } else { return 7; } if (ad.LookupBool("BOOL", b)) { if (b) { return 8; } } else { return 9; } if (ad.LookupInteger("REF", i)) { if (5 != i) { return 10; } } else { return 11; } return 0; }
int main( int argc, char *argv[] ) { const char *filename=0; char *pool=0; int command=-1; int i; bool use_tcp = false; bool with_ack = false; bool allow_multiple = false; param_functions *p_funcs = NULL; myDistro->Init( argc, argv ); config(); p_funcs = get_param_functions(); for( i=1; i<argc; i++ ) { if(!strcmp(argv[i],"-help")) { usage(argv[0]); exit(0); } else if(!strcmp(argv[i],"-pool")) { i++; if(!argv[i]) { fprintf(stderr,"-pool requires an argument.\n\n"); usage(argv[0]); exit(1); } pool = argv[i]; } else if(!strncmp(argv[i],"-tcp",strlen(argv[i]))) { use_tcp = true; } else if(!strncmp(argv[i],"-multiple",strlen(argv[i]))) { // We don't set allow_multiple=true by default, because // existing users (e.g. glideinWMS) have stray blank lines // in the input file. allow_multiple = true; } else if(!strcmp(argv[i],"-version")) { version(); exit(0); } else if(!strcmp(argv[i],"-debug")) { // dprintf to console Termlog = 1; p_funcs = get_param_functions(); dprintf_config ("TOOL", p_funcs); } else if(argv[i][0]!='-' || !strcmp(argv[i],"-")) { if(command==-1) { command = getCollectorCommandNum(argv[i]); if(command==-1) { fprintf(stderr,"Unknown command name %s\n\n",argv[i]); usage(argv[0]); exit(1); } } else if(!filename) { filename = argv[i]; } else { fprintf(stderr,"Extra argument: %s\n\n",argv[i]); usage(argv[0]); exit(1); } } else { fprintf(stderr,"Unknown argument: %s\n\n",argv[i]); usage(argv[0]); exit(1); } } FILE *file; ClassAdList ads; Daemon *collector; Sock *sock; switch( command ) { case UPDATE_STARTD_AD_WITH_ACK: with_ack = true; break; } if( with_ack ) { use_tcp = true; } if(!filename || !strcmp(filename,"-")) { file = stdin; filename = "(stdin)"; } else { file = safe_fopen_wrapper_follow(filename,"r"); } if(!file) { fprintf(stderr,"couldn't open %s: %s\n",filename,strerror(errno)); return 1; } while(!feof(file)) { int eof=0,error=0,empty=0; char const *delim = "\n"; if( !allow_multiple ) { delim = "***"; } ClassAd *ad = new ClassAd(file,const_cast<char *>(delim),eof,error,empty); if(error) { fprintf(stderr,"couldn't parse ClassAd in %s\n",filename); delete ad; return 1; } if( empty ) { delete ad; break; } if( !allow_multiple && ads.Length() > 0 ) { fprintf(stderr,"ERROR: failed to parse '%s' as a ClassAd attribute\n",delim); delete ad; return 1; } ads.Insert(ad); } if(ads.Length() == 0) { fprintf(stderr,"%s is empty\n",filename); return 1; } CollectorList * collectors; if ( pool ) { collector = new Daemon( DT_COLLECTOR, pool, 0 ); collectors = new CollectorList(); collectors->append (collector); } else { collectors = CollectorList::create(); } bool had_error = false; collectors->rewind(); while (collectors->next(collector)) { dprintf(D_FULLDEBUG,"locating collector %s...\n", collector->name()); if(!collector->locate()) { fprintf(stderr,"couldn't locate collector: %s\n",collector->error()); had_error = true; continue; } dprintf(D_FULLDEBUG,"collector is %s located at %s\n", collector->hostname(),collector->addr()); sock = NULL; ClassAd *ad; int success_count = 0; int failure_count = 0; ads.Rewind(); while( (ad=ads.Next()) ) { // If there's no "MyAddress", generate one.. if( !ad->Lookup( ATTR_MY_ADDRESS ) ) { MyString tmp; tmp.formatstr( "<%s:0>", my_ip_string() ); ad->Assign( ATTR_MY_ADDRESS, tmp.Value() ); } if ( use_tcp ) { if( !sock ) { sock = collector->startCommand(command,Stream::reli_sock,20); } else { // Use existing connection. sock->encode(); sock->put(command); } } else { // We must open a new UDP socket each time. delete sock; sock = collector->startCommand(command,Stream::safe_sock,20); } int result = 0; if ( sock ) { result += ad->put( *sock ); result += sock->end_of_message(); } if ( result != 2 ) { fprintf(stderr,"failed to send classad to %s\n",collector->addr()); had_error = true; failure_count++; delete sock; sock = NULL; continue; } if( with_ack ) { sock->decode(); int ok = 0; if( !sock->get(ok) || !sock->end_of_message() ) { fprintf(stderr,"failed to get ack from %s\n",collector->addr()); had_error = true; failure_count++; delete sock; sock = NULL; continue; } // ack protocol does not allow for multiple updates, // so close the socket now delete sock; sock = NULL; } success_count++; } if( sock ) { CondorVersionInfo const *ver = sock->get_peer_version(); if( !ver || ver->built_since_version(7,7,3) ) { // graceful hangup so the collector knows we are done sock->encode(); command = DC_NOP; sock->put(command); sock->end_of_message(); } delete sock; sock = NULL; } printf("Sent %d of %d ad%s to %s.\n", success_count, success_count + failure_count, success_count+failure_count == 1 ? "" : "s", collector->name()); } delete collectors; return (had_error)?1:0; }
int main(int argc, const char **argv) { set_debug_flags(NULL, D_ALWAYS); // initialize to read from config file myDistro->Init( argc, argv ); config(); // Set up the dprintf stuff... Termlog = true; dprintf_config("TEST_NETWORK_ADAPTER", get_param_functions()); const char *tmp; int status = 0; Options opts; if ( CheckArgs(argc, argv, opts) ) { exit( 1 ); } NetworkAdapterBase *net = NULL; if ( opts.m_if_name ) { printf( "Creating network adapter object for name %s\n", opts.m_if_name ); net = NetworkAdapterBase::createNetworkAdapter( opts.m_if_name ); } else { MyString sinful; sinful.formatstr( "<%s:1234>", opts.m_address ); printf( "Creating network adapter object for %s\n", sinful.Value() ); net = NetworkAdapterBase::createNetworkAdapter( sinful.Value() ); } if ( !net ) { printf( "Error creating adapter\n" ); exit(1); } // Initialize it if ( !net->getInitStatus() ) { printf( "Initialization of adaptor with address %s failed\n", opts.m_address ); delete net; exit(1); } // And, check for it's existence if ( !net->exists() ) { printf( "Adaptor with address %s not found\n", opts.m_address ); delete net; exit(1); } // Now, extract information from it tmp = net->hardwareAddress(); if ( !tmp || !strlen(tmp) ) tmp = "<NONE>"; printf( "hardware address: %s\n", tmp ); tmp = net->subnetMask(); if ( !tmp || !strlen(tmp) ) tmp = "<NONE>"; printf( "subnet: %s\n", tmp ); printf( "wakable: %s\n", net->isWakeable() ? "YES" : "NO" ); MyString tmpstr; net->wakeSupportedString( tmpstr ); printf( "wake support flags: %s\n", tmpstr.Value() ); net->wakeEnabledString( tmpstr ); printf( "wake enable flags: %s\n", tmpstr.Value() ); HibernatorBase *hibernator = new RealHibernator( ); if ( opts.m_method ) { printf( "Setting method to %s\n", opts.m_method ); hibernator->setMethod( opts.m_method ); } HibernationManager hman( hibernator ); if ( !hman.initialize( ) ) { fprintf( stderr, "Initialization of hibernation manager failed\n" ); status = 1; } hman.addInterface( *net ); ClassAd ad; hman.publish( ad ); ad.fPrint( stdout ); const char *method = hman.getHibernationMethod(); printf( "Hibernation method used: %s\n", method ); printf( "Can hibernate: %s\n", BoolString(hman.canHibernate()) ); printf( "Can wake: %s\n", BoolString(hman.canWake()) ); if ( hman.canHibernate() && opts.m_state != HibernatorBase::NONE ) { printf( "Setting state %s\n", hman.sleepStateToString(opts.m_state) ); if ( ! hman.switchToState( opts.m_state ) ) { printf( "Failed to switch states\n" ); status = 1; } } if ( status != 0 && opts.m_verbosity >= 1 ) { fprintf(stderr, "test_hibernation FAILED\n"); } delete net; return status; }
int main( int argc, char* argv[] ) { int i; param_functions *p_funcs = NULL; set_mySubSystem( "DAEMON-TOOL", SUBSYSTEM_TYPE_TOOL ); MyName = argv[0]; myDistro->Init( argc, argv ); FILE *input_fp = stdin; for( i=1; i<argc; i++ ) { if( match_prefix( argv[i], "-daemontype" ) ) { if( argv[i + 1] ) { get_mySubSystem()->setName( argv[++i] ); get_mySubSystem()->setTypeFromName( ); } else { usage(); } } else if( match_prefix( argv[i], "-debug" ) ) { // dprintf to console Termlog = 1; p_funcs = get_param_functions(); dprintf_config( "DAEMON-TOOL", p_funcs ); set_debug_flags(NULL, D_FULLDEBUG|D_SECURITY); } else if( match_prefix( argv[i], "-" ) ) { usage(); } else { usage(); } } // If we didn't get told what subsystem we should use, set it // to "TOOL". if( !get_mySubSystem()->isNameValid() ) { get_mySubSystem()->setName( "DAEMON-TOOL" ); } config( 0, true ); IpVerify ipverify; MyString line; while( line.readLine(input_fp) ) { line.chomp(); if( line.IsEmpty() || line[0] == '#' ) { printf("%s\n",line.Value()); continue; } StringList fields(line.Value()," "); fields.rewind(); char const *perm_str = fields.next(); char const *fqu = fields.next(); char const *ip = fields.next(); char const *expected = fields.next(); MyString sin_str = generate_sinful(ip, 0); condor_sockaddr addr; if( !addr.from_sinful(sin_str) ) { fprintf(stderr,"Invalid ip address: %s\n",ip); exit(1); } DCpermission perm = StringToDCpermission(perm_str); if( perm == LAST_PERM ) { fprintf(stderr,"Invalid permission level: %s\n",perm_str); exit(1); } if( strcmp(fqu,"*") == 0 ) { fqu = ""; } char const *result; MyString reason; if( ipverify.Verify(perm,addr,fqu,&reason,&reason) != USER_AUTH_SUCCESS ) { result = "DENIED"; } else { result = "ALLOWED"; } if( expected && strcasecmp(expected,result) != 0 ) { printf("Got wrong result '%s' for '%s': reason: %s!\n", result,line.Value(),reason.Value()); printf("Aborting.\n"); exit(1); } if( expected ) { printf("%s\n",line.Value()); } else { printf("%s %s\n",line.Value(),result); } } }
int main(int argc, const char **argv) { set_debug_flags(NULL, D_ALWAYS); param_functions *p_funcs = NULL; set_mySubSystem( "TEST_LOG_READER_STATE", SUBSYSTEM_TYPE_TOOL ); // initialize to read from config file myDistro->Init( argc, argv ); config(); // Set up the dprintf stuff... p_funcs = get_param_functions(); dprintf_config("TEST_LOG_READER_STATE", p_funcs); Options opts; if ( CheckArgs( argc, argv, opts ) < 0 ) { fprintf( stderr, "CheckArgs() failed\n" ); exit( 1 ); } ReadUserLog::FileState state; if ( opts.needStateFile() && ( ReadState( opts, state ) < 0 ) ) { fprintf( stderr, "ReadState() failed\n" ); exit( 1 ); } ReadUserLog::FileState state2; if ( opts.needStateFile2() && ( ReadState( opts, state2 ) < 0 ) ) { fprintf( stderr, "ReadState() failed\n" ); exit( 1 ); } int status = 0; switch( opts.getCommand() ) { case CMD_NONE: status = -1; break; case CMD_LIST: opts.dumpFieldList( ); break; case CMD_DUMP: status = DumpState( opts, state ); break; case CMD_DIFF: status = DiffState( opts, state, state2 ); break; case CMD_ACCESS: status = CheckStateAccess( opts, state ); break; case CMD_VERIFY: status = VerifyState( opts, state ); break; } if ( status == 0 ) { exit( 0 ); } else { exit( 2 ); } }
bool parseCommandLine(StoreCredOptions *opts, int argc, char *argv[]) { int i; param_functions *p_funcs = NULL; opts->mode = 0; opts->pw[0] = opts->pw[MAX_PASSWORD_LENGTH] = '\0'; opts->username[0] = opts->username[MAX_PASSWORD_LENGTH] = '\0'; opts->daemonname = NULL; opts->password_file = NULL;; opts->help = false; bool err = false; for (i=1; i<argc && !err; i++) { switch(argv[i][0]) { case 'a': case 'A': // Add if (strcasecmp(argv[i], ADD_CREDENTIAL) == 0) { if (!opts->mode) { opts->mode = ADD_MODE; } else if (opts->mode != ADD_MODE) { fprintf(stderr, "ERROR: exactly one command must be provided\n"); usage(); err = true; } } else { err = true; badCommand(argv[i]); } break; case 'd': case 'D': // Delete if (strcasecmp(argv[i], DELETE_CREDENTIAL) == 0) { if (!opts->mode) { opts->mode = DELETE_MODE; } else if (opts->mode != DELETE_MODE) { fprintf(stderr, "ERROR: exactly one command must be provided\n"); usage(); err = true; } } else { err = true; badCommand(argv[i]); } break; case 'q': case 'Q': // tell me if I have anything stored if (strcasecmp(argv[i], QUERY_CREDENTIAL) == 0) { if (!opts->mode) { opts->mode = QUERY_MODE; } else if (opts->mode != QUERY_MODE) { fprintf(stderr, "ERROR: exactly one command must be provided\n"); usage(); err = true; } } else { err = true; badCommand(argv[i]); } break; #if defined(WIN32) case 'c': case 'C': // Config if (strcasecmp(argv[i], CONFIG_CREDENTIAL) == 0) { if (!opts->mode) { opts->mode = CONFIG_MODE; } else { fprintf(stderr, "ERROR: exactly one command must be provided\n"); usage(); err = true; } } else { err = true; badCommand(argv[i]); } break; #endif case '-': // various switches switch (argv[i][1]) { case 'n': if (i+1 < argc) { if (opts->daemonname != NULL) { fprintf(stderr, "ERROR: only one '-n' arg my be provided\n"); usage(); err = true; } else { opts->daemonname = get_daemon_name(argv[i+1]); if (opts->daemonname == NULL) { fprintf(stderr, "ERROR: %s is not a valid daemon name\n", argv[i+1]); err = true; } i++; } } else { err = true; optionNeedsArg(argv[i]); } break; case 'p': if (i+1 < argc) { if (opts->pw[0] != '\0') { fprintf(stderr, "ERROR: only one '-p' args may be provided\n"); usage(); err = true; } else { strncpy(opts->pw, argv[i+1], MAX_PASSWORD_LENGTH); i++; } } else { err = true; optionNeedsArg(argv[i]); } break; case 'c': if (opts->username[0] != '\0') { fprintf(stderr, "ERROR: only one '-c' or '-u' arg may be provided\n"); usage(); err = true; } else { strcpy(opts->username, POOL_PASSWORD_USERNAME); } break; case 'u': if (i+1 < argc) { if (opts->username[0] != '\0') { fprintf(stderr, "ERROR: only one of '-s' or '-u' may be provided\n"); usage(); err = true; } else { strncpy(opts->username, argv[i+1], MAX_PASSWORD_LENGTH); i++; char* at_ptr = strchr(opts->username, '@'); // '@' must be in the string, but not the beginning // or end of the string. if (at_ptr == NULL || at_ptr == opts->username || at_ptr == opts->username+strlen(opts->username)-1) { fprintf(stderr, "ERROR: Username '%s' is not of " "the form: account@domain\n", opts->username); usage(); } } } else { err = true; optionNeedsArg(argv[i]); } break; #if !defined(WIN32) case 'f': if (i+1 >= argc) { err = true; optionNeedsArg(argv[i]); } opts->password_file = argv[i+1]; i++; opts->mode = ADD_MODE; break; #endif case 'd': Termlog = 1; p_funcs = get_param_functions(); dprintf_config ("TOOL", p_funcs); break; case 'h': opts->help = true; break; default: err = true; badOption(argv[i]); } break; // break for case '-' default: err = true; badCommand(argv[i]); break; } } return !err; }
//--------------------------------------------------------------------------- int main(int argc, char *argv[]) { param_functions *p_funcs = NULL; printf("\n"); // Set up the dprintf stuff to write to stderr, so that Condor // libraries which use it will write to the right place... Termlog = true; p_funcs = get_param_functions(); dprintf_config("condor_submit_dag", p_funcs); set_debug_flags(NULL, D_ALWAYS | D_NOHEADER); config(); // Initialize our Distribution object -- condor vs. hawkeye, etc. myDistro->Init( argc, argv ); // Load command-line arguments into the deepOpts and shallowOpts // structures. SubmitDagDeepOptions deepOpts; SubmitDagShallowOptions shallowOpts; parseCommandLine(deepOpts, shallowOpts, argc, argv); int tmpResult; // Recursively run ourself on nested DAGs. We need to do this // depth-first so all of the lower-level .condor.sub files already // exist when we check for log files. if ( deepOpts.recurse ) { tmpResult = doRecursion( deepOpts, shallowOpts ); if ( tmpResult != 0) { fprintf( stderr, "Recursive submit(s) failed; exiting without " "attempting top-level submit\n" ); return tmpResult; } } // Further work to get the shallowOpts structure set up properly. tmpResult = setUpOptions( deepOpts, shallowOpts ); if ( tmpResult != 0 ) return tmpResult; // Check whether the output files already exist; if so, we may // abort depending on the -f flag and whether we're running // a rescue DAG. ensureOutputFilesExist( deepOpts, shallowOpts ); // Make sure that all node jobs have log files, the files // aren't on NFS, etc. // Note that this MUST come after recursion, otherwise we'd // pass down the "preserved" values from the current .condor.sub // file. if ( deepOpts.updateSubmit ) { tmpResult = getOldSubmitFlags( shallowOpts ); if ( tmpResult != 0 ) return tmpResult; } // Write the actual submit file for DAGMan. writeSubmitFile( deepOpts, shallowOpts ); return submitDag( shallowOpts ); }
int main(int argc, char **argv) { char * server_address = NULL; char * cred_name = NULL; char ** ptr; const char * myName; // find our name myName = strrchr( argv[0], DIR_DELIM_CHAR ); if( !myName ) { myName = argv[0]; } else { myName++; } // read config file myDistro->Init (argc, argv); config(); for (ptr=argv+1,argc--; argc > 0; argc--,ptr++) { if ( ptr[0][0] == '-' ) { switch ( ptr[0][1] ) { case 'h': usage(myName); exit(0); break; case 'd': // dprintf to console Termlog = 1; dprintf_config ("TOOL", get_param_functions()); break; case 'n': if( !(--argc) || !(*(++ptr)) ) { fprintf( stderr, "%s: -n requires another argument\n", myName ); exit(1); } server_address = strdup (*ptr); break; case 'N': if( !(--argc) || !(*(++ptr)) ) { fprintf( stderr, "%s: -N requires another argument\n", myName ); exit(1); } cred_name = strdup (*ptr); break; case 'v': version(); // this function calls exit(0) break; default: fprintf( stderr, "%s: Unknown option %s\n", myName, *ptr); usage(myName); exit(1); } } //fi else { fprintf( stderr, "%s: Unknown option %s\n", myName, *ptr); usage(myName); exit(1); } } //rof if (cred_name == NULL) { cred_name = DEFAULT_CREDENTIAL_NAME; } CondorError errstack; DCCredd dc_credd (server_address); // resolve server address if ( ! dc_credd.locate() ) { fprintf (stderr, "%s\n", dc_credd.error() ); return 1; } if (dc_credd.removeCredential(cred_name, errstack)) { fprintf (stderr, "Unable to remove credential '%s'\n%s\n", cred_name, errstack.getFullText(true).c_str()); return 1; } return 0; }
int main(int argc, char **argv) { char ** ptr; const char * myName; // find our name myName = strrchr( argv[0], DIR_DELIM_CHAR ); if( !myName ) { myName = argv[0]; } else { myName++; } int cred_type = 0; char * cred_name = NULL; char * cred_file_name = NULL; char * myproxy_user = NULL; char * myproxy_host = NULL; int myproxy_port = 0; char * myproxy_dn = NULL; char * server_address= NULL; // read config file myDistro->Init (argc, argv); config(); for (ptr=argv+1,argc--; argc > 0; argc--,ptr++) { if ( ptr[0][0] == '-' ) { switch ( ptr[0][1] ) { case 'h': usage(myName); exit(0); break; case 'd': // dprintf to console Termlog = 1; dprintf_config ("TOOL", get_param_functions()); break; case 'S': // dprintf to console Termlog = 1; Read_Myproxy_pw_terminal = false; break; case 'n': if( !(--argc) || !(*(++ptr)) ) { fprintf( stderr, "%s: -n requires another argument\n", myName ); exit(1); } server_address = strdup (*ptr); break; case 't': if( !(--argc) || !(*(++ptr)) ) { fprintf( stderr, "%s: -t requires another argument\n", myName ); exit(1); } if (strcmp (*ptr, "x509") == 0) { cred_type = X509_CREDENTIAL_TYPE; } else { fprintf( stderr, "Invalid credential type %s\n", *ptr ); exit(1); } break; case 'f': if( !(--argc) || !(*(++ptr)) ) { fprintf( stderr, "%s: -f requires another argument\n", myName ); exit(1); } cred_file_name = strdup (*ptr); break; case 'N': if( !(--argc) || !(*(++ptr)) ) { fprintf( stderr, "%s: -N requires another argument\n", myName ); exit(1); } cred_name = strdup (*ptr); break; case 'm': if( !(--argc) || !(*(++ptr)) ) { fprintf( stderr, "%s: -m requires another argument\n", myName ); exit(1); } parseMyProxyArgument (*ptr, myproxy_user, myproxy_host, myproxy_port); break; case 'D': if( !(--argc) || !(*(++ptr)) ) { fprintf( stderr, "%s: -D requires another argument\n", myName ); exit(1); } myproxy_dn = strdup (*ptr); break; case 'v': version(); // this function calls exit(0) break; default: fprintf( stderr, "%s: Unknown option %s\n", myName, *ptr); usage(myName); exit(1); } } //fi } //rof if (( cred_file_name == NULL ) || (cred_type == 0)) { fprintf ( stderr, "Credential filename or type not specified\n"); exit (1); } Credential * cred = NULL; if (cred_type == X509_CREDENTIAL_TYPE) { cred = new X509Credential(); } else { fprintf ( stderr, "Invalid credential type\n"); exit (1); } char * data = NULL; int data_size; if (!read_file (cred_file_name, data, data_size)) { fprintf (stderr, "Can't open %s\n", cred_file_name); exit (1); } cred->SetData (data, data_size); if (cred_name !=NULL) { cred->SetName(cred_name); } else { cred->SetName(DEFAULT_CREDENTIAL_NAME); } char * username = my_username(0); cred->SetOwner (username); if (cred_type == X509_CREDENTIAL_TYPE && myproxy_host != NULL) { X509Credential * x509cred = (X509Credential*)cred; MyString str_host_port = myproxy_host; if (myproxy_port != 0) { str_host_port += ":"; str_host_port += myproxy_port; } x509cred->SetMyProxyServerHost (str_host_port.Value()); if (myproxy_user != NULL) { x509cred->SetMyProxyUser (myproxy_user); } else { x509cred->SetMyProxyUser (username); } if (myproxy_dn != NULL) { x509cred->SetMyProxyServerDN (myproxy_dn); } char * myproxy_password; if ( Read_Myproxy_pw_terminal ) { myproxy_password = prompt_password( "Please enter the MyProxy password:"******"Please enter the MyProxy password from the standard input\n"); } if (myproxy_password) { x509cred->SetRefreshPassword ( myproxy_password ); } x509cred->display( D_FULLDEBUG ); } CondorError errstack; DCCredd dc_credd (server_address); // resolve server address if ( ! dc_credd.locate() ) { fprintf (stderr, "%s\n", dc_credd.error() ); return 1; } if (dc_credd.storeCredential(cred, errstack)) { printf ("Credential submitted successfully\n"); } else { fprintf (stderr, "Unable to submit credential\n%s\n", errstack.getFullText(true)); return 1; } return 0; }
void main_pre_dc_init( int argc, char* argv[] ) { param_functions *p_funcs = NULL; // figure out what get_mySubSystem() should be based on argv[0], or // if we see "-gridshell" anywhere on the command-line const char* base = condor_basename(argv[0]); char const *tmp; tmp = strrchr(base, '_' ); if( tmp && strncasecmp(tmp, "_gridshell", 10) == MATCH ) { get_mySubSystem()->setName( "GRIDSHELL" ); is_gridshell = true; } else { int i, len; for( i=1; i<argc; i++ ) { len = strlen(argv[i]); if( len < 3 ) { // ambiguous, bail out, since we don't want to get // confused with just "-" or something continue; } if( strncasecmp(argv[i], "-gridshell", MIN(len,10)) == MATCH ) { get_mySubSystem()->setName( "GRIDSHELL" ); is_gridshell = true; break; } } } if( ! is_gridshell ) { get_mySubSystem()->setName( "STARTER" ); } // if we were passed "-classad", just print our classad and // exit, without going back to daemoncore or anything. we // need to do this *after* we set get_mySubSystem(), since this ends // up calling functions that rely on it being defined... if( argc == 2 && strncasecmp(argv[1],"-cla",4) == MATCH ) { // needed for Java stuff config(true); // Would like to log errors to stderr if stderr is not // /dev/null to make it easier for users to debug, but not // sure how to do that on windows. On Windows, when // condor_starter is run by the startd, setting Termlog=1 // causes a dprintf to abort with an error if any calls to // dprintf() are made in a debug level that is turned on. // I have not found a way to detect when stderr is in this // state, so I am just leaving Termlog turned off in all // cases. //Termlog = 1; p_funcs = get_param_functions(); dprintf_config(get_mySubSystem()->getName(), p_funcs); printClassAd(); exit(0); } // if we're still here, stash the cwd for future reference MyString cwd; if( ! condor_getcwd(cwd)) { dprintf( D_ALWAYS, "ERROR calling getcwd(): %s (errno %d)\n", strerror(errno), errno ); } else { orig_cwd = strdup(cwd.Value()); } // if we're the gridshell, assume a "-f" option. all that // does in DaemonCore-land is set a global variable, so we'll // just do that here, ourselves... if( is_gridshell ) { Foreground = 1; } // finally, dup() our standard file streams, so we can pass // those onto the actual user job if requested. starter_stdin_fd = dup( 0 ); starter_stdout_fd = dup( 1 ); starter_stderr_fd = dup( 2 ); }
int main(int argc, char **argv) { char * server_address = NULL; char ** ptr; const char * myName; // find our name myName = strrchr( argv[0], DIR_DELIM_CHAR ); if( !myName ) { myName = argv[0]; } else { myName++; } // read config file myDistro->Init (argc, argv); config (); for (ptr=argv+1,argc--; argc > 0; argc--,ptr++) { if ( ptr[0][0] == '-' ) { switch ( ptr[0][1] ) { case 'h': usage(myName); exit(0); break; case 'd': // dprintf to console Termlog = 1; dprintf_config ("TOOL", get_param_functions()); break; case 'n': if( !(--argc) || !(*(++ptr)) ) { fprintf( stderr, "%s: -n requires another argument\n", myName ); exit(1); } server_address = strdup (*ptr); break; case 'v': version(); // this function calls exit(0) break; default: fprintf( stderr, "%s: Unknown option %s\n", myName, *ptr); usage(myName); exit(1); } } //fi } //rof CondorError errorstack; int number = 0; SimpleList <Credential*> result; DCCredd credd(server_address); // resolve server address if ( ! credd.locate() ) { fprintf (stderr, "%s\n", credd.error() ); return 1; } if (!credd.listCredentials (result, number, errorstack)) { fprintf (stderr, "Unable to retrieve credentials (%s)\n", errorstack.getFullText(true)); return 1; } if (number > 0) { Credential * cred; result.Rewind(); printf ("Name\tType\n-----\t-----\n"); while (result.Next (cred)) { printf ("%s\t%s\n", cred->GetName(), cred->GetTypeString()); } printf ("\nTotal %d\n", number); } else if (number == 0) { printf ("No credentials currently stored on this server\n"); } else { fprintf (stderr, "ERROR\n"); return 1; } return 0; }
int main(int argc, char* argv[]) { void **parameters; char* JobHistoryFileName=NULL; int i; parameters = (void **) malloc(NUM_PARAMETERS * sizeof(void *)); myDistro->Init( argc, argv ); config(); Termlog = 1; dprintf_config("TOOL", get_param_functions()); for(i=1; i<argc; i++) { if (strcmp(argv[i],"-f")==0) { if (i+1==argc || JobHistoryFileName) break; i++; JobHistoryFileName=argv[i]; } else if (strcmp(argv[i],"-help")==0) { Usage(argv[0],0); } else if (strcmp(argv[i],"-name")==0) { if (i+1==argc || ScheddName) break; i++; ScheddName=strdup(argv[i]); if ((i+1==argc) || ScheddBirthdate) break; i++; ScheddBirthdate = atoi(argv[i]); } /* else if (strcmp(argv[i],"-debug")==0) { // dprintf to console Termlog = 1; } */ else { Usage(argv[0]); } } if (i<argc) Usage(argv[0]); if (JobHistoryFileName == NULL) Usage(argv[0]); if ((ScheddName == NULL) || (ScheddBirthdate == 0)) { if (ScheddName) fprintf(stdout, "You specified Schedd name without a Job Queue" "Birthdate. Ignoring value %s\n", ScheddName); Daemon schedd( DT_SCHEDD, 0, 0 ); if ( schedd.locate() ) { char *scheddname; if( (scheddname = schedd.name()) ) { ScheddName = strdup(scheddname); } else { fprintf(stderr, "You did not specify a Schedd name and Job Queue " "Birthdate on the command line " "and there was an error getting the Schedd " "name from the local Schedd Daemon Ad. Please " "check that the SCHEDD_DAEMON_AD_FILE config " "parameter is set and the file contains a valid " "Schedd Daemon ad.\n"); exit(1); } ClassAd *daemonAd = schedd.daemonAd(); if(daemonAd) { if (!(daemonAd->LookupInteger( ATTR_JOB_QUEUE_BIRTHDATE, ScheddBirthdate) )) { // Can't find the job queue birthdate fprintf(stderr, "You did not specify a Schedd name and " "Job Queue Birthdate on the command line " "and there was an error getting the Job Queue " "Birthdate from the local Schedd Daemon Ad. Please " "check that the SCHEDD_DAEMON_AD_FILE config " "parameter is set and the file contains a valid " "Schedd Daemon ad.\n"); exit(1); } } } else { fprintf(stderr, "You did not specify a Schedd name and Job Queue " "Birthdate on the command line and there was " "an error getting the Schedd Daemon Ad. Please " "check that Condor is running and the SCHEDD_DAEMON_AD_FILE " "config parameter is set and the file contains a valid " "Schedd Daemon ad.\n"); exit(1); } } doDBconfig(); readHistoryFromFile(JobHistoryFileName); if(parameters) free(parameters); if(ScheddName) free(ScheddName); return 0; }