[MERGED] libosmocore[master]: ensure that osmo_fsm vty commands are only installed once

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Feb 23 11:11:15 UTC 2018

Harald Welte has submitted this change and it was merged.

Change subject: ensure that osmo_fsm vty commands are only installed once

ensure that osmo_fsm vty commands are only installed once

There is a desire to install osmo_fsm vty commands automatically in
a library context, rather than requiring every application which
directly or indirectly uses osmo_fsm to run osmo_fsm_vty_add_cmd().

However, the function install_element_ve() asserts that elements
about to be installed have not already been installed.

This means we cannot shift responsibility into a library context
without first making sure that osmo_fsm commands are only installed
once per combined application+library context, because applications
won't know which commands any of its libraries has already installed.

A simple solution is to use a global flag which is checked by
osmo_fsm_vty_add_cmd() before installing osmo_fsm commands, and
is set once the commands have been installed. This way, no harm
is done if osmo_fsm_vty_add_cmd() is called multiple times.

Change-Id: I10b0b1c1c1bf44c3b8eafc465c1ee06ea2590682
Related: OS#2967
M src/vty/fsm_vty.c
1 file changed, 12 insertions(+), 0 deletions(-)

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

diff --git a/src/vty/fsm_vty.c b/src/vty/fsm_vty.c
index 8abb9c9..2947678 100644
--- a/src/vty/fsm_vty.c
+++ b/src/vty/fsm_vty.c
@@ -181,8 +181,20 @@
  *  application if you want to support those commands. */
 void osmo_fsm_vty_add_cmds(void)
+	static bool osmo_fsm_vty_cmds_installed;
+	/* Make sure FSM commands get installed only once.
+	 * We might be called from libraries or from an application.
+	 * An application might be oblivious to the fact that one or
+	 * more of its libaries are using osmo_fsm. And likewise,
+	 * any given library will not know if another library has
+	 * already installled these commands. */
+	if (osmo_fsm_vty_cmds_installed)
+		return;
+	osmo_fsm_vty_cmds_installed = true;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I10b0b1c1c1bf44c3b8eafc465c1ee06ea2590682
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Stefan Sperling <ssperling at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Stefan Sperling <ssperling at sysmocom.de>

More information about the gerrit-log mailing list