summaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2011-08-05 12:22:35 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-09-11 15:20:55 +0200
commit5e95f45af0e96c9f79d053de55a1cbd689496883 (patch)
tree16d1ea7f246c1e4cc3a48dde22e5f15ce38c0101 /openbsc
parent5ff06af6f560b9e906d6c320325ae84f3602f397 (diff)
ctrl: Improve error handling if controlif setup fails
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/include/openbsc/osmo_bsc.h2
-rw-r--r--openbsc/src/libctrl/control_if.c28
-rw-r--r--openbsc/src/osmo-bsc/osmo_bsc_ctrl.c16
-rw-r--r--openbsc/src/osmo-bsc/osmo_bsc_main.c10
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat.c11
-rw-r--r--openbsc/src/osmo-nitb/bsc_hack.c5
6 files changed, 53 insertions, 19 deletions
diff --git a/openbsc/include/openbsc/osmo_bsc.h b/openbsc/include/openbsc/osmo_bsc.h
index e3a79035b..ffa0b5747 100644
--- a/openbsc/include/openbsc/osmo_bsc.h
+++ b/openbsc/include/openbsc/osmo_bsc.h
@@ -41,6 +41,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 350e8e1ca..8842d3c2f 100644
--- a/openbsc/src/libctrl/control_if.c
+++ b/openbsc/src/libctrl/control_if.c
@@ -642,23 +642,27 @@ 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);
- vector_free(ctrl_node_vec);
- ctrl_node_vec = NULL;
- return NULL;
- }
+ if (ret < 0)
+ goto err_vec;
- 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_vec;
+ ret = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_counter);
+ if (ret)
+ goto err_vec;
return ctrl;
+err_vec:
+ vector_free(ctrl_node_vec);
+ ctrl_node_vec = NULL;
+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 1a24a2431..6bab46111 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c
@@ -304,9 +304,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 0f70ceb36..bba6bc0e6 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_main.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c
@@ -213,8 +213,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->bsc_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 ca6d9ee1f..d99a8dd46 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c
@@ -1770,7 +1770,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 b528a660b..7427ead96 100644
--- a/openbsc/src/osmo-nitb/bsc_hack.c
+++ b/openbsc/src/osmo-nitb/bsc_hack.c
@@ -269,6 +269,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));