osmith submitted this change.

View Change

Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve laforge: Looks good to me, but someone else must approve osmith: Looks good to me, approved
Proper exit if bsc_nat_fsm fails to start

Instead of segfaulting later on, properly exit if the bsc_nat_fsm does
not start. One reason for having it fail could be a missing mgw pool
config block.

Related: SYS#5560
Change-Id: Ia8bbe6ae908d5c3ce49f71b43c950497aeebb6d6
---
M include/osmocom/bsc_nat/bsc_nat_fsm.h
M src/osmo-bsc-nat/bsc_nat_fsm.c
M src/osmo-bsc-nat/main.c
3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/include/osmocom/bsc_nat/bsc_nat_fsm.h b/include/osmocom/bsc_nat/bsc_nat_fsm.h
index a2becfb..bca97e1 100644
--- a/include/osmocom/bsc_nat/bsc_nat_fsm.h
+++ b/include/osmocom/bsc_nat/bsc_nat_fsm.h
@@ -20,5 +20,5 @@
#pragma once

void bsc_nat_fsm_alloc(struct bsc_nat *bsc_nat);
-void bsc_nat_fsm_start(struct bsc_nat *bsc_nat);
+int bsc_nat_fsm_start(struct bsc_nat *bsc_nat);
void bsc_nat_fsm_stop(struct bsc_nat *bsc_nat);
diff --git a/src/osmo-bsc-nat/bsc_nat_fsm.c b/src/osmo-bsc-nat/bsc_nat_fsm.c
index 30486ce..eae2f5e 100644
--- a/src/osmo-bsc-nat/bsc_nat_fsm.c
+++ b/src/osmo-bsc-nat/bsc_nat_fsm.c
@@ -474,9 +474,18 @@
OSMO_ASSERT(bsc_nat->fi);
}

-void bsc_nat_fsm_start(struct bsc_nat *bsc_nat)
+int bsc_nat_fsm_start(struct bsc_nat *bsc_nat)
{
- osmo_fsm_inst_dispatch(bsc_nat->fi, BSC_NAT_FSM_EV_START, NULL);
+ int rc = osmo_fsm_inst_dispatch(bsc_nat->fi, BSC_NAT_FSM_EV_START, NULL);
+ if (rc)
+ return rc;
+
+ /* st_starting_on_enter() doesn't change to STARTED if e.g. vty config
+ * is incomplete */
+ if (bsc_nat->fi->state != BSC_NAT_FSM_ST_STARTED)
+ return -1;
+
+ return 0;
}

void bsc_nat_fsm_stop(struct bsc_nat *bsc_nat)
diff --git a/src/osmo-bsc-nat/main.c b/src/osmo-bsc-nat/main.c
index 6cb1e0f..e58d687 100644
--- a/src/osmo-bsc-nat/main.c
+++ b/src/osmo-bsc-nat/main.c
@@ -198,7 +198,8 @@
main_vty_init(argc, argv);
signal_handler_init();

- bsc_nat_fsm_start(g_bsc_nat);
+ if (bsc_nat_fsm_start(g_bsc_nat) < 0)
+ exit(1);

if (msc_alloc_from_addr_book() < 0)
exit(1);

To view, visit change 27708. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-bsc-nat
Gerrit-Branch: master
Gerrit-Change-Id: Ia8bbe6ae908d5c3ce49f71b43c950497aeebb6d6
Gerrit-Change-Number: 27708
Gerrit-PatchSet: 3
Gerrit-Owner: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-MessageType: merged