diff options
author | Stefan Sperling <ssperling@sysmocom.de> | 2018-02-22 18:16:29 +0100 |
---|---|---|
committer | Stefan Sperling <ssperling@sysmocom.de> | 2018-02-23 11:55:54 +0100 |
commit | 218c4de84f6d94a882e3a945332f53732bf2e134 (patch) | |
tree | 73ffa7542944cc9836149583baab14d8aae80920 /src | |
parent | 92decf2aa916353564a9dabe6871ab00e0f06a80 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/vty/fsm_vty.c | 12 |
1 files changed, 12 insertions, 0 deletions
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; } |