Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Minor VMX NPT bug fix (printing)
[palacios.git] / palacios / src / palacios / vmm_options.c
index 82f12d9..a1b8aae 100644 (file)
@@ -46,12 +46,47 @@ static int option_eq_fn(addr_t key1, addr_t key2) {
     return (strcmp(name1, name2) == 0);
 }
 
+// need to allocate these cleanly and separately so we can easily recover the
+// storage
+static int option_insert(char *key, char *val)
+{
+    char *k, *v;
+
+    k = V3_Malloc(strlen(key)+1);
+
+    if (!k) { 
+       return -1;
+    }
+    
+    v = V3_Malloc(strlen(val)+1);
+
+    if (!v) { 
+       V3_Free(k);
+       return -1;
+    }
+
+    strcpy(k,key);
+    strcpy(v,val);
+
+    if (!v3_htable_insert(option_table, (addr_t)k, (addr_t)v)) {
+       V3_Free(v);
+       V3_Free(k);
+       return -1;
+    }
+
+    return 0;
+}
+
+
 void v3_parse_options(char *options)
 {
     char *currKey = NULL, *currVal = NULL;
     int parseKey = 1;
     int len;
     char *c;
+
+    option_table = v3_create_htable(0, option_hash_fn, option_eq_fn);
+
     if (!options) {
        return; 
     }
@@ -61,17 +96,16 @@ void v3_parse_options(char *options)
     strcpy(option_storage, options);
     c = option_storage;
 
-    option_table = v3_create_htable(0, option_hash_fn, option_eq_fn);
     while (c && *c) {
        /* Skip whitespace */
         if ((*c == ' ')
-           || (*c == '\t')) {
+           || (*c == '\t') || (*c == ',')) {
            *c = 0;
            if (currKey) {
                if (!currVal) {
                    currVal = truevalue;
                }
-               v3_htable_insert(option_table, (addr_t)currKey, (addr_t)currVal);
+               option_insert(currKey, currVal);
                parseKey = 1;
                currKey = NULL;
                currVal = NULL;
@@ -97,11 +131,20 @@ void v3_parse_options(char *options)
        if (!currVal) {
            currVal = truevalue;
        } 
-       v3_htable_insert(option_table, (addr_t)currKey, (addr_t)currVal);
+       option_insert(currKey, currVal);
     }
+    
+    V3_Free(option_storage);
+
     return;
 }
 
 char *v3_lookup_option(char *key) {
     return (char *)v3_htable_search(option_table, (addr_t)(key));
 }
+
+
+void v3_deinit_options()
+{
+    v3_free_htable(option_table,1,1); // will free keys and values
+}