summaryrefslogtreecommitdiff
path: root/cmds-inspect.c
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2018-06-20 08:38:38 +0800
committerDavid Sterba <dsterba@suse.com>2018-08-06 14:59:45 +0200
commit7fb70440cff73c57a2b3a53f22a6ff023718ea39 (patch)
treee48ad8925cf4bb7b64b73e93cca4ad7efad1a365 /cmds-inspect.c
parent8aee4b000d4fdf30cab167d5cf78b413af155098 (diff)
btrfs-progs: Fix wrong optind re-initialization to allow mixed option and non-option
In function handle_global_options(), we reset @optind to 1. However according to man page of getopt(3) NOTES section, if we need to rescan options later, @optind should be reset to 0 to initialize the internal variables correctly. This explains the reason why in cmd_check(), getopt_long() doesn't handle the following command correctly: "btrfs check /dev/data/btrfs --check-data-csum" While mkfs.btrfs handles mixed non-option and option correctly: "mkfs.btrfs -f /dev/data/disk1 --data raid1 /dev/data/disk2" Cc: Paul Jones <paul@pauljones.id.au> Cc: Hugo Mills <hugo@carfax.org.uk> Fixes: 010ceab56e06 ("btrfs-progs: rework option parser to use getopt for global options") Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-inspect.c')
-rw-r--r--cmds-inspect.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/cmds-inspect.c b/cmds-inspect.c
index afd7fe48..2fc50c1a 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -94,6 +94,7 @@ static int cmd_inspect_inode_resolve(int argc, char **argv)
int ret;
DIR *dirstream = NULL;
+ optind = 0;
while (1) {
int c = getopt(argc, argv, "v");
if (c < 0)
@@ -148,6 +149,7 @@ static int cmd_inspect_logical_resolve(int argc, char **argv)
char *path_ptr;
DIR *dirstream = NULL;
+ optind = 0;
while (1) {
int c = getopt(argc, argv, "Pvs:");
if (c < 0)
@@ -591,6 +593,7 @@ static int cmd_inspect_min_dev_size(int argc, char **argv)
DIR *dirstream = NULL;
u64 devid = 1;
+ optind = 0;
while (1) {
int c;
enum { GETOPT_VAL_DEVID = 256 };