[v1,5/8] option: check against common option on register

Message ID 64e6b0b1b696b3e99e28ab35f42b1e94e8e42582.1545325395.git.gaetan.rivet@6wind.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series Clean up rte_option |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Gaëtan Rivet Dec. 20, 2018, 5:06 p.m. UTC
  Not only check against other registered options, but also common EAL
options. This will mitigate user confusion.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/rte_option.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Patch

diff --git a/lib/librte_eal/common/rte_option.c b/lib/librte_eal/common/rte_option.c
index d94363872..ae8a0e2ca 100644
--- a/lib/librte_eal/common/rte_option.c
+++ b/lib/librte_eal/common/rte_option.c
@@ -2,6 +2,7 @@ 
  * Copyright(c) 2018 Intel Corporation.
  */
 
+#include <getopt.h>
 #include <unistd.h>
 #include <string.h>
 
@@ -9,6 +10,8 @@ 
 #include <rte_option.h>
 
 #include "eal_private.h"
+#include "eal_internal_cfg.h" /* Necessary for eal_options.h */
+#include "eal_options.h"
 
 TAILQ_HEAD(rte_option_list, rte_option);
 
@@ -39,6 +42,17 @@  void __rte_experimental
 rte_option_register(struct rte_option *opt)
 {
 	struct rte_option *option;
+	const struct option *gopt;
+
+	gopt = &eal_long_options[0];
+	while (gopt->name != NULL) {
+		if (strcmp(gopt->name, opt->name) == 0) {
+			RTE_LOG(ERR, EAL, "Option %s is already a common EAL option.\n",
+					opt->name);
+			return;
+		}
+		gopt++;
+	}
 
 	TAILQ_FOREACH(option, &rte_option_list, next) {
 		if (strcmp(opt->name, option->name) == 0) {