Return-Path: Received: from mx2.suse.de ([195.135.220.15]:34780 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753554AbeGBWYO (ORCPT ); Mon, 2 Jul 2018 18:24:14 -0400 Date: Tue, 3 Jul 2018 00:24:07 +0200 From: David Sterba To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org, dsterba@suse.cz, Paul Jones , Hugo Mills Subject: Re: [PATCH v2 1/2] btrfs-progs: Fix wrong optind re-initialization to allow mixed option and non-option Message-ID: <20180702222407.GH3126@twin.jikos.cz> Reply-To: dsterba@suse.cz References: <20180620003839.10629-1-wqu@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <20180620003839.10629-1-wqu@suse.com> Sender: linux-btrfs-owner@vger.kernel.org List-ID: On Wed, Jun 20, 2018 at 08:38:38AM +0800, Qu Wenruo wrote: > 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 > --- > changelog: > v2: > Instead of resetting @optind at handle_global_options(), reset @optind > before each later getopt() call. Since there are cases uses @optind and > expects it to be starting from 1. 1 and 2 applied, thanks.