[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/6] qemu-img resize: Fix option parsing
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 1/6] qemu-img resize: Fix option parsing |
Date: |
Tue, 3 May 2011 13:08:21 +0200 |
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 <address@hidden>
---
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
- [Qemu-devel] [PULL 0/6] Block patches, Kevin Wolf, 2011/05/03
- [Qemu-devel] [PATCH 1/6] qemu-img resize: Fix option parsing,
Kevin Wolf <=
- [Qemu-devel] [PATCH 2/6] atapi: Move comment to proper place, Kevin Wolf, 2011/05/03
- [Qemu-devel] [PATCH 3/6] atapi: Explain why we need a 'media not present' state, Kevin Wolf, 2011/05/03
- [Qemu-devel] [PATCH 5/6] qemu-progress.c: printf isn't signal safe, Kevin Wolf, 2011/05/03
- [Qemu-devel] [PATCH 4/6] ide/atapi: fix set but unused, Kevin Wolf, 2011/05/03
- [Qemu-devel] [PATCH 6/6] NBD: Avoid leaking a couple of strings when the NBD device is closed, Kevin Wolf, 2011/05/03
- Re: [Qemu-devel] [PULL 0/6] Block patches, Anthony Liguori, 2011/05/03