Skip to contentSkip to conversation

eal: turn off getopt_long error messages

PATCH In review Keith Wiles 3 participants 4 messages Dec 16, 2018 – Jun 9, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal: turn off getopt_long error messages

When using dpdk register option api when parsing for log level the opterr flags was still set to one causing an error message from getopt_long(). Set opterr to zero to disable error messages.

---
 lib/librte_eal/bsdapp/eal/eal.c   | 1 +
 lib/librte_eal/linuxapp/eal/eal.c | 1 +
 2 files changed, 2 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +1 -0
index b8152a75c..85d6dddc9 100644
@@ -374,6 +374,7 @@ eal_log_level_parse(int argc, char **argv)
 	argvopt = argv;
 	optind = 1;
 	optreset = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
lib/librte_eal/linuxapp/eal/eal.c +1 -0
index 361744d40..9a1289532 100644
@@ -565,6 +565,7 @@ eal_log_level_parse(int argc, char **argv)
 
 	argvopt = argv;
 	optind = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
Signature · 1 line
2.17.1
#1 lore raw

16/12/2018 17:45, Keith Wiles:

Quoted 3 lines

When using dpdk register option api when parsing for log level the opterr flags was still set to one causing an error message from getopt_long(). Set opterr to zero to disable error messages.

Please could you be more specific?
Which function call? Which error message?

We need also Fixes: and stable tags for backport.
Thanks

#2 lore raw

Keith, it seems you missed my questions below:

19/12/2018 21:35, Thomas Monjalon:

Quoted 10 lines

16/12/2018 17:45, Keith Wiles:

Quoted 3 lines

When using dpdk register option api when parsing for log level the opterr flags was still set to one causing an error message from getopt_long(). Set opterr to zero to disable error messages.

Please could you be more specific?
Which function call? Which error message?

We need also Fixes: and stable tags for backport.
Thanks

#3 lore raw

PATCH v2 1/1 eal: turn off getopt_long error message during eal_log_level

In reply to Keith Wiles

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 supressing printing error message on first pass.

---
 lib/eal/freebsd/eal.c | 2 ++
 lib/eal/linux/eal.c   | 2 ++
 lib/eal/windows/eal.c | 3 +++
 3 files changed, 7 insertions(+)
lib/eal/freebsd/eal.c +2 -0
index 78ffb45c5987..51e65181282f 100644
@@ -380,6 +380,7 @@ eal_log_level_parse(int argc, char **argv)
 	argvopt = argv;
 	optind = 1;
 	optreset = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
@@ -423,6 +424,7 @@ eal_parse_args(int argc, char **argv)
 	argvopt = argv;
 	optind = 1;
 	optreset = 1;
+	opterr = 1;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
lib/eal/linux/eal.c +2 -0
index 99b0a597061d..72b62c181238 100644
@@ -561,6 +561,7 @@ eal_log_level_parse(int argc, char **argv)
 
 	argvopt = argv;
 	optind = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
@@ -638,6 +639,7 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 	optind = 1;
+	opterr = 1;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
lib/eal/windows/eal.c +3 -0
index de44d7d67a08..d3745caa8b65 100644
@@ -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) {
Signature · 1 line
2.39.2