void UDPEchoClient::onReadyRead () { { LockGuard guard (mMutex); if (mState != WAIT) return; // ignoring; timeout. // Check protocol String from; int fromPort; ByteArrayPtr data = mSocket.recvFrom(&from,&fromPort); if (!data) { Log (LogWarning) << LOGID << "Could not read any data tough readyRead() signal" << std::endl; return; // ? } String toParse (data->const_c_array(), data->size()); ArgumentList list; sf::argSplit (toParse, &list); // Format: TOKEN IP-Address Port if (list.size() != 4 || list[0] != "condataReply") { Log (LogInfo) << LOGID << "Invalid protocol in answer " << *data << ", token=" << list.size() << std::endl; return; // invalid protocol } if (list[1] != mToken){ Log (LogInfo) << LOGID << "Token mismatch in answer " << *data << std::endl; return; // invalid token } mState = READY; mAddress = list[2]; mPort = atoi (list[3].c_str()); Log (LogInfo) << LOGID << "Successfully decoded echo answer: " << mAddress << ":" << mPort << " coming from " << from << ":" << fromPort << std::endl; sf::cancelTimer(mTimeoutHandle); } mResultDelegate (NoError); }
void InsertMacro(CMacro* Macro, std::wstring& Args) { tTextData Text; ArgumentList Arguments; splitArguments(Arguments,Args); if ((int)Arguments.size() != Macro->getArgumentCount()) { Logger::printError(Logger::Error,L"%s macro arguments (%d vs %d)", (int)Arguments.size() > Macro->getArgumentCount() ? L"Too many" : L"Not enough", Arguments.size(),Macro->getArgumentCount()); return; } Global.MacroNestingLevel++; if (Global.MacroNestingLevel == ASSEMBLER_MACRO_NESTING_LEVEL) { Logger::printError(Logger::Error,L"Maximum macro nesting level reached"); return; } int MacroCounter = Macro->getIncreaseCounter(); for (int i = 0; i < Macro->getLineCount(); i++) { Text.buffer = Macro->getLine(i,Arguments,MacroCounter); Text.buffer = Global.symbolTable.insertEquations(Text.buffer,Global.FileInfo.FileNum,Global.Section); if (CheckEquLabel(Text.buffer) == false) { Text.buffer = checkLabel(Text.buffer,false); splitLine(Text.buffer,Text.name,Text.params); if (Text.name.size() == 0) continue; bool macro = false; for (size_t i = 0; i < Global.Macros.size(); i++) { if (Text.name.compare(Global.Macros[i]->getName()) == 0) { InsertMacro(Global.Macros[i],Text.params); macro = true; } } if (macro == true) continue; if (Arch->AssembleDirective(Text.name,Text.params) == false) { Arch->AssembleOpcode(Text.name,Text.params); } } } Global.MacroNestingLevel--; }
Variant Invoke(Variant &obj, const ArgumentList &arguments) override { UAssert( arguments.size( ) == THIS_ARG_COUNT, "Invalid method arguments.\nExpected %i args but got %i.", THIS_ARG_COUNT, arguments.size( ) ); invoke<void, ArgTypes...>( obj, arguments ); return { }; }
CDirectiveIncbin::CDirectiveIncbin(ArgumentList& args) { fileName = getFullPathName(args[0].text); if (fileExists(fileName) == false) { Logger::printError(Logger::FatalError,L"File %s not found",fileName); return; } int inputFileSize = fileSize(fileName); if (args.size() >= 2) { // load start address if (ConvertExpression(args[1].text,startAddress) == false) { Logger::printError(Logger::FatalError,L"Invalid start address %s",args[1].text); return; } if (startAddress >= inputFileSize) { Logger::printError(Logger::Error,L"Start address 0x%08X after end of file",startAddress); return; } if (args.size() >= 3) { // load size too if (ConvertExpression(args[2].text,loadSize) == false) { Logger::printError(Logger::FatalError,L"Invalid size %s",args[1].text); return; } if (startAddress+loadSize > inputFileSize) { Logger::printError(Logger::Warning,L"Loading beyond file end, truncating"); loadSize = inputFileSize-startAddress; } } else { loadSize = inputFileSize-startAddress; } } else { startAddress = 0; loadSize = inputFileSize; } g_fileManager->advanceMemory(loadSize); }
bool measured_response_time( const char* name, ArgumentList const& arguments, EvalState &state, Value& result) { result.SetErrorValue(); std::string queue_id; int mode = 0, seconds = 0; // we check to make sure that we are passed at least one argument if (arguments.size() <= 1) { return false; } else { Value arg[3]; if (!(arguments[0]->Evaluate(state, arg[0]) && arg[0].IsStringValue(queue_id))) { return false; } if (!(arguments[1]->Evaluate(state, arg[1]) && arg[1].IsIntegerValue(mode))) { return false; } if (!(arguments[2]->Evaluate(state, arg[2]) && arg[2].IsIntegerValue(seconds))) { return false; } } if (mode) { result.SetRealValue(lb_statistics(queue_id, avg, seconds)); } else { result.SetRealValue(lb_statistics(queue_id, std_dev, seconds)); } return true; }
bool DirectiveData(ArgumentList& List, int flags) { bool ascii = false; if (flags & DIRECTIVE_DATA_ASCII) { ascii = true; flags &= ~DIRECTIVE_DATA_ASCII; } bool hasNonAscii = false; for (size_t i = 0; i < List.size(); i++) { if (List[i].isString) { for (size_t k = 0; k < List[i].text.size(); k++) { if (List[i].text[k] >= 0x80) hasNonAscii = true; } } } if (hasNonAscii) Logger::printError(Logger::Warning,L"Non-ASCII character in data directive. Use .string instead"); CDirectiveData* Data = new CDirectiveData(List,flags,ascii); AddAssemblerCommand(Data); return true; }
void Action::clearOutputAgumentValues() { ArgumentList *outArgList = getOutputArgumentList(); int nArgs = outArgList->size(); for (int n = 0; n < nArgs; n++) { Argument *arg = outArgList->getArgument(n); arg->setValue(""); } }
double Calculator::call(Lexer& lexer, string name) { SymEntry* sym = symbols.Get(name); if(!sym) { throw Error::SyntaxError("undefined function "+name); } ArgumentList args = arguments(lexer); switch(sym->type) { case SymEntry::SYS_FUNC: { SymSysFunc* sFunc = static_cast<SymSysFunc*>(sym); if(args.size() != 1) throw Error::SyntaxError("incorrect number of arguments"); return sFunc->func(args[0]); } case SymEntry::USR_FUNC: { SymUsrFunc* uFunc = static_cast<SymUsrFunc*>(sym); if(args.size() != uFunc->params.size()) throw Error::SyntaxError("incorrect number of arguments"); map<string,double> argMap; for(unsigned int i = 0; i < uFunc->params.size(); i++) { argMap[uFunc->params[i]] = args[i]; } for(TokenList::const_iterator i = uFunc->func.begin(); i != uFunc->func.end(); i++) { Token tok = *i; if(tok.Type == Token::NAME && argMap.count(tok.StringValue) > 0) { Token val(Token::NUMBER, argMap[tok.StringValue]); lexer.push(val); } else lexer.push(*i); } return expr(lexer); } default: throw Error::SyntaxError("not a function: "+name); } }
void CMacro::loadArguments(ArgumentList& argumentList) { name = argumentList[0].text; for (size_t i = 1; i < argumentList.size(); i++) { arguments.push_back(argumentList[i].text); } }
DirectiveObjImport::DirectiveObjImport(ArgumentList& args) { if (rel.init(args[0].text)) { rel.exportSymbols(); if (args.size() == 2) rel.writeCtor(args[1].text); } }
CDirectiveData::CDirectiveData(ArgumentList& Args, int SizePerUnit, bool asc) { TotalAmount = Args.size(); StrAmount = 0; ExpAmount = 0; for (int i = 0; i < TotalAmount; i++) { if (Args[i].isString == true) { StrAmount++; } else { ExpAmount++; } } Entries = (tDirectiveDataEntry*) malloc(TotalAmount*sizeof(tDirectiveDataEntry)); ExpData = new CExpressionCommandList[ExpAmount]; switch (SizePerUnit) { case 1: case 2: case 4: UnitSize = SizePerUnit; ascii = asc; break; default: Logger::printError(Logger::Error,L"Invalid data unit size %d",SizePerUnit); return; } int ExpNum = 0; SpaceNeeded = 0; for (int i = 0; i < TotalAmount; i++) { if (Args[i].isString == true) { std::string tt = convertWStringToUtf8(Args[i].text); char* t = (char*) tt.c_str(); int len = strlen(t); Entries[i].String = true; Entries[i].num = StrData.GetCount(); StrData.AddEntry((unsigned char*)t,len); SpaceNeeded += len*UnitSize; } else { Entries[i].String = false; Entries[i].num = ExpNum; if (initExpression(ExpData[ExpNum++],Args[i].text) == false) return; SpaceNeeded += UnitSize; } } g_fileManager->advanceMemory(SpaceNeeded); }
static bool triple( const char *, const ArgumentList &arguments, EvalState &state, Value &result) { Value arg; // takes exactly one argument if( arguments.size() > 1 ) { result.SetErrorValue( ); return true; } if( !arguments[0]->Evaluate( state, arg ) ) { result.SetErrorValue( ); return false; } switch( arg.GetType( ) ) { case Value::UNDEFINED_VALUE: result.SetUndefinedValue( ); return true; case Value::ERROR_VALUE: case Value::CLASSAD_VALUE: case Value::LIST_VALUE: case Value::SLIST_VALUE: case Value::STRING_VALUE: case Value::ABSOLUTE_TIME_VALUE: case Value::RELATIVE_TIME_VALUE: case Value::BOOLEAN_VALUE: result.SetErrorValue( ); return true; case Value::INTEGER_VALUE: int int_value; arg.IsIntegerValue(int_value); result.SetIntegerValue(3 * int_value); return true; case Value::REAL_VALUE: { double real_value; arg.IsRealValue( real_value ); result.SetRealValue(3 * real_value); return true; } default: return false; } return false; }
Argument *Action::getArgument(const std::string &name) { ArgumentList *argList = getArgumentList(); int nArgs = argList->size(); for (int n = 0; n < nArgs; n++) { Argument *arg = argList->getArgument(n); const char *argName = arg->getName(); if (argName == NULL) continue; string argNameStr = argName; if (argNameStr.compare(name) == 0) return arg; } return NULL; }
bool DirectiveOpen(ArgumentList& list, int flags) { if (list.size() == 2) { // open CDirectiveFile* command = new CDirectiveFile(CDirectiveFile::Open,list); AddAssemblerCommand(command); } else { // copy CDirectiveFile* command = new CDirectiveFile(CDirectiveFile::Copy,list); AddAssemblerCommand(command); } return true; }
bool listAttrRegEx(const char *name, const ArgumentList &arguments, EvalState &state, Value &result) { bool eval_successful = false; result.SetErrorValue(); // We check to make sure that we passed exactly two arguments... if (arguments.size() == 2) { Value arg1; std::string pattern; // ...the first argument should evaluate to a string value... if (arguments[0] -> Evaluate(state, arg1) && arg1.IsStringValue(pattern)) { // ...the second argument should be an attribute reference if (arguments[1] -> GetKind() == ExprTree::ATTRREF_NODE) { // Now we compile the pattern... regex_t re; if( !regcomp( &re, pattern.c_str(), REG_EXTENDED|REG_NOSUB ) ) { std::vector<std::string> attrs; deep_find_attribute_if(&attrs, arguments[1], match_pattern(&re)); // if there is no matching attribute then the undefined // value should be returned as result. Otherwise we have // to create an exprlist containing the quoted names of // the attributes matching the regex... eval_successful = !attrs.empty(); if (!eval_successful) result.SetUndefinedValue(); else { std::vector<ExprTree*> attrsList; for(std::vector<std::string>::const_iterator a=attrs.begin(); a != attrs.end(); a++) { Value value; value.SetStringValue(*a); attrsList.push_back( Literal::MakeLiteral(value) ); } ExprList* e = ExprList::MakeExprList(attrsList); e->SetParentScope(state.curAd); result.SetListValue(e); } // dispose memory created by regcomp() regfree( &re ); } } } } return eval_successful; }
BOOST_FOREACH(ArgumentList argList, argLists) { proxyFile.oss << " % " << name << "("; unsigned int i = 0; BOOST_FOREACH(const Argument& arg, argList) { if(i != argList.size()-1) proxyFile.oss << arg.type << " " << arg.name << ", "; else proxyFile.oss << arg.type << " " << arg.name; i++; } proxyFile.oss << ")" << endl; }
bool CDirectiveArea::LoadStart(ArgumentList &Args) { if (initExpression(SizeExpression,Args[0].text) == false) return false; Start = true; if (Args.size() == 2) { if (initExpression(FillExpression,Args[1].text) == false) return false; } return true; }
void PrintDeviceInfo(Device *dev, int indent) { string indentStr; GetIndentString(indent, indentStr); const char *devName = dev->getFriendlyName(); cout << indentStr << devName << endl; int i, n, j; ServiceList *serviceList = dev->getServiceList(); int serviceCnt = serviceList->size(); for (n=0; n<serviceCnt; n++) { Service *service = serviceList->getService(n); cout << indentStr << " service[" << n << "] = "<< service->getServiceType() << endl; ActionList *actionList = service->getActionList(); int actionCnt = actionList->size(); for (i=0; i<actionCnt; i++) { Action *action = actionList->getAction(i); cout << indentStr << " action[" << i << "] = "<< action->getName() << endl; ArgumentList *argList = action->getArgumentList(); int argCnt = argList->size(); for (j=0; j<argCnt; j++) { Argument *arg = argList->getArgument(j); cout << indentStr << " arg[" << j << "] = " << arg->getName() << "(" << arg->getDirection() << ")"; StateVariable *stateVar = arg->getRelatedStateVariable(); if (stateVar != NULL) cout << " - " << stateVar->getName(); cout << endl; } } ServiceStateTable *stateTable = service->getServiceStateTable(); int varCnt = stateTable->size(); for (i=0; i<varCnt; i++) { StateVariable *stateVar = stateTable->getStateVariable(i); cout << indentStr << " stateVar[" << i << "] = " << stateVar->getName() << endl; AllowedValueList *valueList = stateVar->getAllowedValueList(); int valueListCnt = valueList->size(); if (0 < valueListCnt) { for (j=0; j<valueListCnt; j++) cout << indentStr << " AllowedValueList[" << j << "] = " << valueList->getAllowedValue(j) << endl; } AllowedValueRange *valueRange = stateVar->getAllowedValueRange(); if (valueRange != NULL) { cout << indentStr << " AllowedRange[minimum] = " << valueRange->getMinimum() << endl; cout << indentStr << " AllowedRange[maximum] = " << valueRange->getMaximum() << endl; cout << indentStr << " AllowedRange[step] = " << valueRange->getStep() << endl; } } } }
bool DirectiveString(ArgumentList& List, int flags) { ArgumentList NewList; if (Global.Table.isLoaded() == false) { Logger::printError(Logger::Error,L"No table opened"); return false; } for (size_t i = 0; i < List.size(); i++) { if (List[i].isString) { ByteArray data = Global.Table.encodeString(List[i].text,false); if (data.size() == 0 && List[i].text.size() != 0) { Logger::printError(Logger::Error,L"Failed to encode string"); return false; } for (int i = 0; i < data.size(); i++) { wchar_t str[32]; swprintf(str,32,L"0x%02X",data[i]); NewList.add(str,false); } } else { NewList.add(List[i].text,false); } } if ((flags & DIRECTIVE_STR_NOTERMINATION) == 0) { ByteArray data = Global.Table.encodeTermination(); for (int i = 0; i < data.size(); i++) { wchar_t str[32]; swprintf(str,32,L"0x%02X",data[i]); NewList.add(str,false); } } CDirectiveData* Data = new CDirectiveData(NewList,1,false); AddAssemblerCommand(Data); return true; }
CDirectiveAlign::CDirectiveAlign(ArgumentList& args) { if (args.size() >= 1) { if (ConvertExpression(args[0].text,alignment) == false) { Logger::printError(Logger::FatalError,L"Invalid alignment %s",args[0].text); } if (isPowerOfTwo(alignment) == false) { Logger::printError(Logger::Error,L"Invalid alignment %d",alignment); } } else { alignment = Arch->GetWordSize(); } int num = computePadding(); }
bool DirectiveInclude(ArgumentList& List, int flags) { std::wstring fileName = getFullPathName(List[0].text); TextFile::Encoding encoding = TextFile::GUESS; if (List.size() == 2) encoding = getEncodingFromString(List[1].text); int FileNum = Global.FileInfo.FileNum; int LineNum = Global.FileInfo.LineNumber; if (fileExists(fileName) == false) { Logger::printError(Logger::Error,L"Included file \"%s\" does not exist",fileName.c_str()); return false; } LoadAssemblyFile(fileName,encoding); Global.FileInfo.FileNum = FileNum; Global.FileInfo.LineNumber = LineNum; return true; }
//============================================================================== int main (int argc, char **argv) { ConsoleLogger logger; Logger::setCurrentLogger (&logger); ConsoleUnitTestRunner runner; ArgumentList args (argc, argv); if (args.size() == 0) { runner.runAllTests(); } else { if (args.containsOption ("--help|-h")) { std::cout << argv[0] << " [--help|-h] [--category category] [--list-categories]" << std::endl; return 0; } if (args.containsOption ("--list-categories")) { for (auto& category : UnitTest::getAllCategories()) std::cout << category << std::endl; return 0; } if (args.containsOption ("--category")) runner.runTestsInCategory (args.getValueForOption ("--category")); } Logger::setCurrentLogger (nullptr); for (int i = 0; i < runner.getNumResults(); ++i) if (runner.getResult(i)->failures > 0) return 1; return 0; }
bool DirectiveLoadTable(ArgumentList& List, int flags) { std::wstring fileName = getFullPathName(List[0].text); if (fileExists(fileName) == false) { Logger::printError(Logger::Error,L"Table file \"%s\" does not exist",fileName.c_str()); return false; } TextFile::Encoding encoding = TextFile::GUESS; if (List.size() == 2) encoding = getEncodingFromString(List[1].text); if (Global.Table.load(fileName,encoding) == false) { Logger::printError(Logger::Error,L"Invalid table file \"%s\"",fileName.c_str()); return false; } return true; }
void processMacro(istream* input, Define define) { Token tok = get_token(input, true, false); ArgumentList args; if(tok.token == TOK_LPAREN) { args = arguments(input); } if (args.size() != define.params.size()) { cerr << "Macro argument mismatch, expected " << define.params.size() << ", got " << args.size() << endl; return; } map<string,TokenList> argLookup; for(int i = 0; i < define.params.size(); i++) { if(argLookup.count(define.params[i]) > 0) cerr << "Warning: duplicate parameter name in macro" << endl; else argLookup[define.params[i]] = args[i]; } for(TokenList::const_iterator i = define.tokens.begin(); i != define.tokens.end(); i++) { Token paramTok = *i; if(paramTok.token == TOK_ID && argLookup.count(paramTok.value) > 0) { TokenList argToks = argLookup[paramTok.value]; for(TokenList::const_iterator j = argToks.begin(); j != argToks.end(); j++) { cout << (*j).value; } } else cout << paramTok.value; } if(tok.token != TOK_LPAREN) cout << tok.value; }
/* ************************************************************************* */ string Method::wrapper_call(FileWriter& wrapperFile, Str cppClassName, Str matlabUniqueName, const ArgumentList& args) const { // check arguments // extra argument obj -> nargin-1 is passed ! // example: checkArguments("equals",nargout,nargin-1,2); wrapperFile.oss << " checkArguments(\"" << matlabName() << "\",nargout,nargin-1," << args.size() << ");\n"; // get class pointer // example: shared_ptr<Test> = unwrap_shared_ptr< Test >(in[0], "Test"); wrapperFile.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName << ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl; // unwrap arguments, see Argument.cpp, we start at 1 as first is obj args.matlab_unwrap(wrapperFile, 1); // call method and wrap result // example: out[0]=wrap<bool>(obj->return_field(t)); string expanded = "obj->" + name_; if (templateArgValue_) expanded += ("<" + templateArgValue_->qualifiedName("::") + ">"); return expanded; }
double Parser::call(istream* input, string name) { if (functions.count(name) < 1) throw Error::SyntaxError("undefined function "+name); ArgumentList args = arguments(input); Function func = functions[name]; if(func.params.size() != args.size()) throw Error::SyntaxError("incorrect number of arguments"); if(func.type == FUNC_BUILTIN) { return func.ptr(args[0]); } map<string,double> argMap; for(unsigned int i = 0; i < func.params.size(); i++) { argMap[func.params[i]] = args[i]; } for(TokenList::const_iterator i = func.tokens.begin(); i != func.tokens.end(); i++) { Token tok = *i; if(tok.curr_tok == Lexer::NAME && argMap.count(tok.string_value) > 0) { Token val; val.curr_tok = Lexer::NUMBER; val.number_value = argMap[tok.string_value]; Lexer::token_queue.push(val); } else Lexer::token_queue.push(*i); } return expr(input, true); }
/**************************************************************************** * * Query an xrootd server and translate filenames to locations * To use: * files_to_sites("xrootd.example.com", ["file1", "file2", "file3"]) * * This function will aggressively cache the results (matchmaking will call * it many times over a short period); it is also guaranteed to return within * 50ms. * * Returns the list of xrootd endpoints which claim to have the file. Any not * responding or not in the cache after 50ms will be left off the list. It is * not possible to distinguish, in this function, the difference between * timeouts, failures, and empty responses. * ****************************************************************************/ static bool files_to_sites( const char *, // name const ArgumentList &arguments, EvalState & state, Value &result) { Value xrootd_host_arg, filenames_arg; // We check to make sure that we are passed exactly one argument, // then we have to evaluate that argument. if (arguments.size() != 2) { result.SetErrorValue(); CondorErrMsg = "Invalid number of arguments passed to files_to_sites; 2 required."; return false; } std::string xrootd_host; if (!arguments[0]->Evaluate(state, xrootd_host_arg) || (!xrootd_host_arg.IsStringValue(xrootd_host))) { result.SetErrorValue(); CondorErrMsg = "Could not evaluate the first argument (Xrootd hostname) of files_to_sites to a string."; return false; } if (!arguments[1]->Evaluate(state, filenames_arg)) { result.SetErrorValue(); CondorErrMsg = "Could not evaluate the second argument (list of filenames) of files_to_sites."; return false; } std::vector<std::string> filenames; std::string single_filename; if (filenames_arg.IsStringValue(single_filename)) { filenames.push_back(single_filename); } else if (!convert_to_vector_string(state, filenames_arg, filenames)) { result.SetErrorValue(); CondorErrMsg = "Could not evaluate the second argument (list of filenames) of files_to_sites to a list of strings."; return false; } std::vector<std::string> files_to_query; ResponseCache &cache = ResponseCache::getInstance(); classad_shared_ptr<ExprList> result_list = cache.query(filenames, files_to_query); if (files_to_query.size() > 0) { FileMappingClient &client = FileMappingClient::getClient(xrootd_host); if (!client.is_connected()) { result.SetErrorValue(); CondorErrMsg = "Could not connect to specified xrootd host: " + xrootd_host; return false; } std::set<std::string> hosts; if (!client.map(filenames, hosts)) { result.SetErrorValue(); CondorErrMsg = "Error while mapping the files to hosts."; return false; } if (hosts.size() > 0) { classad_shared_ptr<ExprList> new_list = cache.addToList(result_list, hosts); result_list = new_list; } } result.SetListValue(result_list.get()); return true; }
bool doMatch(const char *name, const ArgumentList &arguments, EvalState &state, Value &result) { bool eval_successful = false; result.SetErrorValue(); // We check to make sure that we passed exactly two arguments... if (arguments.size() == 2) { Value arg1; const ExprList *adList; // ...the first argument should evaluate to a list... if (arguments[0] -> Evaluate(state, arg1) && arg1.IsListValue(adList)) { // ...the second argument should be either an expression // operand node or a function call node... if (arguments[1] -> GetKind() == ExprTree::OP_NODE || arguments[1] -> GetKind() == ExprTree::FN_CALL_NODE) { // Now we prepare the match context used while looking for // any matching ad in the adList.In order to evaluate correctly // any attribute reference involved in the second argument we // should use the same classad containing the anyMatch statement // while matching. Moreover we should make a copy of the requirements // expression passed as second argument and set the parent scope by // inserting it into the just copied classad. Finally, we set the left // context which will be constant for any further match. MatchClassAd match; ClassAd* al = static_cast<classad::ClassAd*>(arguments[1]->GetParentScope()->Copy()); al->Insert("requirements", arguments[1]->Copy()); match.ReplaceLeftAd(al); std::vector<ExprTree*> ads, matching; adList->GetComponents(ads); for(std::vector<ExprTree*>::const_iterator it = ads.begin(); it != ads.end(); it++) { // Each expression in the list should be a classad... if (!utils::is_classad(*it)) { result.SetErrorValue(); eval_successful = false; break; } ClassAd* ar = static_cast<ClassAd*>((*it)->Copy()); match.ReplaceRightAd(ar); // If requirements does not evaluate to a boolean there is // something seriously wrong and exit... if (!match.EvaluateAttrBool("rightMatchesLeft", eval_successful)) { result.SetErrorValue(); eval_successful = false; break; } // ...otherwise we have to set the result and exit depending // on which function was called. if ( (!strcasecmp(name, "anyMatch") && eval_successful) || (!strcasecmp(name, "allMatch") && !eval_successful)) { result.SetBooleanValue(eval_successful); break; } if (!strcasecmp(name, "whichMatch") && eval_successful) { matching.push_back(dynamic_cast<ClassAd*>(*it)); } } // if the whichMatch was called we have to set the result to // the classad which matched... if (!strcasecmp(name, "whichMatch")) { eval_successful = !matching.empty(); // if there is no matching ad then the evaluation was successful // and we have to set the result to undefined... // ...otherwise we have to set the result to the matching ad(s) if (!eval_successful) result.SetUndefinedValue(); else result.SetListValue(ExprList::MakeExprList(matching)); } } } } return eval_successful; }
void Process::setupChild(const std::string& _exe, const ArgumentList& _args, const Environment& _env, const std::string& _workdir) { // restore signal handler(s) ::signal(SIGPIPE, SIG_DFL); // setup environment int k = 0; std::vector<char *> env(_env.size() + 1); for (Environment::const_iterator i = _env.cbegin(), e = _env.cend(); i != e; ++i) { char *buf = new char[i->first.size() + i->second.size() + 2]; ::memcpy(buf, i->first.c_str(), i->first.size()); buf[i->first.size()] = '='; ::memcpy(buf + i->first.size() + 1, i->second.c_str(), i->second.size() + 1); //::fprintf(stderr, "proc[%d]: setting env[%d]: %s\n", getpid(), k, buf); //::fflush(stderr); env[k++] = buf; } env[_env.size()] = 0; // setup args std::vector<char *> args(_args.size() + 2); args[0] = const_cast<char *>(_exe.c_str()); //::fprintf(stderr, "args[%d] = %s\n", 0, args[0]); for (int i = 0, e = _args.size(); i != e; ++i) { args[i + 1] = const_cast<char *>(_args[i].c_str()); //::fprintf(stderr, "args[%d] = %s\n", i + 1, args[i + 1]); } args[args.size() - 1] = 0; // chdir if (!_workdir.empty()) { ::chdir(_workdir.c_str()); } // setup I/O EINTR_LOOP(::close(STDIN_FILENO)); EINTR_LOOP(::close(STDOUT_FILENO)); EINTR_LOOP(::close(STDERR_FILENO)); EINTR_LOOP(::dup2(input_.remote(), STDIN_FILENO)); EINTR_LOOP(::dup2(output_.remote(), STDOUT_FILENO)); EINTR_LOOP(::dup2(error_.remote(), STDERR_FILENO)); #if 0 // this is basically working but a very bad idea for high performance (XXX better get O_CLOEXEC working) for (int i = 3; i < 1024; ++i) ::close(i); #endif // input_.close(); // output_.close(); // error_.close(); // finally execute ::execve(args[0], &args[0], &env[0]); // OOPS ::fprintf(stderr, "proc[%d]: execve(%s) error: %s\n", getpid(), args[0], strerror(errno)); ::fflush(stderr); ::_exit(1); }