aboutsummaryrefslogtreecommitdiffstats
path: root/android/utils
diff options
context:
space:
mode:
authorVladimir Chtchetkine <vchtchetkine@google.com>2012-01-12 13:37:40 -0800
committerVladimir Chtchetkine <vchtchetkine@google.com>2012-01-13 08:16:05 -0800
commitdb450d73092add519efddcd6d55c7a0e7541ec70 (patch)
treea4de5f7d4c9d1fb35a376dcd198da8c06c846b4f /android/utils
parentaa1af37d8b3c3a21eb4cac4a225225425b50d08c (diff)
downloadexternal_qemu-db450d73092add519efddcd6d55c7a0e7541ec70.zip
external_qemu-db450d73092add519efddcd6d55c7a0e7541ec70.tar.gz
external_qemu-db450d73092add519efddcd6d55c7a0e7541ec70.tar.bz2
Respect HW configs when loading VM from snapshots.
Changing HW configuration properties may cause emulator / guest system crash on condition that VM has been loaded from a snapshot. This CL addresses this issue in the following way: 1. Each time a snapshot is saved, a backup copy of HW config is saved with it. 2. Each time a snapshot is loaded, emulator finds an appropriate HW config backup, and compares current HW config with the one that was saved in the backup, and if configs are different, emulator exits with an appropriate error. Change-Id: I730bec0afbe166e88189fdcc4804b76e109e4422
Diffstat (limited to 'android/utils')
-rw-r--r--android/utils/ini.c53
-rw-r--r--android/utils/ini.h17
2 files changed, 63 insertions, 7 deletions
diff --git a/android/utils/ini.c b/android/utils/ini.c
index ff4a8af..43f1321 100644
--- a/android/utils/ini.c
+++ b/android/utils/ini.c
@@ -298,8 +298,18 @@ EXIT:
return ini;
}
-int
-iniFile_saveToFile( IniFile* f, const char* filepath )
+/* Common routine for saving IniFile instance to the given file.
+ * Param:
+ * f - IniFile instance to save.
+ * filepath - Path to a file where to save the instance.
+ * strip - If 1, ignore (don't save) pairs with empty values. If 0, save all
+ * pairs found in the IniFile instance, including the ones that contain
+ * empty values.
+ * Returns:
+ * 0 on success, -1 on error (see errno for error code)
+ */
+static int
+iniFile_saveToFileCommon( IniFile* f, const char* filepath, int strip )
{
FILE* fp = fopen(filepath, "wt");
IniPair* pair = f->pairs;
@@ -313,11 +323,13 @@ iniFile_saveToFile( IniFile* f, const char* filepath )
}
for ( ; pair < pairEnd; pair++ ) {
- char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
- p = bufprint(temp, end, "%s = %s\n", pair->key, pair->value);
- if (fwrite(temp, p - temp, 1, fp) != 1) {
- result = -1;
- break;
+ if ((pair->value && *pair->value) || !strip) {
+ char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
+ p = bufprint(temp, end, "%s = %s\n", pair->key, pair->value);
+ if (fwrite(temp, p - temp, 1, fp) != 1) {
+ result = -1;
+ break;
+ }
}
}
@@ -325,6 +337,33 @@ iniFile_saveToFile( IniFile* f, const char* filepath )
return result;
}
+int
+iniFile_saveToFile( IniFile* f, const char* filepath )
+{
+ return iniFile_saveToFileCommon(f, filepath, 0);
+}
+
+int
+iniFile_saveToFileClean( IniFile* f, const char* filepath )
+{
+ return iniFile_saveToFileCommon(f, filepath, 1);
+}
+
+int
+iniFile_getEntry(IniFile* f, int index, char** key, char** value)
+{
+ if (index >= f->numPairs) {
+ D("Index %d exceeds the number of ini file entries %d",
+ index, f->numPairs);
+ return -1;
+ }
+
+ *key = ASTRDUP(f->pairs[index].key);
+ *value = ASTRDUP(f->pairs[index].value);
+
+ return 0;
+}
+
char*
iniFile_getString( IniFile* f, const char* key, const char* defaultValue )
{
diff --git a/android/utils/ini.h b/android/utils/ini.h
index 5730ee0..fd56575 100644
--- a/android/utils/ini.h
+++ b/android/utils/ini.h
@@ -37,6 +37,11 @@ IniFile* iniFile_newFromFile( const char* filePath);
*/
int iniFile_saveToFile( IniFile* f, const char* filePath );
+/* try to write an IniFile into a given file, ignorig pairs with empty values.
+ * returns 0 on success, -1 on error (see errno for error code)
+ */
+int iniFile_saveToFileClean( IniFile* f, const char* filepath );
+
/* free an IniFile object */
void iniFile_free( IniFile* f );
@@ -48,6 +53,18 @@ int iniFile_getPairCount( IniFile* f );
*/
const char* iniFile_getValue( IniFile* f, const char* key );
+/* Copies a 'key, value' pair for an entry in the file.
+ * Param:
+ * f - Initialized IniFile instance.
+ * index - Index of the entry to copy. Must be less than value returned from the
+ * iniFile_getPairCount routine.
+ * key, value - Receives key, and value strings for the entry. If this routine
+ * succeeds, the caller must free the buffers allocated for the strings.
+ * Return:
+ * 0 on success, -1 if the index exceeds the capacity of the file
+ */
+int iniFile_getEntry(IniFile* f, int index, char** key, char** value);
+
/* returns a copy of the value of a given key, or NULL if defaultValue is NULL.
* caller must free() it.
*/