diff options
author | Markus Armbruster <armbru@redhat.com> | 2010-02-18 19:48:33 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2010-03-16 16:58:32 +0100 |
commit | cf5a65aaaf3e9382e50df550ba049a1c8691a5dd (patch) | |
tree | cefb10d2cab499ba0d7c76682503a309c187dc4a /qemu-config.c | |
parent | 65abca0a3441fb47024553e7676f6f3eef685a32 (diff) | |
download | qemu-cf5a65aaaf3e9382e50df550ba049a1c8691a5dd.zip qemu-cf5a65aaaf3e9382e50df550ba049a1c8691a5dd.tar.gz qemu-cf5a65aaaf3e9382e50df550ba049a1c8691a5dd.tar.bz2 |
error: Track locations in configuration files
New LOC_FILE. Use it for tracking file name and line number in
qemu_config_parse(). We now report errors like
qemu:foo.conf:42: Did not find I2C bus for smbus-eeprom
In particular, gems like this message:
-device: no driver specified
become almost nice now:
qemu:foo.conf:44: -device: no driver specified
(A later commit will get rid of the bogus -device:)
Diffstat (limited to 'qemu-config.c')
-rw-r--r-- | qemu-config.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/qemu-config.c b/qemu-config.c index 8e06770..2de97cd 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -425,13 +425,17 @@ void qemu_config_write(FILE *fp) } } -int qemu_config_parse(FILE *fp) +int qemu_config_parse(FILE *fp, const char *fname) { char line[1024], group[64], id[64], arg[64], value[1024]; + Location loc; QemuOptsList *list = NULL; QemuOpts *opts = NULL; + int res = -1, lno = 0; + loc_push_none(&loc); while (fgets(line, sizeof(line), fp) != NULL) { + loc_set_file(fname, ++lno); if (line[0] == '\n') { /* skip empty lines */ continue; @@ -444,7 +448,7 @@ int qemu_config_parse(FILE *fp) /* group with id */ list = find_list(group); if (list == NULL) - return -1; + goto out; opts = qemu_opts_create(list, id, 1); continue; } @@ -452,25 +456,27 @@ int qemu_config_parse(FILE *fp) /* group without id */ list = find_list(group); if (list == NULL) - return -1; + goto out; opts = qemu_opts_create(list, NULL, 0); continue; } if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) { /* arg = value */ if (opts == NULL) { - fprintf(stderr, "no group defined\n"); - return -1; + error_report("no group defined"); + goto out; } if (qemu_opt_set(opts, arg, value) != 0) { - fprintf(stderr, "failed to set \"%s\" for %s\n", - arg, group); - return -1; + error_report("failed to set \"%s\" for %s", arg, group); + goto out; } continue; } - fprintf(stderr, "parse error: %s\n", line); - return -1; + error_report("parse error"); + goto out; } - return 0; + res = 0; +out: + loc_pop(&loc); + return res; } |