From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG8pl-0000oV-UP for qemu-devel@nongnu.org; Wed, 19 Feb 2014 10:13:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WG8pf-0002h8-3S for qemu-devel@nongnu.org; Wed, 19 Feb 2014 10:13:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:61961) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG8pe-0002gl-R8 for qemu-devel@nongnu.org; Wed, 19 Feb 2014 10:13:07 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1JFD6Xs016308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 19 Feb 2014 10:13:06 -0500 From: Kevin Wolf Date: Wed, 19 Feb 2014 16:12:54 +0100 Message-Id: <1392822778-4823-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1392822778-4823-1-git-send-email-kwolf@redhat.com> References: <1392822778-4823-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 3/7] qemu-img amend: Detect options specified more than once List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, mreitz@redhat.com Instead of ignoring all option values but the last one, error out if an option is set multiple times. Again, the only exception is a -o help option, which may be added to any valid qemu-img amend command and ignores all other options. Signed-off-by: Kevin Wolf --- qemu-img.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 55c2c75..247987d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2687,6 +2687,7 @@ static int img_amend(int argc, char **argv) { int c, ret = 0; char *options = NULL; + bool options_help = false; QEMUOptionParameter *create_options = NULL, *options_param = NULL; const char *fmt = NULL, *filename; bool quiet = false; @@ -2704,9 +2705,22 @@ static int img_amend(int argc, char **argv) help(); break; case 'o': - options = optarg; + if (is_help_option(optarg)) { + options_help = true; + } else if (!options) { + options = optarg; + } else { + error_report("-o cannot be used multiple times. Please use a " + "single -o option with comma-separated settings " + "instead."); + return 1; + } break; case 'f': + if (fmt) { + error_report("-f may only be specified once"); + return 1; + } fmt = optarg; break; case 'q': @@ -2734,7 +2748,7 @@ static int img_amend(int argc, char **argv) fmt = bs->drv->format_name; - if (is_help_option(options)) { + if (options_help) { ret = print_block_option_help(filename, fmt); goto out; } -- 1.8.1.4