From patchwork Thu Mar 4 15:56:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 46951 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C2B9AB7CB8 for ; Fri, 5 Mar 2010 04:17:55 +1100 (EST) Received: from localhost ([127.0.0.1]:35619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnEg9-0001ZP-Rx for incoming@patchwork.ozlabs.org; Thu, 04 Mar 2010 12:17:41 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NnDXX-0005gj-LO for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:43 -0500 Received: from [199.232.76.173] (port=58585 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnDXW-0005gX-Om for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:42 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NnDXQ-0001Ql-T6 for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:41 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:47485) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NnDXO-0001PI-LE for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:35 -0500 Received: from blackfin.pond.sub.org (pD9E38041.dip.t-dialin.net [217.227.128.65]) by oxygen.pond.sub.org (Postfix) with ESMTPA id D04EE2DD30F for ; Thu, 4 Mar 2010 17:04:30 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 572BF108; Thu, 4 Mar 2010 16:57:12 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 4 Mar 2010 16:56:41 +0100 Message-Id: <1267718231-13303-21-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1267718231-13303-1-git-send-email-armbru@redhat.com> References: <1267718231-13303-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Luiz Capitulino Subject: [Qemu-devel] [PATCH 20/50] error: Track locations in configuration files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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:) Signed-off-by: Markus Armbruster --- qemu-config.c | 28 +++++++++++++++++----------- qemu-config.h | 2 +- qemu-error.c | 20 ++++++++++++++++++++ qemu-error.h | 3 ++- vl.c | 14 +++++++++----- 5 files changed, 49 insertions(+), 18 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; } diff --git a/qemu-config.h b/qemu-config.h index b335c42..c507687 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 214e448..23176e1 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 204dfb6..8f2a140 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 2ba8eda..397b018 100644 --- a/vl.c +++ b/vl.c @@ -4901,18 +4901,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); @@ -5585,7 +5589,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);