//-------------------------------------------------------------------------------------------------- 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 void SetObject9InstanceForApp ( const char* appName, ///< The name of the application in question. assetData_InstanceDataRef_t instanceRef ///< The instance of object 9 to link to. Pass NULL if ///< the link is to be cleared. ) //-------------------------------------------------------------------------------------------------- { le_cfg_IteratorRef_t iterRef = le_cfg_CreateWriteTxn(CFG_OBJECT_INFO_PATH); if (instanceRef != NULL) { int instanceId; LE_ASSERT(assetData_GetInstanceId(instanceRef, &instanceId) == LE_OK); le_cfg_GoToNode(iterRef, appName); le_cfg_SetInt(iterRef, "oiid", instanceId); LE_DEBUG("Application '%s' mapped to instance %d.", appName, instanceId); } else { le_cfg_DeleteNode(iterRef, appName); } le_cfg_CommitTxn(iterRef); }
static void ClearTree() { LE_INFO("---- Clearing Out Current Tree -----------------------------------------------------"); le_cfg_IteratorRef_t iterRef = le_cfg_CreateWriteTxn(TestRootDir); LE_FATAL_IF(iterRef == NULL, "Test: %s - Could not create iterator.", TestRootDir); DumpTree(iterRef, 0); le_cfg_DeleteNode(iterRef, ""); le_cfg_CommitTxn(iterRef); iterRef = le_cfg_CreateReadTxn(TestRootDir); DumpTree(iterRef, 0); le_cfg_CancelTxn(iterRef); }
//-------------------------------------------------------------------------------------------------- LE_SHARED void cfgInstall_Remove ( const char* appName ) //-------------------------------------------------------------------------------------------------- { LE_INFO("Removing configuration for application '%s'.", appName); // Remove the app configuration from the system tree. le_cfg_IteratorRef_t i = le_cfg_CreateWriteTxn("/apps"); le_cfg_DeleteNode(i, appName); le_cfg_CommitTxn(i); // Now delete the app specific tree. le_cfgAdmin_DeleteTree(appName); }
static void DeleteTest() { static char pathBuffer[STR_SIZE] = { 0 }; snprintf(pathBuffer, STR_SIZE, "%s/deleteTest/", TestRootDir); le_cfg_IteratorRef_t iterRef = le_cfg_CreateWriteTxn(pathBuffer); le_cfg_SetString(iterRef, "valueA", "aNewValue"); le_cfg_SetString(iterRef, "valueB", "aNewValue"); le_cfg_SetString(iterRef, "valueC", "aNewValue"); TestValue(iterRef, "valueA", "aNewValue"); TestValue(iterRef, "valueB", "aNewValue"); TestValue(iterRef, "valueC", "aNewValue"); le_cfg_CommitTxn(iterRef); iterRef = le_cfg_CreateWriteTxn(pathBuffer); le_cfg_DeleteNode(iterRef, "valueB"); TestValue(iterRef, "valueA", "aNewValue"); TestValue(iterRef, "valueB", ""); TestValue(iterRef, "valueC", "aNewValue"); le_cfg_CommitTxn(iterRef); iterRef = le_cfg_CreateReadTxn(pathBuffer); TestValue(iterRef, "valueA", "aNewValue"); TestValue(iterRef, "valueB", ""); TestValue(iterRef, "valueC", "aNewValue"); DumpTree(iterRef, 0); le_cfg_CancelTxn(iterRef); }
//-------------------------------------------------------------------------------------------------- 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 int HandleCopy ( void ) // ------------------------------------------------------------------------------------------------- { // Create a temp file to export the tree to. char tempFilePath[] = "/tmp/configExport-XXXXXX"; int tempFd; do { tempFd = mkstemp(tempFilePath); } while ((tempFd == -1) && (errno == EINTR)); if (tempFd == -1) { fprintf(stderr, "Could not create temp file. Reason, %s (%d).", strerror(errno), errno); return 1; } // Unlink the file now so that we can make sure that it will end up being deleted, no matter how // we exit. if (unlink(tempFilePath) == -1) { printf("Could not unlink temporary file. Reason, %s (%d).", strerror(errno), errno); } // Create a transaction and export the data from the config tree. le_cfg_IteratorRef_t iterRef = le_cfg_CreateWriteTxn(NodePath); le_result_t result = le_cfgAdmin_ExportTree(iterRef, tempFilePath, ""); if (result != LE_OK) { fprintf(stderr, "An I/O error occurred while updating the config tree. " "Tree has been left untouched.\n"); goto txnDone; } if (DeleteAfterCopy != false) { // Since this is a rename, then delete the node at the original location. le_cfg_DeleteNode(iterRef, ""); } // Now, move the iterator to the node's new name, then attempt to reload the data. le_cfg_GoToNode(iterRef, ".."); result = le_cfgAdmin_ImportTree(iterRef, tempFilePath, NodeDestPath); if (result != LE_OK) { switch (result) { case LE_FAULT: fprintf(stderr, "An I/O error occurred while updating the config tree. " "Tree has been left untouched.\n"); break; case LE_FORMAT_ERROR: fprintf(stderr, "Import/export corruption detected. Tree has been left untouched.\n"); break; default: fprintf(stderr, "An unexpected error has occurred: %s, (%d).\n", LE_RESULT_TXT(result), result); break; } } txnDone: // Make sure that the change was successful, and either commit or discard any changes that were // made. if (result == LE_OK) { le_cfg_CommitTxn(iterRef); } else { le_cfg_CancelTxn(iterRef); } // Was the operation successful? int exitResult = (result == LE_OK) ? EXIT_SUCCESS : EXIT_FAILURE; // Finally, clean up our temp file and report our results. int closeRetVal; do { closeRetVal = close(tempFd); } while ((closeRetVal == -1) && (errno == EINTR)); if (closeRetVal == -1) { fprintf(stderr, "Could not close temp file. Reason, %s (%d).", strerror(errno), errno); exitResult = EXIT_FAILURE; } return exitResult; }