diff options
author | Daniel Willmann <daniel@totalueberwachung.de> | 2011-08-05 12:22:35 +0200 |
---|---|---|
committer | Daniel Willmann <daniel@totalueberwachung.de> | 2011-08-22 19:27:49 +0200 |
commit | 40f917f3a6dc7d801192b9c8d8cb849fe54923ef (patch) | |
tree | 4d40927acd34f6f4e28465add793a6bb77b88c07 /openbsc | |
parent | 5c5bfc4e3cdf98101ac6cf1094649bebee01fcac (diff) |
libctrl: Improve error handling if controlif setup fails
Diffstat (limited to 'openbsc')
-rw-r--r-- | openbsc/include/openbsc/osmo_bsc.h | 2 | ||||
-rw-r--r-- | openbsc/src/libctrl/control_if.c | 23 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc/osmo_bsc_ctrl.c | 16 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc/osmo_bsc_main.c | 10 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc_nat/bsc_nat.c | 11 | ||||
-rw-r--r-- | openbsc/src/osmo-nitb/bsc_hack.c | 5 |
6 files changed, 50 insertions, 17 deletions
diff --git a/openbsc/include/openbsc/osmo_bsc.h b/openbsc/include/openbsc/osmo_bsc.h index 94a2ad460..d267bcee0 100644 --- a/openbsc/include/openbsc/osmo_bsc.h +++ b/openbsc/include/openbsc/osmo_bsc.h @@ -39,6 +39,6 @@ int bsc_scan_msc_msg(struct gsm_subscriber_connection *conn, struct msgb *msg); int bsc_handle_udt(struct gsm_network *net, struct bsc_msc_connection *conn, struct msgb *msg, unsigned int length); int bsc_handle_dt1(struct osmo_bsc_sccp_con *conn, struct msgb *msg, unsigned int len); -void bsc_ctrl_cmds_install(); +int bsc_ctrl_cmds_install(); #endif diff --git a/openbsc/src/libctrl/control_if.c b/openbsc/src/libctrl/control_if.c index 0115b3a26..46869d3e9 100644 --- a/openbsc/src/libctrl/control_if.c +++ b/openbsc/src/libctrl/control_if.c @@ -641,21 +641,24 @@ struct ctrl_handle *controlif_setup(struct gsm_network *gsmnet, uint16_t port) ctrl->gsmnet = gsmnet; ctrl_node_vec = vector_init(5); - if (!ctrl_node_vec) { - talloc_free(ctrl); - return NULL; - } + if (!ctrl_node_vec) + goto err; /* Listen for control connections */ ret = make_sock(&ctrl->listen_fd, IPPROTO_TCP, INADDR_LOOPBACK, port, 0, listen_fd_cb, ctrl); - if (ret < 0) { - talloc_free(ctrl); - return NULL; - } + if (ret < 0) + goto err; - ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_rate_ctr); - ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_counter); + ret = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_rate_ctr); + if (ret) + goto err; + ret = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_counter); + if (ret) + goto err; return ctrl; +err: + talloc_free(ctrl); + return NULL; } diff --git a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c index b1e63fc28..9d03d4040 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c @@ -297,9 +297,17 @@ static int verify_net_rf_lock(struct ctrl_cmd *cmd, const char *value, void *dat return 0; } -void bsc_ctrl_cmds_install() +int bsc_ctrl_cmds_install() { - ctrl_cmd_install(CTRL_NODE_NET, &cmd_net_loc); - ctrl_cmd_install(CTRL_NODE_NET, &cmd_net_rf_lock); - ctrl_cmd_install(CTRL_NODE_TRX, &cmd_trx_rf_lock); + int rc; + + rc = ctrl_cmd_install(CTRL_NODE_NET, &cmd_net_loc); + if (rc) + goto end; + rc = ctrl_cmd_install(CTRL_NODE_NET, &cmd_net_rf_lock); + if (rc) + goto end; + rc = ctrl_cmd_install(CTRL_NODE_TRX, &cmd_trx_rf_lock); +end: + return rc; } diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c index 9690b9f28..dbcc705e4 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_main.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c @@ -208,8 +208,16 @@ int main(int argc, char **argv) bsc_api_init(bsc_gsmnet, osmo_bsc_api()); bsc_gsmnet->ctrl = controlif_setup(bsc_gsmnet, 4249); + if (!bsc_gsmnet) { + fprintf(stderr, "Failed to init the control interface. Exiting.\n"); + exit(1); + } - bsc_ctrl_cmds_install(); + rc = bsc_ctrl_cmds_install(); + if (rc < 0) { + fprintf(stderr, "Failed to install control commands. Exiting.\n"); + exit(1); + } data = bsc_gsmnet->msc_data; if (rf_ctrl) diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c index 60d421724..25ab1a91b 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c @@ -1763,7 +1763,16 @@ int main(int argc, char **argv) } nat->ctrl = controlif_setup(NULL, 4250); - ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_fwd_cmd); + if (!nat->ctrl) { + fprintf(stderr, "Failed to initialize the control interface. Exiting.\n"); + exit(1); + } + + rc = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_fwd_cmd); + if (rc) { + fprintf(stderr, "Failed to install the control command. Exiting.\n"); + exit(1); + } nat->msc_con->connection_loss = msc_connection_was_lost; nat->msc_con->connected = msc_connection_connected; diff --git a/openbsc/src/osmo-nitb/bsc_hack.c b/openbsc/src/osmo-nitb/bsc_hack.c index 724e97344..7135455ab 100644 --- a/openbsc/src/osmo-nitb/bsc_hack.c +++ b/openbsc/src/osmo-nitb/bsc_hack.c @@ -251,6 +251,11 @@ int main(int argc, char **argv) bsc_api_init(bsc_gsmnet, msc_bsc_api()); bsc_gsmnet->ctrl = controlif_setup(bsc_gsmnet, 4249); + if (!bsc_gsmnet->ctrl) { + printf("Failed to initialize control interface. Exiting.\n"); + return -1; + } + /* seed the PRNG */ srand(time(NULL)); |