This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/1540 Add osmo_fsm_find_by_name() and avoid registering FSM with same name This addresses a FIXME in the fsm.c code: osmo_fsm_register() should fail in case a FSM with the given name already exists. Change-Id: I5fd882939859c79581eba70c14cbafd64560b583 --- M include/osmocom/core/fsm.h M src/fsm.c 2 files changed, 14 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/40/1540/1 diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h index a2c20b7..952f82f 100644 --- a/include/osmocom/core/fsm.h +++ b/include/osmocom/core/fsm.h @@ -140,6 +140,7 @@ int osmo_fsm_register(struct osmo_fsm *fsm); void osmo_fsm_unregister(struct osmo_fsm *fsm); +struct osmo_fsm *osmo_fsm_find_by_name(const char *name); struct osmo_fsm_inst *osmo_fsm_inst_alloc(struct osmo_fsm *fsm, void *ctx, void *priv, int log_level, const char *id); struct osmo_fsm_inst *osmo_fsm_inst_alloc_child(struct osmo_fsm *fsm, diff --git a/src/fsm.c b/src/fsm.c index 19705b9..666dbe3 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -20,6 +20,7 @@ #include <errno.h> #include <stdbool.h> +#include <string.h> #include <osmocom/core/fsm.h> #include <osmocom/core/talloc.h> @@ -102,6 +103,16 @@ fsm_log_addr = log_addr; } +struct osmo_fsm *osmo_fsm_find_by_name(const char *name) +{ + struct osmo_fsm *fsm; + llist_for_each_entry(fsm, &g_fsms, list) { + if (!strcmp(name, fsm->name)) + return fsm; + } + return NULL; +} + /*! \brief register a FSM with the core * * A FSM descriptor needs to be registered with the core before any @@ -112,7 +123,8 @@ */ int osmo_fsm_register(struct osmo_fsm *fsm) { - /* FIXME:check for duplicate name? */ + if (osmo_fsm_find_by_name(fsm->name)) + return -EEXIST; llist_add_tail(&fsm->list, &g_fsms); INIT_LLIST_HEAD(&fsm->instances); -- To view, visit https://gerrit.osmocom.org/1540 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5fd882939859c79581eba70c14cbafd64560b583 Gerrit-PatchSet: 1 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Harald Welte <laforge at gnumonks.org>