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
This commit is contained in:
Oliver Smith 2022-03-24 13:00:36 +01:00
parent e04bf1402d
commit ba1c49028f
3 changed files with 14 additions and 4 deletions

View File

@ -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);

View File

@ -474,9 +474,18 @@ void bsc_nat_fsm_alloc(struct bsc_nat *bsc_nat)
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)

View File

@ -198,7 +198,8 @@ int main(int argc, char **argv)
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);