[dpdk-dev] examples: optind should be reset to one not zero
Checks
Commit Message
Signed-off-by: Keith Wiles <keith.wiles@intel.com>
---
app/test-pipeline/config.c | 2 +-
examples/distributor/main.c | 2 +-
examples/dpdk_qat/main.c | 2 +-
examples/ip_fragmentation/main.c | 2 +-
examples/ip_pipeline/config_parse.c | 4 ++--
examples/ip_reassembly/main.c | 2 +-
examples/ipsec-secgw/ipsec-secgw.c | 2 +-
examples/ipv4_multicast/main.c | 2 +-
examples/l2fwd-cat/cat.c | 2 +-
examples/l2fwd-crypto/main.c | 2 +-
examples/l2fwd-jobstats/main.c | 2 +-
examples/l2fwd-keepalive/main.c | 2 +-
examples/l2fwd/main.c | 2 +-
examples/l3fwd-acl/main.c | 2 +-
examples/l3fwd-power/main.c | 2 +-
examples/l3fwd-vf/main.c | 2 +-
examples/l3fwd/main.c | 2 +-
examples/link_status_interrupt/main.c | 2 +-
examples/load_balancer/config.c | 2 +-
examples/multi_process/l2fwd_fork/main.c | 2 +-
examples/multi_process/symmetric_mp/main.c | 2 +-
examples/packet_ordering/main.c | 2 +-
examples/performance-thread/l3fwd-thread/main.c | 2 +-
examples/ptpclient/ptpclient.c | 2 +-
examples/qos_meter/main.c | 2 +-
25 files changed, 26 insertions(+), 26 deletions(-)
Comments
2017-02-14 16:09, Keith Wiles:
> Signed-off-by: Keith Wiles <keith.wiles@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.
Thanks
> On Mar 9, 2017, at 2:41 PM, Thomas Monjalon <thomas.monjalon@6wind.com> wrote:
>
> 2017-02-14 16:09, Keith Wiles:
>> Signed-off-by: Keith Wiles <keith.wiles@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
2017-03-09 21:11, Wiles, Keith:
>
> > On Mar 9, 2017, at 2:41 PM, Thomas Monjalon <thomas.monjalon@6wind.com> wrote:
> >
> > 2017-02-14 16:09, Keith Wiles:
> >> Signed-off-by: Keith Wiles <keith.wiles@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.
Applied with this explanation integrated, thanks.
@@ -259,6 +259,6 @@ app_parse_args(int argc, char **argv)
argv[optind - 1] = prgname;
ret = optind - 1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -487,7 +487,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return 0;
}
@@ -582,7 +582,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -586,7 +586,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -1,4 +1,4 @@
-/*-
+/*-
* BSD LICENSE
*
* Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
@@ -3407,7 +3407,7 @@ app_config_args(struct app_params *app, int argc, char **argv)
app_print_usage(argv[0]);
}
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
/* Check dependencies between args */
if (preproc_params_present && (preproc_present == 0))
@@ -718,7 +718,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -1039,7 +1039,7 @@ parse_args(int32_t argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -575,7 +575,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -686,7 +686,7 @@ parse_args(int argc, char **argv)
exit:
/* reset getopt lib */
- optind = 0;
+ optind = 1;
/* Restore opterr value */
opterr = oldopterr;
@@ -1450,7 +1450,7 @@ l2fwd_crypto_parse_args(struct l2fwd_crypto_options *options,
argv[optind-1] = prgname;
retval = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return retval;
}
@@ -709,7 +709,7 @@ l2fwd_parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -464,7 +464,7 @@ l2fwd_parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -475,7 +475,7 @@ l2fwd_parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -1776,7 +1776,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -1361,7 +1361,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -816,7 +816,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -688,7 +688,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -451,7 +451,7 @@ lsi_parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -758,7 +758,7 @@ app_parse_args(int argc, char **argv)
argv[optind - 1] = prgname;
ret = optind - 1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -865,7 +865,7 @@ l2fwd_parse_args(int argc, char **argv)
return -1;
}
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -193,7 +193,7 @@ smp_parse_args(int argc, char **argv)
ports[num_ports++] = (uint8_t)i;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -216,7 +216,7 @@ parse_args(int argc, char **argv)
}
argv[optind-1] = prgname;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return 0;
}
@@ -3052,7 +3052,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return ret;
}
@@ -708,7 +708,7 @@ ptp_parse_args(int argc, char **argv)
argv[optind-1] = prgname;
- optind = 0; /* Reset getopt lib. */
+ optind = 1; /* Reset getopt lib. */
return 0;
}
@@ -300,7 +300,7 @@ parse_args(int argc, char **argv)
argv[optind-1] = prgname;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
return 0;
}