From 7fb70440cff73c57a2b3a53f22a6ff023718ea39 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 20 Jun 2018 08:38:38 +0800 Subject: 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 Cc: Hugo Mills Fixes: 010ceab56e06 ("btrfs-progs: rework option parser to use getopt for global options") Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- cmds-replace.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cmds-replace.c') diff --git a/cmds-replace.c b/cmds-replace.c index 032a44fc..1fa80284 100644 --- a/cmds-replace.c +++ b/cmds-replace.c @@ -134,6 +134,7 @@ static int cmd_replace_start(int argc, char **argv) u64 srcdev_size; u64 dstdev_size; + optind = 0; while ((c = getopt(argc, argv, "Brf")) != -1) { switch (c) { case 'B': @@ -333,6 +334,7 @@ static int cmd_replace_status(int argc, char **argv) int ret; DIR *dirstream = NULL; + optind = 0; while ((c = getopt(argc, argv, "1")) != -1) { switch (c) { case '1': @@ -501,6 +503,7 @@ static int cmd_replace_cancel(int argc, char **argv) char *path; DIR *dirstream = NULL; + optind = 0; while ((c = getopt(argc, argv, "")) != -1) { switch (c) { case '?': -- cgit v1.2.3