From 218c4de84f6d94a882e3a945332f53732bf2e134 Mon Sep 17 00:00:00 2001 From: Stefan Sperling Date: Thu, 22 Feb 2018 18:16:29 +0100 Subject: 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 --- src/vty/fsm_vty.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/vty/fsm_vty.c b/src/vty/fsm_vty.c index 8abb9c92..2947678b 100644 --- a/src/vty/fsm_vty.c +++ b/src/vty/fsm_vty.c @@ -181,8 +181,20 @@ DEFUN(show_fsm_inst, show_fsm_inst_cmd, * 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; + install_element_ve(&show_fsm_cmd); install_element_ve(&show_fsms_cmd); install_element_ve(&show_fsm_inst_cmd); install_element_ve(&show_fsm_insts_cmd); + osmo_fsm_vty_cmds_installed = true; } -- cgit v1.2.3