From nobody Mon May 6 12:44:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489747634823706.254881902543; Fri, 17 Mar 2017 03:47:14 -0700 (PDT) Received: from localhost ([::1]:48163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1copPd-0000v3-Fm for importer@patchew.org; Fri, 17 Mar 2017 06:47:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1copOO-0000nM-U2 for qemu-devel@nongnu.org; Fri, 17 Mar 2017 06:46:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1copOO-0000Jz-37 for qemu-devel@nongnu.org; Fri, 17 Mar 2017 06:45:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53646) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1copOL-0000IG-BB; Fri, 17 Mar 2017 06:45:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 497BAC05B1E3; Fri, 17 Mar 2017 10:45:53 +0000 (UTC) Received: from localhost (ovpn-116-23.ams2.redhat.com [10.36.116.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8FE05DC1D; Fri, 17 Mar 2017 10:45:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 497BAC05B1E3 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=stefanha@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 497BAC05B1E3 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 18:45:39 +0800 Message-Id: <20170317104541.28979-2-stefanha@redhat.com> In-Reply-To: <20170317104541.28979-1-stefanha@redhat.com> References: <20170317104541.28979-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 17 Mar 2017 10:45:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/3] qemu-img: show help for invalid global options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The qemu-img sub-command executes regardless of invalid global options: $ qemu-img --foo info test.img qemu-img: unrecognized option '--foo' image: test.img ... The unrecognized option warning may be missed by the user. This can hide incorrect command-lines in scripts and confuse users. This patch prints the help information and terminates instead of executing the sub-command. Signed-off-by: Stefan Hajnoczi --- qemu-img.c | 1 + 1 file changed, 1 insertion(+) diff --git a/qemu-img.c b/qemu-img.c index 98b836b..ce293a4 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4339,6 +4339,7 @@ int main(int argc, char **argv) while ((c =3D getopt_long(argc, argv, "+hVT:", long_options, NULL)) != =3D -1) { switch (c) { case 'h': + case '?': help(); return 0; case 'V': --=20 2.9.3 From nobody Mon May 6 12:44:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148974763553110.922679336860256; Fri, 17 Mar 2017 03:47:15 -0700 (PDT) Received: from localhost ([::1]:48165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1copPe-0000vd-4Q for importer@patchew.org; Fri, 17 Mar 2017 06:47:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1copOW-0000tq-1P for qemu-devel@nongnu.org; Fri, 17 Mar 2017 06:46:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1copOU-0000MU-PS for qemu-devel@nongnu.org; Fri, 17 Mar 2017 06:46:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47928) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1copOR-0000Kn-4S; Fri, 17 Mar 2017 06:45:59 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 213B980480; Fri, 17 Mar 2017 10:45:59 +0000 (UTC) Received: from localhost (ovpn-116-23.ams2.redhat.com [10.36.116.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80C6518981; Fri, 17 Mar 2017 10:45:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 213B980480 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=stefanha@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 213B980480 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 18:45:40 +0800 Message-Id: <20170317104541.28979-3-stefanha@redhat.com> In-Reply-To: <20170317104541.28979-1-stefanha@redhat.com> References: <20170317104541.28979-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 17 Mar 2017 10:45:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/3] qemu-img: fix switch indentation in img_amend() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" QEMU coding style indents 'case' to the same level as the 'switch' statement: switch (foo) { case 1: Fix this coding style violation so checkpatch.pl doesn't complain about the next patch. Signed-off-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- qemu-img.c | 82 +++++++++++++++++++++++++++++++---------------------------= ---- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index ce293a4..c7ffabb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3500,47 +3500,47 @@ static int img_amend(int argc, char **argv) } =20 switch (c) { - case 'h': - case '?': - help(); - break; - case 'o': - if (!is_valid_option_list(optarg)) { - error_report("Invalid option list: %s", optarg); - ret =3D -1; - goto out_no_progress; - } - if (!options) { - options =3D g_strdup(optarg); - } else { - char *old_options =3D options; - options =3D g_strdup_printf("%s,%s", options, optarg); - g_free(old_options); - } - break; - case 'f': - fmt =3D optarg; - break; - case 't': - cache =3D optarg; - break; - case 'p': - progress =3D true; - break; - case 'q': - quiet =3D true; - break; - case OPTION_OBJECT: - opts =3D qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!opts) { - ret =3D -1; - goto out_no_progress; - } - break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; + case 'h': + case '?': + help(); + break; + case 'o': + if (!is_valid_option_list(optarg)) { + error_report("Invalid option list: %s", optarg); + ret =3D -1; + goto out_no_progress; + } + if (!options) { + options =3D g_strdup(optarg); + } else { + char *old_options =3D options; + options =3D g_strdup_printf("%s,%s", options, optarg); + g_free(old_options); + } + break; + case 'f': + fmt =3D optarg; + break; + case 't': + cache =3D optarg; + break; + case 'p': + progress =3D true; + break; + case 'q': + quiet =3D true; + break; + case OPTION_OBJECT: + opts =3D qemu_opts_parse_noisily(&qemu_object_opts, + optarg, true); + if (!opts) { + ret =3D -1; + goto out_no_progress; + } + break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; } } =20 --=20 2.9.3 From nobody Mon May 6 12:44:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489747769014512.1864806208876; Fri, 17 Mar 2017 03:49:29 -0700 (PDT) Received: from localhost ([::1]:48173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1copRn-0003C8-L3 for importer@patchew.org; Fri, 17 Mar 2017 06:49:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1copOd-0000zU-8C for qemu-devel@nongnu.org; Fri, 17 Mar 2017 06:46:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1copOZ-0000T8-6e for qemu-devel@nongnu.org; Fri, 17 Mar 2017 06:46:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55530) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1copOV-0000MS-CH; Fri, 17 Mar 2017 06:46:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54FACC0528CF; Fri, 17 Mar 2017 10:46:03 +0000 (UTC) Received: from localhost (ovpn-116-23.ams2.redhat.com [10.36.116.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 595B65C6C9; Fri, 17 Mar 2017 10:46:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 54FACC0528CF Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=stefanha@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 54FACC0528CF From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 18:45:41 +0800 Message-Id: <20170317104541.28979-4-stefanha@redhat.com> In-Reply-To: <20170317104541.28979-1-stefanha@redhat.com> References: <20170317104541.28979-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 17 Mar 2017 10:46:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/3] qemu-img: print short help on getopt failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Printing the full help output obscures the error message for an invalid command-line option or missing argument. Before this patch: $ ./qemu-img --foo ...pages of output... After this patch: $ ./qemu-img --foo qemu-img: unrecognized option '--foo' Try 'qemu-img --help' for more information This patch adds the getopt ':' character so that it can distinguish between missing arguments and unrecognized options. This helps provide more detailed error messages. Suggested-by: Max Reitz Signed-off-by: Stefan Hajnoczi Reviewed-by: Max Reitz --- qemu-img.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++-------= ---- 1 file changed, 97 insertions(+), 20 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index c7ffabb..b220cf7 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -88,6 +88,16 @@ static void QEMU_NORETURN GCC_FMT_ATTR(1, 2) error_exit(= const char *fmt, ...) exit(EXIT_FAILURE); } =20 +static void QEMU_NORETURN missing_argument(const char *option) +{ + error_exit("missing argument for option '%s'", option); +} + +static void QEMU_NORETURN unrecognized_option(const char *option) +{ + error_exit("unrecognized option '%s'", option); +} + /* Please keep in synch with qemu-img.texi */ static void QEMU_NORETURN help(void) { @@ -406,13 +416,18 @@ static int img_create(int argc, char **argv) {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "F:b:f:he6o:q", + c =3D getopt_long(argc, argv, ":F:b:f:he6o:q", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -651,13 +666,18 @@ static int img_check(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:r:T:q", + c =3D getopt_long(argc, argv, ":hf:r:T:q", long_options, &option_index); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -855,13 +875,18 @@ static int img_commit(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:ht:b:dpq", + c =3D getopt_long(argc, argv, ":f:ht:b:dpq", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -1190,13 +1215,18 @@ static int img_compare(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:F:T:pqs", + c =3D getopt_long(argc, argv, ":hf:F:T:pqs", long_options, NULL); if (c =3D=3D -1) { break; } switch (c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -1926,13 +1956,18 @@ static int img_convert(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:O:B:ce6o:s:l:S:pt:T:qnm:W", + c =3D getopt_long(argc, argv, ":hf:O:B:ce6o:s:l:S:pt:T:qnm:W", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -2502,13 +2537,18 @@ static int img_info(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:h", + c =3D getopt_long(argc, argv, ":f:h", long_options, &option_index); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -2713,13 +2753,18 @@ static int img_map(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:h", + c =3D getopt_long(argc, argv, ":f:h", long_options, &option_index); if (c =3D=3D -1) { break; } switch (c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -2835,13 +2880,18 @@ static int img_snapshot(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "la:c:d:hq", + c =3D getopt_long(argc, argv, ":la:c:d:hq", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); return 0; @@ -2988,13 +3038,18 @@ static int img_rebase(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:F:b:upt:T:q", + c =3D getopt_long(argc, argv, ":hf:F:b:upt:T:q", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); return 0; @@ -3355,13 +3410,18 @@ static int img_resize(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:hq", + c =3D getopt_long(argc, argv, ":f:hq", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -3493,15 +3553,20 @@ static int img_amend(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "ho:f:t:pq", + c =3D getopt_long(argc, argv, ":ho:f:t:pq", long_options, NULL); if (c =3D=3D -1) { break; } =20 switch (c) { - case 'h': + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; + case 'h': help(); break; case 'o': @@ -3759,14 +3824,19 @@ static int img_bench(int argc, char **argv) {"no-drain", no_argument, 0, OPTION_NO_DRAIN}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hc:d:f:no:qs:S:t:w", long_options, = NULL); + c =3D getopt_long(argc, argv, ":hc:d:f:no:qs:S:t:w", long_options,= NULL); if (c =3D=3D -1) { break; } =20 switch (c) { - case 'h': + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; + case 'h': help(); break; case 'c': @@ -4093,7 +4163,7 @@ static int img_dd(int argc, char **argv) { 0, 0, 0, 0 } }; =20 - while ((c =3D getopt_long(argc, argv, "hf:O:", long_options, NULL))) { + while ((c =3D getopt_long(argc, argv, ":hf:O:", long_options, NULL))) { if (c =3D=3D EOF) { break; } @@ -4104,10 +4174,12 @@ static int img_dd(int argc, char **argv) case 'f': fmt =3D optarg; break; + case ':': + missing_argument(argv[optind - 1]); + break; case '?': - error_report("Try 'qemu-img --help' for more information."); - ret =3D -1; - goto out; + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -4336,10 +4408,15 @@ int main(int argc, char **argv) qemu_add_opts(&qemu_source_opts); qemu_add_opts(&qemu_trace_opts); =20 - while ((c =3D getopt_long(argc, argv, "+hVT:", long_options, NULL)) != =3D -1) { + while ((c =3D getopt_long(argc, argv, "+:hVT:", long_options, NULL)) != =3D -1) { switch (c) { - case 'h': + case ':': + missing_argument(argv[optind - 1]); + return 0; case '?': + unrecognized_option(argv[optind - 1]); + return 0; + case 'h': help(); return 0; case 'V': --=20 2.9.3