aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2010-02-18 19:48:33 +0100
committerMarkus Armbruster <armbru@redhat.com>2010-03-16 16:58:32 +0100
commitcf5a65aaaf3e9382e50df550ba049a1c8691a5dd (patch)
treecefb10d2cab499ba0d7c76682503a309c187dc4a
parent65abca0a3441fb47024553e7676f6f3eef685a32 (diff)
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:)
-rw-r--r--qemu-config.c28
-rw-r--r--qemu-config.h2
-rw-r--r--qemu-error.c20
-rw-r--r--qemu-error.h3
-rw-r--r--vl.c14
5 files changed, 49 insertions, 18 deletions
diff --git a/qemu-config.c b/qemu-config.c
index 8e06770a1..2de97cde2 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;
}
diff --git a/qemu-config.h b/qemu-config.h
index b335c4292..c507687d6 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -16,6 +16,6 @@ int qemu_global_option(const char *str);
void qemu_add_globals(void);
void qemu_config_write(FILE *fp);
-int qemu_config_parse(FILE *fp);
+int qemu_config_parse(FILE *fp, const char *fname);
#endif /* QEMU_CONFIG_H */
diff --git a/qemu-error.c b/qemu-error.c
index 214e4481e..23176e16a 100644
--- a/qemu-error.c
+++ b/qemu-error.c
@@ -113,6 +113,19 @@ void loc_set_none(void)
cur_loc->kind = LOC_NONE;
}
+/*
+ * Change the current location to file FNAME, line LNO.
+ */
+void loc_set_file(const char *fname, int lno)
+{
+ assert (fname || cur_loc->kind == LOC_FILE);
+ cur_loc->kind = LOC_FILE;
+ cur_loc->num = lno;
+ if (fname) {
+ cur_loc->ptr = fname;
+ }
+}
+
static const char *progname;
/*
@@ -136,6 +149,13 @@ void error_print_loc(void)
sep = " ";
}
switch (cur_loc->kind) {
+ case LOC_FILE:
+ error_printf("%s:", (const char *)cur_loc->ptr);
+ if (cur_loc->num) {
+ error_printf("%d:", cur_loc->num);
+ }
+ error_printf(" ");
+ break;
default:
error_printf(sep);
}
diff --git a/qemu-error.h b/qemu-error.h
index 204dfb6a9..8f2a140ef 100644
--- a/qemu-error.h
+++ b/qemu-error.h
@@ -15,7 +15,7 @@
typedef struct Location {
/* all members are private to qemu-error.c */
- enum { LOC_NONE } kind;
+ enum { LOC_NONE, LOC_FILE } kind;
int num;
const void *ptr;
struct Location *prev;
@@ -27,6 +27,7 @@ Location *loc_pop(Location *loc);
Location *loc_save(Location *loc);
void loc_restore(Location *loc);
void loc_set_none(void);
+void loc_set_file(const char *fname, int lno);
void error_vprintf(const char *fmt, va_list ap);
void error_printf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
diff --git a/vl.c b/vl.c
index c3abeeff2..a83ed553f 100644
--- a/vl.c
+++ b/vl.c
@@ -4941,18 +4941,22 @@ int main(int argc, char **argv, char **envp)
}
if (defconfig) {
+ const char *fname;
FILE *fp;
- fp = fopen(CONFIG_QEMU_CONFDIR "/qemu.conf", "r");
+
+ fname = CONFIG_QEMU_CONFDIR "/qemu.conf";
+ fp = fopen(fname, "r");
if (fp) {
- if (qemu_config_parse(fp) != 0) {
+ if (qemu_config_parse(fp, fname) != 0) {
exit(1);
}
fclose(fp);
}
- fp = fopen(CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", "r");
+ fname = CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf";
+ fp = fopen(fname, "r");
if (fp) {
- if (qemu_config_parse(fp) != 0) {
+ if (qemu_config_parse(fp, fname) != 0) {
exit(1);
}
fclose(fp);
@@ -5633,7 +5637,7 @@ int main(int argc, char **argv, char **envp)
fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
exit(1);
}
- if (qemu_config_parse(fp) != 0) {
+ if (qemu_config_parse(fp, optarg) != 0) {
exit(1);
}
fclose(fp);