void printOutput( ClassAd* reply, DCStartd* startd ) { char* claimid = NULL; char* last_state = NULL; if( cmd == CA_REQUEST_CLAIM ) { reply->LookupString( ATTR_CLAIM_ID, &claimid ); } if( CA_PATH ) { fPrintAd( CA_PATH, *reply ); fclose( CA_PATH ); printf( "Successfully sent %s to startd at %s\n", getCommandString(cmd), startd->addr() ); printf( "Result ClassAd written to %s\n", classad_path ); if( cmd == CA_REQUEST_CLAIM ) { printf( "ID of new claim is: \"%s\"\n", claimid ); free( claimid ); } return; } if( cmd == CA_REQUEST_CLAIM ) { fprintf( stderr, "Successfully sent %s to startd at %s\n", getCommandString(cmd), startd->addr() ); fprintf( stderr, "WARNING: You did not specify " "-classad, printing to STDOUT\n" ); fPrintAd( stdout, *reply ); fprintf( stderr, "ID of new claim is: \"%s\"\n", claimid ); free( claimid ); return; } printf( "Successfully sent %s to startd at %s\n", getCommandString(cmd), startd->addr() ); switch( cmd ) { case CA_REQUEST_CLAIM: EXCEPT( "Already handled CA_REQUEST_CLAIM!" ); break; case CA_RELEASE_CLAIM: if( reply->LookupString(ATTR_LAST_CLAIM_STATE, &last_state) ) { printf( "State of claim when it was released: \"%s\"\n", last_state ); free( last_state ); } else { fprintf( stderr, "Warning: " "reply ClassAd did not contain attribute \"%s\"\n", ATTR_LAST_CLAIM_STATE ); } break; default: // nothing else yet to print break; } }
int SimScheddQ::send_SpoolFileIfNeeded(ClassAd& ad) { if (fp) { fprintf(fp, "::send_SpoolFileIfNeeded\n"); fPrintAd(fp, ad); } return 0; }
bool JobInfoCommunicator::writeOutputAdFile( ClassAd* ad ) { if( ! job_output_ad_file ) { return false; } FILE* fp; if( job_output_ad_is_stdout ) { dprintf( D_ALWAYS, "Will write job output ClassAd to STDOUT\n" ); fp = stdout; } else { fp = safe_fopen_wrapper_follow( job_output_ad_file, "a" ); if( ! fp ) { dprintf( D_ALWAYS, "Failed to open job output ClassAd " "\"%s\": %s (errno %d)\n", job_output_ad_file, strerror(errno), errno ); return false; } else { dprintf( D_ALWAYS, "Writing job output ClassAd to \"%s\"\n", job_output_ad_file ); } } // append a delimiter? fPrintAd( fp, *ad ); if( job_output_ad_is_stdout ) { fflush( fp ); } else { fclose( fp ); } return true; }
int main(int argc, char *argv[]) { myDistro->Init( argc, argv ); if (argc != 2) { fprintf(stderr, "usage: %s collection-file\n", argv[0]); } // rename the collection file to some temporary file, so we don't // mess up the actual collection file char tmpfile[L_tmpnam]; tmpnam(tmpfile); MyString cmd; cmd.formatstr( "cp %s %s", argv[1], tmpfile); system(cmd.Value()); ClassAdCollection c(tmpfile); c.StartIterateAllCollections(); ClassAd *ad = NULL; while (c.IterateAllClassAds(ad)) { fPrintAd(stdout, *ad); printf("\n"); } unlink(tmpfile); return 0; }
int sendCmd( const char* job_id, const char* name, const char* pool ) { DCStartd d( name, pool ); if( ! d.locate() ) { fprintf( stderr, "Can't locate startd: %s\n", d.error() ); return 1; } ClassAd reply; if( ! d.locateStarter(job_id, &reply) ) { fprintf( stderr, "locateStarter() failed: %s\n", d.error() ); fprintf( stderr, "reply ad:\n" ); fPrintAd( stderr, reply ); return 1; } printf( "locateStarter() worked!\n" ); printf( "reply ad:\n" ); fPrintAd( stdout, reply ); return 0; }
// print a single job ad // static void printJob(ClassAd & ad) { if (longformat) { if (use_xml) { fPrintAdAsXML(stdout, ad); } else { fPrintAd(stdout, ad); } printf("\n"); } else { if (customFormat) { mask.display(stdout, &ad); } else { displayJobShort(&ad); } } }
void Defrag::saveState() { ClassAd ad; ad.Assign(ATTR_LAST_POLL,(int)m_last_poll); std::string new_state_file; formatstr(new_state_file,"%s.new",m_state_file.c_str()); FILE *fp; if( !(fp = safe_fopen_wrapper_follow(new_state_file.c_str(), "w")) ) { EXCEPT("failed to save state to %s",new_state_file.c_str()); } else { fPrintAd(fp, ad); fclose( fp ); if( rotate_file(new_state_file.c_str(),m_state_file.c_str())!=0 ) { EXCEPT("failed to save state to %s",m_state_file.c_str()); } } }
int sendCmd( const char* starter_addr ) { DCStarter d( starter_addr ); ClassAd req; ClassAd reply; ReliSock rsock; if( ! d.reconnect(&req, &reply, &rsock) ) { fprintf( stderr, "command failed: (%s) %s\n", getCAResultString(d.errorCode()), d.error() ); } printf( "reply ad:\n" ); fPrintAd( stdout, reply ); return 0; }
// Read the history from a single file and print it out. static void readHistoryFromFileOld(const char *JobHistoryFileName, const char* constraint, ExprTree *constraintExpr) { int EndFlag = 0; int ErrorFlag = 0; int EmptyFlag = 0; ClassAd *ad = NULL; long offset = 0; bool BOF = false; // Beginning Of File MyString buf; int flags = 0; if( !backwards ) { // Currently, the file position manipulations used in -backwards // do not work with files > 2GB on platforms with 32-bit file // offsets. flags = O_LARGEFILE; } int LogFd = safe_open_wrapper_follow(JobHistoryFileName,flags,0); if (LogFd < 0) { fprintf(stderr,"Error opening history file %s: %s\n", JobHistoryFileName,strerror(errno)); #ifdef EFBIG if( (errno == EFBIG) && backwards ) { fprintf(stderr,"The -backwards option does not support files this large.\n"); } #endif exit(1); } FILE *LogFile = fdopen(LogFd,"r"); if (!LogFile) { fprintf(stderr,"Error opening history file %s: %s\n", JobHistoryFileName,strerror(errno)); exit(1); } // In case of rotated history files, check if we have already reached the number of // matches specified by the user before reading the next file if (specifiedMatch != 0) { if (matchCount == specifiedMatch) { // Already found n number of matches, cleanup fclose(LogFile); return; } } if (backwards) { offset = findLastDelimiter(LogFile, JobHistoryFileName); } if(longformat && use_xml) { std::string out; AddClassAdXMLFileHeader(out); printf("%s\n", out.c_str()); } while(!EndFlag) { if (backwards) { // Read history file backwards if (BOF) { // If reached beginning of file break; } offset = findPrevDelimiter(LogFile, JobHistoryFileName, offset); if (offset == -1) { // Unable to match constraint break; } else if (offset != 0) { fseek(LogFile, offset, SEEK_SET); buf.readLine(LogFile); // Read one line to skip delimiter and adjust to actual offset of ad } else { // Offset set to 0 BOF = true; fseek(LogFile, offset, SEEK_SET); } } if( !( ad=new ClassAd(LogFile,"***", EndFlag, ErrorFlag, EmptyFlag) ) ){ fprintf( stderr, "Error: Out of memory\n" ); exit( 1 ); } if( ErrorFlag ) { printf( "\t*** Warning: Bad history file; skipping malformed ad(s)\n" ); ErrorFlag=0; if(ad) { delete ad; ad = NULL; } continue; } if( EmptyFlag ) { EmptyFlag=0; if(ad) { delete ad; ad = NULL; } continue; } if (!constraint || constraint[0]=='\0' || EvalBool(ad, constraintExpr)) { if (longformat) { if( use_xml ) { fPrintAdAsXML(stdout, *ad); } else { fPrintAd(stdout, *ad); } printf("\n"); } else { if (customFormat) { mask.display(stdout, ad); } else { displayJobShort(ad); } } matchCount++; // if control reached here, match has occured if (specifiedMatch != 0) { // User specified a match number if (matchCount == specifiedMatch) { // Found n number of matches, cleanup if (ad) { delete ad; ad = NULL; } fclose(LogFile); return; } } } if(ad) { delete ad; ad = NULL; } } if(longformat && use_xml) { std::string out; AddClassAdXMLFileFooter(out); printf("%s\n", out.c_str()); } fclose(LogFile); return; }
void printVerbose (ClassAd *ad) { fPrintAd (stdout, *ad); fputc ('\n', stdout); }
// Read the history from a single file and print it out. static void readHistoryFromFile(char *JobHistoryFileName, char* constraint, ExprTree *constraintExpr) { int EndFlag = 0; int ErrorFlag = 0; int EmptyFlag = 0; AttrList *ad = NULL; long offset = 0; bool BOF = false; // Beginning Of File MyString buf; FILE* LogFile=safe_fopen_wrapper(JobHistoryFileName,"r"); if (!LogFile) { fprintf(stderr,"History file (%s) not found or empty.\n", JobHistoryFileName); exit(1); } // In case of rotated history files, check if we have already reached the number of // matches specified by the user before reading the next file if (specifiedMatch != 0) { if (matchCount == specifiedMatch) { // Already found n number of matches, cleanup fclose(LogFile); return; } } if (backwards) { offset = findLastDelimiter(LogFile, JobHistoryFileName); } while(!EndFlag) { if (backwards) { // Read history file backwards if (BOF) { // If reached beginning of file break; } offset = findPrevDelimiter(LogFile, JobHistoryFileName, offset); if (offset == -1) { // Unable to match constraint break; } else if (offset != 0) { fseek(LogFile, offset, SEEK_SET); buf.readLine(LogFile); // Read one line to skip delimiter and adjust to actual offset of ad } else { // Offset set to 0 BOF = true; fseek(LogFile, offset, SEEK_SET); } } if( !( ad=new AttrList(LogFile,"***", EndFlag, ErrorFlag, EmptyFlag) ) ){ fprintf( stderr, "Error: Out of memory\n" ); exit( 1 ); } if( ErrorFlag ) { printf( "\t*** Warning: Bad history file; skipping malformed ad(s)\n" ); ErrorFlag=0; if(ad) { delete ad; ad = NULL; } continue; } if( EmptyFlag ) { EmptyFlag=0; if(ad) { delete ad; ad = NULL; } continue; } if (!constraint || EvalBool(ad, constraintExpr)) { if (longformat) { fPrintAd(stdout, *ad); printf("\n"); } else { if (customFormat) { mask.display(stdout, ad); } else { displayJobShort(ad); } } matchCount++; // if control reached here, match has occured if (specifiedMatch != 0) { // User specified a match number if (matchCount == specifiedMatch) { // Found n number of matches, cleanup if (ad) { delete ad; ad = NULL; } fclose(LogFile); return; } } } if(ad) { delete ad; ad = NULL; } } fclose(LogFile); return; }