From patchwork Tue Jun 5 17:25:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 163130 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 31666B6F9F for ; Wed, 6 Jun 2012 04:20:01 +1000 (EST) Received: from localhost ([::1]:42777 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbyMJ-0006JN-0F for incoming@patchwork.ozlabs.org; Tue, 05 Jun 2012 14:19:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbxWI-000407-0t for qemu-devel@nongnu.org; Tue, 05 Jun 2012 13:26:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SbxWC-0001J2-Ra for qemu-devel@nongnu.org; Tue, 05 Jun 2012 13:26:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63359) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbxWC-0001Hy-K4 for qemu-devel@nongnu.org; Tue, 05 Jun 2012 13:26:08 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q55HQ7UV010115 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 5 Jun 2012 13:26:07 -0400 Received: from localhost (ovpn-116-79.ams2.redhat.com [10.36.116.79]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q55HQ5lR016700; Tue, 5 Jun 2012 13:26:06 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 5 Jun 2012 14:25:02 -0300 Message-Id: <1338917108-3965-24-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1338917108-3965-1-git-send-email-lcapitulino@redhat.com> References: <1338917108-3965-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 23/29] qemu-config: find_list(): use error_set() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Note that qemu_find_opts() and qemu_config_parse() need to call error_report() to maintain their semantics on error. Signed-off-by: Luiz Capitulino Reviewed-By: Laszlo Ersek --- qemu-config.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index f876646..bdb381d 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -3,6 +3,7 @@ #include "qemu-option.h" #include "qemu-config.h" #include "hw/qdev.h" +#include "error.h" static QemuOptsList qemu_drive_opts = { .name = "drive", @@ -631,7 +632,8 @@ static QemuOptsList *vm_config_groups[32] = { NULL, }; -static QemuOptsList *find_list(QemuOptsList **lists, const char *group) +static QemuOptsList *find_list(QemuOptsList **lists, const char *group, + Error **errp) { int i; @@ -640,14 +642,23 @@ static QemuOptsList *find_list(QemuOptsList **lists, const char *group) break; } if (lists[i] == NULL) { - error_report("there is no option group \"%s\"", group); + error_set(errp, QERR_INVALID_OPTION_GROUP, group); } return lists[i]; } QemuOptsList *qemu_find_opts(const char *group) { - return find_list(vm_config_groups, group); + QemuOptsList *ret; + Error *local_err = NULL; + + ret = find_list(vm_config_groups, group, &local_err); + if (error_is_set(&local_err)) { + error_report("%s\n", error_get_pretty(local_err)); + error_free(local_err); + } + + return ret; } void qemu_add_opts(QemuOptsList *list) @@ -762,6 +773,7 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) char line[1024], group[64], id[64], arg[64], value[1024]; Location loc; QemuOptsList *list = NULL; + Error *local_err = NULL; QemuOpts *opts = NULL; int res = -1, lno = 0; @@ -778,17 +790,23 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) } if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) { /* group with id */ - list = find_list(lists, group); - if (list == NULL) + list = find_list(lists, group, &local_err); + if (error_is_set(&local_err)) { + error_report("%s\n", error_get_pretty(local_err)); + error_free(local_err); goto out; + } opts = qemu_opts_create(list, id, 1, NULL); continue; } if (sscanf(line, "[%63[^]]]", group) == 1) { /* group without id */ - list = find_list(lists, group); - if (list == NULL) + list = find_list(lists, group, &local_err); + if (error_is_set(&local_err)) { + error_report("%s\n", error_get_pretty(local_err)); + error_free(local_err); goto out; + } opts = qemu_opts_create(list, NULL, 0, NULL); continue; }