From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ustc.edu.cn (smtp2.ustc.edu.cn [202.38.64.46]) by dpdk.org (Postfix) with ESMTP id EEB8F5A64 for ; Wed, 14 Oct 2015 12:19:45 +0200 (CEST) Received: from dell (unknown [222.195.92.204]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygAHuQk9LB5W16WxAQ--.38558S2; Wed, 14 Oct 2015 18:19:42 +0800 (CST) Date: Wed, 14 Oct 2015 18:19:33 +0800 From: Tiwei Bie To: Bruce Richardson Message-ID: <20151014101933.GB68200@dell> References: <1444726446-8106-1-git-send-email-btw@mail.ustc.edu.cn> <1444726446-8106-2-git-send-email-btw@mail.ustc.edu.cn> <20151014022843.GA26774@dell> <20151014093128.GC32308@bricha3-MOBL3> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20151014093128.GC32308@bricha3-MOBL3> User-Agent: Mutt/1.5.24 (2015-08-30) X-CM-TRANSID: LkAmygAHuQk9LB5W16WxAQ--.38558S2 X-Coremail-Antispam: 1UD129KBjvJXoW3GrW5tFW5GrWkCrykXrW3Awb_yoW7AF1fpa 47W3W2kF4kJFW0yr4qqw1kCw1Fvw1rtFy8W3Z0y34kArnIka4vkryUtFWFgF1fCrs8AFWj yr40vay7Za1YvFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkFb7Iv0xC_tr1lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Gr0_Cr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxkIecxEwVAFwVW8twCF04k20xvY 0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I 0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAI cVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcV CF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jOa9-UUUUU= X-CM-SenderInfo: xewzqzxdloh3xvwfhvlgxou0/1tbiAQcCAVQhmEgJgQAKsi Cc: "dev@dpdk.org" , Don Provan Subject: Re: [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and optreset to 1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Oct 2015 10:19:46 -0000 On Wed, Oct 14, 2015 at 10:31:28AM +0100, Bruce Richardson wrote: > On Wed, Oct 14, 2015 at 10:28:44AM +0800, Tiwei Bie wrote: > > On Tue, Oct 13, 2015 at 05:14:38PM +0000, Don Provan wrote: > > > Actually, this is a good opportunity to fix a bug that's been in this code forever: it shouldn't be resetting optind to some arbitrary value: it should be saving optind (and optarg and optopt) at the beginning, initializing optind to 1 before calling getopt_long(), then restoring all the values after. (And, from what you're saying, optreset should be handled the same as optind.) > > > > > > > It is designed to have DPDK's parameters specified in the front of the > > cmd line and terminated by '--'. Or at least, you should put DPDK's > > parameters together and terminate them by '--'. And 1 or 0 are not some > > arbitrary values. They are used to put the index back to the beginning > > of the new argv[] array. > > > > > This avoids broken behavior if rte_eal_init() is called by code that's in the middle of using getopt() to parse its own unrelated argc/argv parameters. > > > > > > > We shouldn't mix up DPDK's parameters and application's parameters. > > And we should group them using '--'. > > > > Best, > > Tiwei Bie > > While true, that does not prevent us from implementing Don's suggestion, as it > should fix the bug you are looking at with your original patch, and also allow > additional use-cases for applications at no extra cost. > As I understand it, what Don wants is something like this: int main(int argc, char **argv) { int ret; int ch; while ((ch = getopt(argc, argv, "whateveroptions:d")) != -1) { switch (ch) { case 'd': /* rte_eal_init() will be called */ ret = dpdk_init(argc, argv); argc -= ret; argv += ret; break; case 'w': ...... } } argc -= optind; argv += optind; ...... } static int dpdk_init(int argc, char **argv) { int ret; ret = rte_eal_init(argc, argv); if (ret < 0) FATAL_ERROR("Could not initialise EAL (%d)", ret); ...... return (ret); } And the current code should work correctly if DPDK's parameters are put together and terminated by '--': $ ./demo -whatever -d -c f -n 2 -- -option -s hello The only limitation is that the return value of rte_eal_init() must be returned to the code which is using getopt() to parse argc/argv. And I'm very willing to rework my patch to get rid of this limitation. Best regards, Tiwei Bie > /Bruce > > > -----Original Message----- > > From: Tiwei Bie [mailto:btw@mail.ustc.edu.cn] > > Sent: Wednesday, October 14, 2015 6:48 AM > > To: Zhu, Heqing > > Cc: Richardson, Bruce; O'Driscoll, Tim; Ananyev, Konstantin > > Subject: Re: [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and optreset > > to 1 > > > > On Wed, Oct 14, 2015 at 05:26:17AM +0000, Zhu, Heqing wrote: > > > > > > Bruce, thank you. Tiwei will join DPDK team in 2016. :) > > > > > > @Tiwei, Bruce/Konstantin are the DPDK tech leads, both work and live in > > Ireland. > > > > > > > Cool! It's my great honor to join DPDK team! Thank you very much! :-) > > > > Best regards, > > Tiwei Bie > > > > > > > > > > > -----Original Message----- > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Bruce Richardson > > > Sent: Tuesday, October 13, 2015 10:59 PM > > > To: Tiwei Bie > > > Cc: dev@dpdk.org > > > Subject: Re: [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and > > > optreset to 1 > > > > > > On Tue, Oct 13, 2015 at 04:54:06PM +0800, Tiwei Bie wrote: > > > > The variable optind must be reinitialized to 1 in order to skip over > > > > argv[0] on FreeBSD. Because getopt() on FreeBSD will return -1 when > > > > it meets an argument which doesn't start with '-'. > > > > > > > > The variable optreset is provided on FreeBSD to indicate the > > > > additional set of calls to getopt(). So, also reinitialize it to 1. > > > > > > > > Signed-off-by: Tiwei Bie > > > > > > Acked-by: Bruce Richardson > > > > > /Bruce > > > > > > -don provan > > > dprovan@bivio.net > > > > > > -----Original Message----- > > > From: Tiwei Bie [mailto:btw@mail.ustc.edu.cn] > > > Sent: Tuesday, October 13, 2015 1:54 AM > > > To: dev@dpdk.org > > > Subject: [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and optreset to 1 > > > > > > The variable optind must be reinitialized to 1 in order to skip over argv[0] on FreeBSD. Because getopt() on FreeBSD will return -1 when it meets an argument which doesn't start with '-'. > > > > > > The variable optreset is provided on FreeBSD to indicate the additional set of calls to getopt(). So, also reinitialize it to 1. > > > > > > Signed-off-by: Tiwei Bie > > > --- > > > lib/librte_eal/bsdapp/eal/eal.c | 6 ++++-- > > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > > > diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 1b6f705..35feaee 100644 > > > --- a/lib/librte_eal/bsdapp/eal/eal.c > > > +++ b/lib/librte_eal/bsdapp/eal/eal.c > > > @@ -334,7 +334,8 @@ eal_log_level_parse(int argc, char **argv) > > > break; > > > } > > > > > > - optind = 0; /* reset getopt lib */ > > > + optind = 1; /* reset getopt lib */ > > > + optreset = 1; > > > } > > > > > > /* Parse the argument given in the command line of the application */ @@ -403,7 +404,8 @@ eal_parse_args(int argc, char **argv) > > > if (optind >= 0) > > > argv[optind-1] = prgname; > > > ret = optind-1; > > > - optind = 0; /* reset getopt lib */ > > > + optind = 1; /* reset getopt lib */ > > > + optreset = 1; > > > return ret; > > > } > > > > > > -- > > > 2.6.0 > > > > > > > > > > >