On 3/13/2024 4:51 PM, David Marchand wrote: <...>
>> >> And just after while loop, there is "if (optind != argc)" check, I don't >> see when this check will be hit, so it looks useless. > But this part actually looks correct to me. > We could still hit this part with non handled trailing strings: > > $ build-mini/app/dpdk-testpmd -c 3 --no-huge -m 40 -a 0:0.0 --vdev > net_null1 --vdev net_null2 -- -i garbage > Invalid parameter: garbage > EAL: Error - exiting with code: 1 > Cause: Command line is incorrect > Port 0 is closed > Port 1 is closed > OK, I see it is to catch non-option argument and works as expected. I missed that when 'getopt_long()' returns -1 (EOF), it sets 'optind' to point first non-option argument in argv, and does this by swapping elements in argv[] (I wasn't aware 'getopt_long()' does this). Since testpmd doesn't get any non-option argument, it can be possible to prefix 'short_options' with '+', (like "+ah"), which modify 'getopt_long()' behavior to stop when first non-option argument seen. This prevents some unnecessary argument parsing, but it seems this is a GNU extension, not posix standard, so not sure does it worth this optimization.