From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: Re: [PATCH] examples: optind should be reset to one not zero Date: Fri, 10 Mar 2017 15:41:05 +0100 Message-ID: <5516131.2JN5YXhbWQ@xps13> References: <20170214220941.1178-1-keith.wiles@intel.com> <74455339.85cqDTeWke@xps13> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Cc: dev@dpdk.org To: "Wiles, Keith" Return-path: Received: from mail-wr0-f171.google.com (mail-wr0-f171.google.com [209.85.128.171]) by dpdk.org (Postfix) with ESMTP id C15A136E for ; Fri, 10 Mar 2017 15:41:06 +0100 (CET) Received: by mail-wr0-f171.google.com with SMTP id l37so66244726wrc.1 for ; Fri, 10 Mar 2017 06:41:06 -0800 (PST) In-Reply-To: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 2017-03-09 21:11, Wiles, Keith: >=20 > > On Mar 9, 2017, at 2:41 PM, Thomas Monjalon wrote: > >=20 > > 2017-02-14 16:09, Keith Wiles: > >> Signed-off-by: Keith Wiles > >=20 > > Please, could explain and describe what was the consequence of this= > > wrong reset value? > > You can just reply and I will integrate it in the commit when apply= ing. >=20 > Here is the man page text: >=20 > "The variable optind is the index of the next element to be processed= in argv. The system initializes this value to 1. > The caller can reset it to 1 to restart scanning of the same argv, or= when scanning a new argument vector.=E2=80=9D >=20 > The problem I saw with my application was trying to parse the wrong o= ption, which can happen as DPDK parses the first part of the command li= ne and the application parses the second part. If you call getopt() mul= tiple times in the same execution, the behavior is not maintained when = using zero for optind. >=20 >=20 > =E2=80=94 Do not put the next part in the commit message unless you w= ant =E2=80=94=20 > As a side note it appears MacOS is much more picky about trying to us= e optind of zero and not one. I would get a segfault on DPDK running in= MacOS and I assumed Linux/FreeBSD could be fixing optind internally, b= ut it is best to set the correct value in all cases. >=20 > I hope that helps. Applied with this explanation integrated, thanks.