//-------------------------------------------------------------------------------------------------- static void ResetApp ( void ) { le_cfg_ConnectService(); le_cfgAdmin_ConnectService(); // Get a write iterator to the application node. le_cfg_IteratorRef_t cfgIter = le_cfg_CreateWriteTxn("/apps"); le_cfg_GoToNode(cfgIter, AppName); // Check if this is a temporary configuration that was previously created by this or a similar // tool. if (le_cfg_IsEmpty(cfgIter, CFG_DEBUG_TOOL)) { fprintf(stderr, "This application already has its original configuration.\n"); exit(EXIT_FAILURE); } // Blow away what's in there now. le_cfg_GoToNode(cfgIter, "/apps"); le_cfg_DeleteNode(cfgIter, AppName); le_cfg_CommitTxn(cfgIter); // NOTE: Currently there is a bug in the config DB where deletions and imports cannot be done in // the same transaction so we must do it in two transactions. cfgInstall_Add(AppName); }
//-------------------------------------------------------------------------------------------------- static le_result_t LoadRatList ( const char *ratPath, uint32_t *ratMaskPtr ) { uint32_t idx=0; LE_DEBUG("Load Rat Preference <%s>",ratPath); le_cfg_IteratorRef_t ratCfg = le_cfg_CreateReadTxn(ratPath); *ratMaskPtr = 0; do { // Get the node name. char ratNodeName[LIMIT_MAX_PATH_BYTES] = {0}; char ratNodeValue[LIMIT_MAX_PATH_BYTES] = {0}; sprintf(ratNodeName,PATTERN_RAT"%d",idx); // This is the exist state for the loop if (le_cfg_IsEmpty(ratCfg, ratNodeName)) { LE_DEBUG("'%s' does not exist. stop reading configuration", ratNodeName); break; } if ( le_cfg_GetString(ratCfg,ratNodeName,ratNodeValue,sizeof(ratNodeValue), "") != LE_OK ) { LE_WARN("Node value string for '%s' too large.",ratNodeName); le_cfg_CancelTxn(ratCfg); return LE_NOT_POSSIBLE; } if ( strncmp(ratNodeName,"",sizeof(ratNodeName)) == 0 ) { LE_WARN("No node value set for '%s'",ratNodeName); le_cfg_CancelTxn(ratCfg); return LE_NOT_POSSIBLE; } *ratMaskPtr |= ConvertRatValue(ratNodeValue); ++idx; } while (true); le_cfg_CancelTxn(ratCfg); return LE_OK; }
static void ExistAndEmptyTest() { static char pathBuffer[STR_SIZE] = { 0 }; snprintf(pathBuffer, STR_SIZE, "/%s/existAndEmptyTest/", TestRootDir); { le_cfg_IteratorRef_t iterRef = le_cfg_CreateWriteTxn(pathBuffer); le_cfg_SetEmpty(iterRef, ""); LE_TEST(le_cfg_IsEmpty(iterRef, "") == true); LE_TEST(le_cfg_NodeExists(iterRef, "valueA") == false); LE_TEST(le_cfg_NodeExists(iterRef, "valueB") == false); LE_TEST(le_cfg_NodeExists(iterRef, "valueC") == false); LE_TEST(le_cfg_NodeExists(iterRef, "valueD") == false); LE_TEST(le_cfg_IsEmpty(iterRef, "valueA") == true); LE_TEST(le_cfg_IsEmpty(iterRef, "valueB") == true); LE_TEST(le_cfg_IsEmpty(iterRef, "valueC") == true); LE_TEST(le_cfg_IsEmpty(iterRef, "valueD") == true); le_cfg_SetString(iterRef, "valueA", "aNewValue"); le_cfg_SetInt(iterRef, "valueB", 10); le_cfg_SetBool(iterRef, "valueC", true); le_cfg_SetFloat(iterRef, "valueD", 10.24); LE_TEST(le_cfg_NodeExists(iterRef, "valueA") == true); LE_TEST(le_cfg_NodeExists(iterRef, "valueB") == true); LE_TEST(le_cfg_NodeExists(iterRef, "valueC") == true); LE_TEST(le_cfg_NodeExists(iterRef, "valueD") == true); LE_TEST(le_cfg_IsEmpty(iterRef, "valueA") == false); LE_TEST(le_cfg_IsEmpty(iterRef, "valueB") == false); LE_TEST(le_cfg_IsEmpty(iterRef, "valueC") == false); LE_TEST(le_cfg_IsEmpty(iterRef, "valueD") == false); le_cfg_CommitTxn(iterRef); } }
//-------------------------------------------------------------------------------------------------- static int GetCfgResourceLimit ( le_cfg_IteratorRef_t limitCfg, // The iterator to use to read the configured limit. This // iterator is owned by the caller and should not be deleted // in this function. const char* nodeName, // The name of the node in the config tree that holds the value. int defaultValue // The default value to use if the config value is invalid. ) { int limitValue = le_cfg_GetInt(limitCfg, nodeName, defaultValue); if (!le_cfg_NodeExists(limitCfg, nodeName)) { LE_INFO("Configured resource limit %s is not available. Using the default value %d.", nodeName, defaultValue); return defaultValue; } if (le_cfg_IsEmpty(limitCfg, nodeName)) { LE_WARN("Configured resource limit %s is empty. Using the default value %d.", nodeName, defaultValue); return defaultValue; } if (le_cfg_GetNodeType(limitCfg, nodeName) != LE_CFG_TYPE_INT) { LE_ERROR("Configured resource limit %s is the wrong type. Using the default value %d.", nodeName, defaultValue); return defaultValue; } if (limitValue < 0) { LE_ERROR("Configured resource limit %s is negative. Using the default value %d.", nodeName, defaultValue); return defaultValue; } return limitValue; }
//-------------------------------------------------------------------------------------------------- static le_result_t GetCfgResourceLimit ( le_cfg_IteratorRef_t limitCfg, // The iterator pointing to the configured limit to read. This // iterator is a owned by the caller and should not be deleted // in this function. rlim_t* limitValuePtr // The value read from the config tree. ) { if (le_cfg_IsEmpty(limitCfg, "")) { return LE_FAULT; } int limitValue = le_cfg_GetInt(limitCfg, "", 0); if (limitValue < 0) { // Negative values are not allowed. return LE_FAULT; } *limitValuePtr = (rlim_t)limitValue; return LE_OK; }
//-------------------------------------------------------------------------------------------------- static void LoadPreferredList ( ) { uint32_t idx = 0; le_dls_List_t preferredNetworkList = LE_DLS_LIST_INIT; // Check that the modemRadioControl has a configuration value for preferred list. le_cfg_IteratorRef_t mrcCfg = le_cfg_CreateReadTxn(CFG_MODEMSERVICE_MRC_PATH"/"CFG_NODE_PREFERREDLIST); if (le_cfg_NodeExists(mrcCfg,"") == false) { LE_DEBUG("'%s' does not exist. Stop reading configuration", CFG_MODEMSERVICE_MRC_PATH"/"CFG_NODE_PREFERREDLIST); le_cfg_CancelTxn(mrcCfg); return; } // Read all network from configDB do { uint32_t ratMask; char mccNodePath[LIMIT_MAX_PATH_BYTES] = {0}; char mncNodePath[LIMIT_MAX_PATH_BYTES] = {0}; char ratNodePath[LIMIT_MAX_PATH_BYTES] = {0}; char mccStr[LIMIT_MAX_PATH_BYTES] = {0}; char mncStr[LIMIT_MAX_PATH_BYTES] = {0}; // Get the node name. char nodeName[LIMIT_MAX_PATH_BYTES] = {0}; sprintf(nodeName,PATTERN_NETWORK"%d",idx); if (le_cfg_IsEmpty(mrcCfg, nodeName)) { LE_DEBUG("'%s' does not exist. stop reading configuration", nodeName); break; } snprintf(mccNodePath, sizeof(mccNodePath), "%s/%s",nodeName,CFG_NODE_MCC); snprintf(mncNodePath, sizeof(mncNodePath), "%s/%s",nodeName,CFG_NODE_MNC); snprintf(ratNodePath, sizeof(ratNodePath), CFG_MODEMSERVICE_MRC_PATH"/"CFG_NODE_PREFERREDLIST"/%s/%s",nodeName,CFG_NODE_RAT); if ( le_cfg_GetString(mrcCfg,mccNodePath,mccStr,sizeof(mccStr),"") != LE_OK ) { LE_WARN("String value for '%s' too large.",mccNodePath); break; } if ( strcmp(mccStr,"") == 0 ) { LE_WARN("No node value set for '%s'",mccNodePath); break; } if ( le_cfg_GetString(mrcCfg,mncNodePath,mncStr,sizeof(mncStr),"") != LE_OK ) { LE_WARN("String value for '%s' too large.",mncNodePath); break; } if ( strcmp(mncStr,"") == 0 ) { LE_WARN("No node value set for '%s'",mncNodePath); break; } if ( LoadRatList(ratNodePath,&ratMask) != LE_OK ) { LE_WARN("Could not read rat information in '%s'",ratNodePath); break; } if ( pa_mrc_AddPreferredNetwork(&preferredNetworkList,mccStr,mncStr,ratMask) != LE_OK ) { LE_WARN("Could not add [%s,%s] into the preferred list",mccStr,mncStr); } ++idx; } while (true); le_cfg_CancelTxn(mrcCfg); if ( pa_mrc_SavePreferredList(&preferredNetworkList) != LE_OK ) { LE_WARN("Could not save the preferred list"); } pa_mrc_ClearPreferedList(&preferredNetworkList); }
//-------------------------------------------------------------------------------------------------- static void ConfigureGdb ( void ) { le_cfg_ConnectService(); le_cfgAdmin_ConnectService(); // Get a write iterator to the application node. le_cfg_IteratorRef_t cfgIter = le_cfg_CreateWriteTxn("/apps"); le_cfg_GoToNode(cfgIter, AppName); // Check if this is a temporary configuration that was previously created by this or a similar // tool. if (!le_cfg_IsEmpty(cfgIter, CFG_DEBUG_TOOL)) { char debugTool[LIMIT_MAX_PATH_BYTES]; // Don't need to check return code because the value is just informative and does not matter // if it is truncated. le_cfg_GetString(cfgIter, CFG_DEBUG_TOOL, debugTool, sizeof(debugTool), ""); fprintf(stderr, "This application has already been configured for %s debug mode.\n", debugTool); exit(EXIT_FAILURE); } // Write into the config's debug tool node to indicate that this configuration has been modified. le_cfg_SetString(cfgIter, CFG_DEBUG_TOOL, "gdb"); // Add 512K to the maxFileSytemBytes so that we can debug this app in sandboxed mode uint32_t maxBytes; maxBytes = le_cfg_GetInt(cfgIter, "maxFileSystemBytes", DEFAULT_LIMIT_MAX_FILE_SYSTEM_BYTES); maxBytes += ADD_FILE_SYSTEM_BYTES; // add an additional 512KBytes LE_INFO("Resetting maxFileSystemBytes to %d bytes", maxBytes); le_cfg_SetInt(cfgIter, "maxFileSystemBytes", maxBytes); // Add gdbserver and libs to the app's 'requires/files' section. le_cfg_GoToNode(cfgIter, "requires/files"); AddImportFiles(cfgIter, &GdbFilesImports, NUM_ARRAY_MEMBERS(GdbFilesImports)); // Add /proc to the app's dirs section. le_cfg_GoToParent(cfgIter); le_cfg_GoToNode(cfgIter, "dirs"); AddImportFiles(cfgIter, &GdbDirsImports, NUM_ARRAY_MEMBERS(GdbDirsImports)); // Delete the list of processes. le_cfg_GoToParent(cfgIter); le_cfg_GoToParent(cfgIter); int i; for (i = 0; i < NumProcs; i++) { char nodePath[LIMIT_MAX_PATH_BYTES]; int n = snprintf(nodePath, sizeof(nodePath), "procs/%s", ProcNames[i]); INTERNAL_ERR_IF(n >= sizeof(nodePath), "Node name is too long."); INTERNAL_ERR_IF(n < 0, "Format error. %m"); le_cfg_DeleteNode(cfgIter, nodePath); } le_cfg_CommitTxn(cfgIter); }
//-------------------------------------------------------------------------------------------------- static le_result_t GetArgs ( proc_Ref_t procRef, ///< [IN] The process to get the args for. char argsBuffers[LIMIT_MAX_NUM_CMD_LINE_ARGS][LIMIT_MAX_ARGS_STR_BYTES], ///< [OUT] A pointer to /// an array of buffers /// used to store /// arguments. char* argsPtr[NUM_ARGS_PTRS] ///< [OUT] An array of pointers that will point to the valid /// arguments list. The list is terminated by NULL. ) { // Get a config iterator to the arguments list. le_cfg_IteratorRef_t procCfg = le_cfg_CreateReadTxn(procRef->cfgPathRoot); le_cfg_GoToNode(procCfg, CFG_NODE_ARGS); if (le_cfg_GoToFirstChild(procCfg) != LE_OK) { LE_ERROR("No arguments for process '%s'.", procRef->name); le_cfg_CancelTxn(procCfg); return LE_FAULT; } size_t ptrIndex = 0; size_t bufIndex = 0; // Record the executable path. if (le_cfg_GetString(procCfg, "", argsBuffers[bufIndex], LIMIT_MAX_ARGS_STR_BYTES, "") != LE_OK) { LE_ERROR("Error reading argument '%s...' for process '%s'.", argsBuffers[bufIndex], procRef->name); le_cfg_CancelTxn(procCfg); return LE_FAULT; } argsPtr[ptrIndex++] = argsBuffers[bufIndex++]; // Record the process name in the list. argsPtr[ptrIndex++] = procRef->name; // Record the arguments in the caller's list of buffers. while(1) { if (le_cfg_GoToNextSibling(procCfg) != LE_OK) { // Terminate the list. argsPtr[ptrIndex] = NULL; break; } else if (bufIndex >= LIMIT_MAX_NUM_CMD_LINE_ARGS) { LE_ERROR("Too many arguments for process '%s'.", procRef->name); le_cfg_CancelTxn(procCfg); return LE_FAULT; } if (le_cfg_IsEmpty(procCfg, "")) { LE_ERROR("Empty node in argument list for process '%s'.", procRef->name); le_cfg_CancelTxn(procCfg); return LE_FAULT; } if (le_cfg_GetString(procCfg, "", argsBuffers[bufIndex], LIMIT_MAX_ARGS_STR_BYTES, "") != LE_OK) { LE_ERROR("Argument too long '%s...' for process '%s'.", argsBuffers[bufIndex], procRef->name); le_cfg_CancelTxn(procCfg); return LE_FAULT; } // Point to the string. argsPtr[ptrIndex++] = argsBuffers[bufIndex++]; } le_cfg_CancelTxn(procCfg); return LE_OK; }