[MERGED] libosmocore[master]: fsm: Update the name as well if the id is updated and accept...

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.org
Mon Mar 19 20:28:19 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: fsm: Update the name as well if the id is updated and accept NULL
......................................................................


fsm: Update the name as well if the id is updated and accept NULL

If the name stays the same the log messages will still log with the old
id. Since we can now change the id we need to update the name as well.

NULL as id was allowed before so we should allow that as well.

Change-Id: I6b01eb10b8a05fee3e4a5cdefdcf3ce9f79545b4
---
M src/fsm.c
M tests/fsm/fsm_test.c
2 files changed, 26 insertions(+), 14 deletions(-)

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



diff --git a/src/fsm.c b/src/fsm.c
index 342542f..c5256da 100644
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -214,9 +214,30 @@
 		}
 		osmo_talloc_replace_string(fi, (char **)&fi->id, id);
 
+		if (fi->name)
+			talloc_free((void*)fi->name);
+
+		if (!fsm_log_addr) {
+			fi->name = talloc_asprintf(fi, "%s(%s)", fi->fsm->name, id);
+		} else {
+			fi->name = talloc_asprintf(fi, "%s(%s)[%p]", fi->fsm->name, id, fi);
+		}
+
 		return 0;
 	}
-	return -EINVAL;
+
+	if (fi->id)
+		talloc_free((void*)fi->id);
+	fi->id = NULL;
+	if (fi->name)
+		talloc_free((void*)fi->name);
+
+	if (!fsm_log_addr) {
+		fi->name = talloc_asprintf(fi, "%s", fi->fsm->name);
+	} else {
+		fi->name = talloc_asprintf(fi, "%s[%p]", fi->fsm->name, fi);
+	}
+	return 0;
 }
 
 /*! allocate a new instance of a specified FSM
@@ -242,19 +263,6 @@
 				talloc_free(fi);
 				return NULL;
 		}
-	}
-
-	if (!fsm_log_addr) {
-		if (id)
-			fi->name = talloc_asprintf(fi, "%s(%s)", fsm->name, id);
-		else
-			fi->name = talloc_asprintf(fi, "%s", fsm->name);
-	} else {
-		if (id)
-			fi->name = talloc_asprintf(fi, "%s(%s)[%p]", fsm->name,
-						   id, fi);
-		else
-			fi->name = talloc_asprintf(fi, "%s[%p]", fsm->name, fi);
 	}
 
 	INIT_LLIST_HEAD(&fi->proc.children);
diff --git a/tests/fsm/fsm_test.c b/tests/fsm/fsm_test.c
index f70b0b5..d7b08ae 100644
--- a/tests/fsm/fsm_test.c
+++ b/tests/fsm/fsm_test.c
@@ -196,6 +196,10 @@
 	finst = foo();
 	OSMO_ASSERT(osmo_fsm_inst_find_by_id(&fsm, "my_id") == finst);
 	OSMO_ASSERT(osmo_fsm_inst_find_by_name(&fsm, "Test_FSM(my_id)") == finst);
+	OSMO_ASSERT(osmo_fsm_inst_update_id(finst, "another_id") == 0);
+	OSMO_ASSERT(osmo_fsm_inst_find_by_id(&fsm, "another_id") == finst);
+	OSMO_ASSERT(osmo_fsm_inst_find_by_name(&fsm, "Test_FSM(another_id)") == finst);
+	OSMO_ASSERT(osmo_fsm_inst_update_id(finst, "my_id") == 0);
 
 	while (1) {
 		osmo_select_main(0);

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6b01eb10b8a05fee3e4a5cdefdcf3ce9f79545b4
Gerrit-PatchSet: 5
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>



More information about the gerrit-log mailing list