//call this program with a directory as an argument int main(int argc, char* argv[]) { //define variables to hold information about the current //directory. struct stat buf; int err, i, match; char *longPath; //If there are not enough arguments, don't go any further //and print a message to the user as to the function if (argc < 4) { printf("Usage is:\t%s (directory) -(selection) (argument)\n",argv[0]); return(1); } //Process arguments if (procArg(argv[1],argv[2],argv[3]) == -1) return(1); //get information about the supplied argument if ((err = (lstat(argv[1],&buf))) == -1) { perror(argv[1]); return(1); } //Get the absolute path of the supplied argument longPath = malloc(PATH_MAX); realpath(argv[1],longPath); //Run visitDir function if the argument is a directory if (!(S_ISDIR(buf.st_mode))) { printf("%s is not a directory.\n",longPath); return(1); } else { switch (selNum) { case 0: if (strcasecmp(argv[1],matchName) == 0) match = 1; break; case 2: if (buf.st_uid == uid) match = 1; break; default: break; } if (match == 1) printf("\tDIR:\t%s\n",longPath); visitDir(longPath); } return(0); }
int main(int argc, char *argv[]) { char *arg; int nArgs = 0; // number of args int i, result; char* pool = NULL; char* scheddName = NULL; char* scheddAddr = NULL; MyString method; char *tmp; myDistro->Init( argc, argv ); MyName = condor_basename(argv[0]); config(); #if !defined(WIN32) install_sig_handler(SIGPIPE, SIG_IGN ); #endif // dig around in the config file looking for what the config file says // about getting files from Condor. This defaults with the global variable // initialization. tmp = param( "SANDBOX_TRANSFER_METHOD" ); if ( tmp != NULL ) { method = tmp; free( tmp ); string_to_stm( method, st_method ); } char **args = (char **)malloc(sizeof(char *) * argc); // args if ( ! args) exit(2); // parse the arguments. for( argv++; (arg = *argv); argv++ ) { if( arg[0] == '-' ) { if( ! arg[1] ) { usage(); } switch( arg[1] ) { case 'd': // dprintf to console dprintf_set_tool_debug("TOOL", 0); break; case 'c': args[nArgs] = arg; nArgs++; argv++; if( ! *argv ) { fprintf( stderr, "%s: -constraint requires another argument\n", MyName); exit(1); } args[nArgs] = *argv; nArgs++; break; case 'a': if( arg[2] && arg[2] == 'd' ) { argv++; if( ! *argv ) { fprintf( stderr, "%s: -addr requires another argument\n", MyName); exit(1); } if( is_valid_sinful(*argv) ) { scheddAddr = strdup(*argv); if( ! scheddAddr ) { fprintf( stderr, "Out of Memory!\n" ); exit(1); } } else { fprintf( stderr, "%s: \"%s\" is not a valid address\n", MyName, *argv ); fprintf( stderr, "Should be of the form " "<ip.address.here:port>\n" ); fprintf( stderr, "For example: <123.456.789.123:6789>\n" ); exit( 1 ); } break; } All = true; break; case 'n': // use the given name as the schedd name to connect to argv++; if( ! *argv ) { fprintf( stderr, "%s: -name requires another argument\n", MyName); exit(1); } if ( scheddName ) free(scheddName); scheddName = strdup(*argv); break; case 'p': // use the given name as the central manager to query argv++; if( ! *argv ) { fprintf( stderr, "%s: -pool requires another argument\n", MyName); exit(1); } if( pool ) { free( pool ); } pool = strdup( *argv ); break; case 's': argv++; if( ! *argv ) { fprintf( stderr, "%s: -stm requires another argument\n", MyName); exit(1); } method = *argv; string_to_stm(method, st_method); break; case 'v': version(); break; case 'h': usage(0); break; default: fprintf( stderr, "Unrecognized option: %s\n", arg ); usage(); break; } } else { if( All ) { // If -all is set, there should be no other // constraint arguments. usage(); } args[nArgs] = arg; nArgs++; } } // Check to make sure we have a valid sandbox transfer mechanism. if (st_method == STM_UNKNOWN) { fprintf( stderr, "%s: Unknown sandbox transfer method: %s\n", MyName, method.Value()); usage(); exit(1); } if( ! (All || nArgs) ) { // We got no indication of what to act on fprintf( stderr, "You did not specify any jobs\n" ); usage(); } // We're done parsing args, now make sure we know how to // contact the schedd. if( ! scheddAddr ) { // This will always do the right thing, even if either or // both of scheddName or pool are NULL. schedd = new DCSchedd( scheddName, pool ); } else { schedd = new DCSchedd( scheddAddr ); } if( ! schedd->locate() ) { fprintf( stderr, "%s: %s\n", MyName, schedd->error() ); exit( 1 ); } // Process the args. if( All ) { handleAll(); } else { for(i = 0; i < nArgs; i++) { if( match_prefix( args[i], "-constraint" ) ) { i++; addConstraint( args[i] ); } else { procArg(args[i]); } } } // Sanity check: make certain we now have a constraint if ( global_constraint.Length() <= 0 ) { fprintf( stderr, "Unable to create a job constraint!\n"); exit(1); } fprintf(stdout,"Fetching data files...\n"); switch(st_method) { case STM_USE_SCHEDD_ONLY: { // start block // Get the sandbox directly from the schedd. // And now, do the work. CondorError errstack; result = schedd->receiveJobSandbox(global_constraint.Value(), &errstack); if ( !result ) { fprintf( stderr, "\n%s\n", errstack.getFullText(true).c_str() ); fprintf( stderr, "ERROR: Failed to spool job files.\n" ); exit(1); } // All done return 0; } //end block break; case STM_USE_TRANSFERD: { // start block // NEW METHOD where we ask the schedd for a transferd, then get the // files from the transferd CondorError errstack; ClassAd respad; int invalid; MyString reason; MyString td_sinful; MyString td_cap; result = schedd->requestSandboxLocation(FTPD_DOWNLOAD, global_constraint, FTP_CFTP, &respad, &errstack); if ( !result ) { fprintf( stderr, "\n%s\n", errstack.getFullText(true).c_str() ); fprintf( stderr, "ERROR: Failed to spool job files.\n" ); exit(1); } respad.LookupInteger(ATTR_TREQ_INVALID_REQUEST, invalid); if (invalid == TRUE) { fprintf( stderr, "ERROR: Failed to spool job files.\n" ); respad.LookupString(ATTR_TREQ_INVALID_REASON, reason); fprintf( stderr, "%s\n", reason.Value()); exit(EXIT_FAILURE); } respad.LookupString(ATTR_TREQ_TD_SINFUL, td_sinful); respad.LookupString(ATTR_TREQ_CAPABILITY, td_cap); dprintf(D_ALWAYS, "td: %s, cap: %s\n", td_sinful.Value(), td_cap.Value()); DCTransferD dctd(td_sinful.Value()); result = dctd.download_job_files(&respad, &errstack); if ( !result ) { fprintf( stderr, "\n%s\n", errstack.getFullText(true).c_str() ); fprintf( stderr, "ERROR: Failed to spool job files.\n" ); exit(1); } } // end block break; default: EXCEPT("PROGRAMMER ERROR: st_method must be known."); break; } // All done return 0; }
int main( int argc, char *argv[] ) { char *arg; char **args = (char **)malloc(sizeof(char *)*(argc - 1)); // args int nArgs = 0; // number of args int i; char* cmd_str; DCCollector* pool = NULL; char* scheddName = NULL; char* scheddAddr = NULL; // Initialize our global variables has_constraint = false; myDistro->Init( argc, argv ); MyName = strrchr( argv[0], DIR_DELIM_CHAR ); if( !MyName ) { MyName = argv[0]; } else { MyName++; } cmd_str = strchr( MyName, '_'); // we match modes based on characters after the '_'. This means // 'condor_hold.exe' or 'condor_hold_wrapped' are all legal argv[0]'s // for condor_hold. if (cmd_str && strncasecmp( cmd_str, "_hold", strlen("_hold") ) == MATCH) { mode = JA_HOLD_JOBS; } else if ( cmd_str && strncasecmp( cmd_str, "_release", strlen("_release") ) == MATCH ) { mode = JA_RELEASE_JOBS; } else if ( cmd_str && strncasecmp( cmd_str, "_suspend", strlen("_suspend") ) == MATCH ) { mode = JA_SUSPEND_JOBS; } else if ( cmd_str && strncasecmp( cmd_str, "_continue", strlen("_continue") ) == MATCH ) { mode = JA_CONTINUE_JOBS; }else if ( cmd_str && strncasecmp( cmd_str, "_rm", strlen("_rm") ) == MATCH ) { mode = JA_REMOVE_JOBS; } else if( cmd_str && ! strncasecmp(cmd_str, "_vacate_job", strlen("_vacate_job")) ) { mode = JA_VACATE_JOBS; } else { // don't know what mode we're using, so bail. fprintf( stderr, "Unrecognized command name, \"%s\"\n", MyName ); usage(); } config(); if( argc < 2 ) { // We got no indication of what to act on fprintf( stderr, "You did not specify any jobs\n" ); usage(); } #if !defined(WIN32) install_sig_handler(SIGPIPE, SIG_IGN ); #endif for( argv++; (arg = *argv); argv++ ) { if( arg[0] == '-' ) { if (match_prefix(arg, "-debug")) { // dprintf to console dprintf_set_tool_debug("TOOL", 0); } else if (match_prefix(arg, "-constraint")) { args[nArgs] = arg; nArgs++; argv++; if( ! *argv ) { fprintf( stderr, "%s: -constraint requires another argument\n", MyName); exit(1); } args[nArgs] = *argv; nArgs++; ConstraintArg = true; } else if (match_prefix(arg, "-all")) { All = true; } else if (match_prefix(arg, "-addr")) { argv++; if( ! *argv ) { fprintf( stderr, "%s: -addr requires another argument\n", MyName); exit(1); } if( is_valid_sinful(*argv) ) { scheddAddr = strdup(*argv); if( ! scheddAddr ) { fprintf( stderr, "Out of memory!\n" ); exit(1); } } else { fprintf( stderr, "%s: \"%s\" is not a valid address\n", MyName, *argv ); fprintf( stderr, "Should be of the form " "<ip.address.here:port>\n" ); fprintf( stderr, "For example: <123.456.789.123:6789>\n" ); exit( 1 ); } } else if (match_prefix(arg, "-reason")) { argv++; if( ! *argv ) { fprintf( stderr, "%s: -reason requires another argument\n", MyName); exit(1); } actionReason = strdup(*argv); if( ! actionReason ) { fprintf( stderr, "Out of memory!\n" ); exit(1); } } else if (match_prefix(arg, "-subcode")) { argv++; if( ! *argv ) { fprintf( stderr, "%s: -subcode requires another argument\n", MyName); exit(1); } char *end = NULL; long code = strtol(*argv,&end,10); if( code == LONG_MIN || !end || *end || end==*argv ) { fprintf( stderr, "Invalid -subcode %s!\n", *argv ); exit(1); } holdReasonSubCode = strdup(*argv); ASSERT( holdReasonSubCode ); } else if (match_prefix(arg, "-forcex")) { if( mode == JA_REMOVE_JOBS ) { mode = JA_REMOVE_X_JOBS; } else { fprintf( stderr, "-forcex is only valid with condor_rm\n" ); usage(); } } else if (match_prefix(arg, "-fast")) { if( mode == JA_VACATE_JOBS ) { mode = JA_VACATE_FAST_JOBS; } else { fprintf( stderr, "-fast is only valid with condor_vacate_job\n" ); usage(); } } else if (match_prefix(arg, "-name")) { // use the given name as the schedd name to connect to argv++; if( ! *argv ) { fprintf( stderr, "%s: -name requires another argument\n", MyName); exit(1); } if( !(scheddName = get_daemon_name(*argv)) ) { fprintf( stderr, "%s: unknown host %s\n", MyName, get_host_part(*argv) ); exit(1); } } else if (match_prefix(arg, "-pool")) { // use the given name as the central manager to query argv++; if( ! *argv ) { fprintf( stderr, "%s: -pool requires another argument\n", MyName); exit(1); } if( pool ) { delete pool; } pool = new DCCollector( *argv ); if( ! pool->addr() ) { fprintf( stderr, "%s: %s\n", MyName, pool->error() ); exit(1); } } else if (match_prefix(arg, "-version")) { version(); } else if (match_prefix(arg, "-help")) { usage(0); } else { fprintf( stderr, "Unrecognized option: %s\n", arg ); usage(); } } else { if( All ) { // If -all is set, there should be no other // constraint arguments. usage(); } args[nArgs] = arg; nArgs++; UserJobIdArg = true; } } if( ! (All || nArgs) ) { // We got no indication of what to act on fprintf( stderr, "You did not specify any jobs\n" ); usage(); } if ( ConstraintArg && UserJobIdArg ) { fprintf( stderr, "You can't use both -constraint and usernames or job ids\n" ); usage(); } // Pick the default reason if the user didn't specify one if( actionReason == NULL ) { switch( mode ) { case JA_RELEASE_JOBS: actionReason = strdup("via condor_release"); break; case JA_REMOVE_X_JOBS: actionReason = strdup("via condor_rm -forcex"); break; case JA_REMOVE_JOBS: actionReason = strdup("via condor_rm"); break; case JA_HOLD_JOBS: actionReason = strdup("via condor_hold"); break; case JA_SUSPEND_JOBS: actionReason = strdup("via condor_suspend"); break; case JA_CONTINUE_JOBS: actionReason = strdup("via condor_continue"); break; default: actionReason = NULL; } } // We're done parsing args, now make sure we know how to // contact the schedd. if( ! scheddAddr ) { // This will always do the right thing, even if either or // both of scheddName or pool are NULL. schedd = new DCSchedd( scheddName, pool ? pool->addr() : NULL ); } else { schedd = new DCSchedd( scheddAddr ); } if( ! schedd->locate() ) { fprintf( stderr, "%s: %s\n", MyName, schedd->error() ); exit( 1 ); } // Special case for condor_rm -forcex: a configuration // setting can disable this functionality. The real // validation is done in the schedd, but we can catch // the most common cases here and give a useful error // message. if(mode == JA_REMOVE_X_JOBS) { if( mayUserForceRm() == false) { fprintf( stderr, "Remove aborted. condor_rm -forcex has been disabled by the administrator.\n" ); exit( 1 ); } } // Process the args so we do the work. if( All ) { handleAll(); } else { for(i = 0; i < nArgs; i++) { if( match_prefix( args[i], "-constraint" ) ) { i++; addConstraint( args[i] ); } else { procArg(args[i]); } } } // Deal with all the -constraint constraints handleConstraints(); // Finally, do the actual work for all our args which weren't // constraints... if( job_ids ) { CondorError errstack; ClassAd* result_ad = doWorkByList( job_ids, &errstack ); if (had_error) { fprintf( stderr, "%s\n", errstack.getFullText(true).c_str() ); } printNewMessages( result_ad, job_ids ); delete( result_ad ); } // If releasing jobs, and no errors happened, do a // reschedule command now. if ( mode == JA_RELEASE_JOBS && had_error == false ) { Daemon my_schedd(DT_SCHEDD, NULL, NULL); CondorError errstack; if (!my_schedd.sendCommand(RESCHEDULE, Stream::safe_sock, 0, &errstack)) { fprintf( stderr, "%s\n", errstack.getFullText(true).c_str() ); } } return had_error; }