* [Qemu-devel] [PATCH] qemu-img resize: Fix option parsing
@ 2011-04-29 9:06 Kevin Wolf
2011-05-03 11:22 ` Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: Kevin Wolf @ 2011-04-29 9:06 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf
For shrinking images, you're supposed to use a negative size. However, the
leading minus makes getopt think that it's an option and so you get the help
text if you don't use -- like in 'qemu-img resize test.img -- -1G'.
This patch handles the size first and removes it from the argument list so that
getopt won't even try to interpret it and you don't need -- any more.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qemu-img.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index ed5ba91..e825123 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1442,6 +1442,16 @@ static int img_resize(int argc, char **argv)
{ NULL }
};
+ /* Remove size from argv manually so that negative numbers are not treated
+ * as options by getopt. */
+ if (argc < 3) {
+ help();
+ return 1;
+ }
+
+ size = argv[--argc];
+
+ /* Parse getopt arguments */
fmt = NULL;
for(;;) {
c = getopt(argc, argv, "f:h");
@@ -1458,11 +1468,10 @@ static int img_resize(int argc, char **argv)
break;
}
}
- if (optind + 1 >= argc) {
+ if (optind >= argc) {
help();
}
filename = argv[optind++];
- size = argv[optind++];
/* Choose grow, shrink, or absolute resize mode */
switch (size[0]) {
--
1.7.2.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-img resize: Fix option parsing
2011-04-29 9:06 [Qemu-devel] [PATCH] qemu-img resize: Fix option parsing Kevin Wolf
@ 2011-05-03 11:22 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2011-05-03 11:22 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel
On Fri, Apr 29, 2011 at 10:06 AM, Kevin Wolf <kwolf@redhat.com> wrote:
> For shrinking images, you're supposed to use a negative size. However, the
> leading minus makes getopt think that it's an option and so you get the help
> text if you don't use -- like in 'qemu-img resize test.img -- -1G'.
>
> This patch handles the size first and removes it from the argument list so that
> getopt won't even try to interpret it and you don't need -- any more.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> qemu-img.c | 13 +++++++++++--
> 1 files changed, 11 insertions(+), 2 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-05-03 11:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-29 9:06 [Qemu-devel] [PATCH] qemu-img resize: Fix option parsing Kevin Wolf
2011-05-03 11:22 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).