//-------------------------------------------------------------------------------------------------- static void GenerateSystemConfig ( const std::string& stagingDirPath ) //-------------------------------------------------------------------------------------------------- { // Open the bindings file for writing std::string path = stagingDirPath + "/bindings"; if (BuildParams.IsVerbose()) { std::cout << "Writing non-app bindings to file '" << path << "'." << std::endl; } std::ofstream cfgStream(path, std::ofstream::trunc); // For each binding in the System object's list, for (auto bindIter : System.ApiBinds()) { auto& bind = bindIter.second; // If the client is a non-app user, // Write an entry into the bindings file for this binding. if (! bind.IsClientAnApp()) { cfgStream << '<' << bind.ClientUserName() << ">." << bind.ClientInterfaceName() << " -> "; if (bind.IsServerAnApp()) { cfgStream << bind.ServerAppName() << "."; } else { cfgStream << "<" << bind.ServerUserName() << ">."; } cfgStream << bind.ServerInterfaceName() << std::endl; } } }
//-------------------------------------------------------------------------------------------------- static void GenerateSystemConfig ( const std::string& stagingDirPath, ///< Path to the root of the app's staging directory. legato::App& app, ///< The app to generate the configuration for. const legato::BuildParams_t& buildParams ///< Build parameters, such as the "is verbose" flag. ) //-------------------------------------------------------------------------------------------------- { // TODO: Rename this file to something that makes more sense (like "system.cfg", because it // gets installed in the "system" config tree). std::string path = stagingDirPath + "/root.cfg"; if (buildParams.IsVerbose()) { std::cout << "Generating system configuration data for app '" << app.Name() << "' in file '" << path << "'." << std::endl; } std::ofstream cfgStream(path, std::ofstream::trunc); cfgStream << "{" << std::endl; GenerateAppVersionConfig(cfgStream, app); GenerateAppLimitsConfig(cfgStream, app); GenerateGroupsConfig(cfgStream, app); GenerateFileMappingConfig(cfgStream, app); GenerateProcessConfig(cfgStream, app); GenerateIpcBindingConfig(cfgStream, app, buildParams); GenerateConfigTreeAclConfig(cfgStream, app); cfgStream << "}" << std::endl; }
void BaseRunTimeConfig::initializeFromBuffer( const string& cfgStr ) { TRACER_OP_START("BaseRunTimeConfig::initializeFromBuffer"); TRACER(cfgStr, READ, HEAP, "Configuration string"); if (&cfgStr != &this->cfgStr) this->cfgStr = cfgStr; m_warnings.str(""); RunTimeVariableMap newVars; int lineNum = 0; try { getVariables(); istringstream cfgStream(cfgStr); string line; while (getline(cfgStream, line)) { ++lineNum; bal::trim(line); // trim whitespace // skip blank or comment lines if (line.empty() || line.find_first_of("#[") == 0) continue; // otherwise, the line must be in the form "Key=Value" and Key must be in the variables map if (!bal::contains(line, "=")) { m_warnings << "Line " << lineNum << ": line does not define a parameter in the \"Parameter = Value\" format.\n"; continue; } size_t predIdx = line.find_first_of('=') + 1; TRACER_OP_START("get value for key"); TRACER_BI; string key = line.substr(0, predIdx-1); TRACER(key, WRITE, STACK, "Parameter name"); bal::trim(key); if (m_variables.count(key) == 0) { m_warnings << "Line " << lineNum << ": \"" << key << "\" is not a supported parameter.\n"; continue; } RunTimeVariableMap::iterator itr = newVars.find(key); if (itr != newVars.end()) { m_warnings << "Line " << lineNum << ": \"" << key << "\" has already been defined.\n"; continue; } size_t valBegin = line.find_first_not_of("\t ", predIdx); size_t valEnd = valBegin; bool inQuote = false; for (valEnd = valBegin; valEnd < line.size(); ++valEnd) { if (line[valEnd] == '"' && line[valEnd-1] != '\\') inQuote = !inQuote; else if ((line[valEnd] == '#') && !inQuote) break; // stop at unquoted comment token } if (valEnd == valBegin || valBegin == string::npos) { m_warnings << "Line " << lineNum << ": no value set for \"" << key << "\"; did you mean to use an empty string (\"\")?\n"; continue; } string& value = newVars[key]; value = TrimWhitespace(line.substr(valBegin, valEnd-valBegin)); if (value.empty()) { m_warnings << "Line " << lineNum << ": no value set for \"" << key << "\"; did you mean to use an empty string (\"\")?\n"; continue; } value = UnquoteString(value); bal::replace_all(value, "\\\"", "\""); bal::replace_all(value, "true", "1"); bal::replace_all(value, "false", "0"); TRACER(value, WRITE, HEAP, std::string("Value for ")+std::string(key)); TRACER_BO; TRACER_OP_END("get value for key"); } } catch (exception& e) { m_warnings << "Line " << lineNum << ": " << e.what() << "\n"; } // apply the new variable values setVariables(newVars); TRACER_OP_END("BaseRunTimeConfig::initializeFromBuffer"); }