[v6,2/6] eal: turn off getopt_long error message during eal_log_level

Message ID 20230629155858.75668-3-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Logging related patches |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger June 29, 2023, 3:58 p.m. UTC
  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@intel.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/common/eal_common_log.c | 3 +++
 lib/eal/windows/eal.c           | 1 +
 2 files changed, 4 insertions(+)
  

Patch

diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c
index 7e2f010fa371..ada3ed5ebec9 100644
--- a/lib/eal/common/eal_common_log.c
+++ b/lib/eal/common/eal_common_log.c
@@ -235,6 +235,7 @@  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_optreset = optreset;
@@ -242,6 +243,7 @@  eal_log_level_parse(int argc, char *const argv[])
 #endif
 
 	optind = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argv, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
@@ -263,6 +265,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 240d5b8ad3e4..c6006c48ddef 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -108,6 +108,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) {