[MERGED] libosmocore[master]: vty: OSMO_ASSERT() if two identical commands are installed

Harald Welte gerrit-no-reply at lists.osmocom.org
Sat Jan 7 12:14:48 UTC 2017

Harald Welte has submitted this change and it was merged.

Change subject: vty: OSMO_ASSERT() if two identical commands are installed

vty: OSMO_ASSERT() if two identical commands are installed

When the caller installs two identical commands at a given VTY node, the
result is that neither of the two commands can ever be executed: The VTY
would always complain about "Ambiguous command.".  Let's fail fast at
program start when two identical commands are intalled.

Change-Id: I85ff4640ebb3d8b75a6a9ab5d2f668edb5b7189e
M src/vty/command.c
1 file changed, 19 insertions(+), 0 deletions(-)

  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified

diff --git a/src/vty/command.c b/src/vty/command.c
index 9d8bf31..587bd62 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -594,6 +594,22 @@
 	return 0;
+/* \brief Check if a command with given string exists at given node */
+static int check_element_exists(struct cmd_node *cnode, const char *cmdstring)
+	int i;
+	for (i = 0; i < vector_active(cnode->cmd_vector); ++i) {
+		struct cmd_element *elem;
+		elem = vector_slot(cnode->cmd_vector, i);
+		if (!elem->string)
+			continue;
+		if (!strcmp(elem->string, cmdstring))
+			return 1;
+	}
+	return 0;
 /*! \brief Install a command into a node
  *  \param[in] ntype Node Type
  *  \param[cmd] element to be installed
@@ -605,6 +621,9 @@
 	cnode = vector_slot(cmdvec, ntype);
+	/* ensure no _identical_ command has been registered at this
+	 * node so far */
+	OSMO_ASSERT(!check_element_exists(cnode, cmd->string));
 	vector_set(cnode->cmd_vector, cmd);

To view, visit https://gerrit.osmocom.org/1539
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I85ff4640ebb3d8b75a6a9ab5d2f668edb5b7189e
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder

More information about the gerrit-log mailing list