From patchwork Wed Sep 23 10:24:11 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 34146 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 24E30B7B68 for ; Wed, 23 Sep 2009 21:26:00 +1000 (EST) Received: from localhost ([127.0.0.1]:43820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MqPyv-0006Nm-4g for incoming@patchwork.ozlabs.org; Wed, 23 Sep 2009 07:25:57 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MqP2x-0003r0-UZ for qemu-devel@nongnu.org; Wed, 23 Sep 2009 06:26:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MqP2i-0003gZ-0b for qemu-devel@nongnu.org; Wed, 23 Sep 2009 06:25:54 -0400 Received: from [199.232.76.173] (port=37810 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MqP2g-0003fj-Mv for qemu-devel@nongnu.org; Wed, 23 Sep 2009 06:25:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45164) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MqP2g-0001VT-0e for qemu-devel@nongnu.org; Wed, 23 Sep 2009 06:25:46 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8NAPj0O016518 for ; Wed, 23 Sep 2009 06:25:45 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8NAPhG6012109; Wed, 23 Sep 2009 06:25:44 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 1EEF64743E; Wed, 23 Sep 2009 11:24:24 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 23 Sep 2009 11:24:11 +0100 Message-Id: <1253701463-3134-13-git-send-email-markmc@redhat.com> In-Reply-To: <1253701463-3134-1-git-send-email-markmc@redhat.com> References: <1253701463-3134-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 12/24] Never overwrite a QemuOpt 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 Rather than overwriting a QemuOpt, just add a new one to the tail and always do a reverse search for parameters to preserve the same behaviour. We use this order so that foreach() iterates over the opts in their original order. This will allow us handle options where multiple values for the same parameter is allowed - e.g. -net user,hostfwd= Signed-off-by: Mark McLoughlin --- qemu-option.c | 51 +++++++++++++++++++++++---------------------------- 1 files changed, 23 insertions(+), 28 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 6cb5f50..ffc369a 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -483,7 +483,7 @@ struct QemuOpt { struct QemuOpts { const char *id; QemuOptsList *list; - QTAILQ_HEAD(, QemuOpt) head; + QTAILQ_HEAD(QemuOptHead, QemuOpt) head; QTAILQ_ENTRY(QemuOpts) next; }; @@ -491,7 +491,7 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) { QemuOpt *opt; - QTAILQ_FOREACH(opt, &opts->head, next) { + QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) { if (strcmp(opt->name, name) != 0) continue; return opt; @@ -565,36 +565,31 @@ static void qemu_opt_del(QemuOpt *opt) int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) { QemuOpt *opt; + QemuOptDesc *desc = opts->list->desc; + int i; - opt = qemu_opt_find(opts, name); - if (!opt) { - QemuOptDesc *desc = opts->list->desc; - int i; - - for (i = 0; desc[i].name != NULL; i++) { - if (strcmp(desc[i].name, name) == 0) { - break; - } - } - if (desc[i].name == NULL) { - if (i == 0) { - /* empty list -> allow any */; - } else { - fprintf(stderr, "option \"%s\" is not valid for %s\n", - name, opts->list->name); - return -1; - } + for (i = 0; desc[i].name != NULL; i++) { + if (strcmp(desc[i].name, name) == 0) { + break; } - opt = qemu_mallocz(sizeof(*opt)); - opt->name = qemu_strdup(name); - opt->opts = opts; - QTAILQ_INSERT_TAIL(&opts->head, opt, next); - if (desc[i].name != NULL) { - opt->desc = desc+i; + } + if (desc[i].name == NULL) { + if (i == 0) { + /* empty list -> allow any */; + } else { + fprintf(stderr, "option \"%s\" is not valid for %s\n", + name, opts->list->name); + return -1; } } - qemu_free((/* !const */ char*)opt->str); - opt->str = NULL; + + opt = qemu_mallocz(sizeof(*opt)); + opt->name = qemu_strdup(name); + opt->opts = opts; + QTAILQ_INSERT_TAIL(&opts->head, opt, next); + if (desc[i].name != NULL) { + opt->desc = desc+i; + } if (value) { opt->str = qemu_strdup(value); }