[PATCH v5 2/6] eal: turn off getopt_long error message during eal_log_level
Stephen Hemminger
stephen at networkplumber.org
Wed Jun 28 19:58:23 CEST 2023
If DPDK application is given a bogus option, the error message
would get printed twice. Once during scan for log level and
again during parsing of arguments.
Example:
# ./build/app/dpdk-testpmd --bogus
./build/app/dpdk-testpmd: unrecognized option '--bogus'
EAL: Detected CPU lcores: 16
EAL: Detected NUMA nodes: 1
./build/app/dpdk-testpmd: unrecognized option '--bogus'
Usage: ./build/app/dpdk-testpmd [options]
Fix by suppressing printing error message on first pass.
Signed-off-by: Keith Wiles <keith.wiles at intel.com>
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
lib/eal/unix/eal_log.c | 3 +++
lib/eal/windows/eal.c | 3 +++
2 files changed, 6 insertions(+)
diff --git a/lib/eal/unix/eal_log.c b/lib/eal/unix/eal_log.c
index f8a5c853f2df..3f54284494d7 100644
--- a/lib/eal/unix/eal_log.c
+++ b/lib/eal/unix/eal_log.c
@@ -64,12 +64,14 @@ eal_log_level_parse(int argc, char *const argv[])
int option_index, opt;
const int old_optind = optind;
const int old_optopt = optopt;
+ const int old_opterr = opterr;
char * const old_optarg = optarg;
#ifdef RTE_EXEC_ENV_FREEBSD
const int old_optrset = optreset;
#endif
optind = 1;
+ opterr = 0;
#ifdef RTE_EXEC_ENV_FREEBSD
optreset = 1;
#endif
@@ -94,6 +96,7 @@ eal_log_level_parse(int argc, char *const argv[])
optind = old_optind;
optopt = old_optopt;
optarg = old_optarg;
+ opterr = old_opterr;
#ifdef RTE_EXEC_ENV_FREEBSD
optreset = old_optreset;
#endif
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index 2d7a0e9ab27e..0800a9e5c2d2 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -106,6 +106,8 @@ eal_log_level_parse(int argc, char **argv)
struct internal_config *internal_conf =
eal_get_internal_configuration();
+ opterr = 0;
+
argvopt = argv;
eal_reset_internal_config(internal_conf);
@@ -143,6 +145,7 @@ eal_parse_args(int argc, char **argv)
eal_get_internal_configuration();
argvopt = argv;
+ opterr = 1;
while ((opt = getopt_long(argc, argvopt, eal_short_options,
eal_long_options, &option_index)) != EOF) {
--
2.39.2
More information about the dev
mailing list