X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_options.c;h=a1b8aae629a2d68ac4631ffab840b365498a2b17;hb=8d2c7907ad4b10ccb51dfb7e5ee7c02604b786ba;hp=82f12d9df3008742e44d9db08c1bfa574b6e2001;hpb=a19f42cc45ff4c4a07bf917a78a2a422319a78bb;p=palacios.git diff --git a/palacios/src/palacios/vmm_options.c b/palacios/src/palacios/vmm_options.c index 82f12d9..a1b8aae 100644 --- a/palacios/src/palacios/vmm_options.c +++ b/palacios/src/palacios/vmm_options.c @@ -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 +}