[dpdk-dev] [PATCH] examples: optind should be reset to one not zero

Wiles, Keith keith.wiles at intel.com
Thu Mar 9 22:11:39 CET 2017


> On Mar 9, 2017, at 2:41 PM, Thomas Monjalon <thomas.monjalon at 6wind.com> wrote:
> 
> 2017-02-14 16:09, Keith Wiles:
>> Signed-off-by: Keith Wiles <keith.wiles at intel.com>
> 
> 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 applying.

Here is the man page text:

"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.”

The problem I saw with my application was trying to parse the wrong option, which can happen as DPDK parses the first part of the command line and the application parses the second part. If you call getopt() multiple times in the same execution, the behavior is not maintained when using zero for optind.


— Do not put the next part in the commit message unless you want — 
As a side note it appears MacOS is much more picky about trying to use 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, but it is best to set the correct value in all cases.

I hope that helps.


> Thanks
> 

Regards,
Keith



More information about the dev mailing list