diff options
author | Max <msuraev@sysmocom.de> | 2017-03-07 17:43:35 +0100 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2017-03-14 08:59:19 +0000 |
commit | 6f5e398ccb10c0095061d9adf39f0ebcebd0c876 (patch) | |
tree | 93c0220ffa1903abf68defb898b3b5b5328a6aa6 | |
parent | a1b891aab4a250ef12ed6c1cd2a331a272b4d65c (diff) |
Handle ctrl cmd allocation failures
Check that ctrl command was successfully allocated before using it.
Fixes: CID163884
Change-Id: Id19e1ce5fae6f936c9ed93f9a6317b57d28d7311
-rw-r--r-- | src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c index 2a15d2ec..f01fd14d 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c @@ -190,22 +190,14 @@ static void sysmobts_mgr_temp_handle(struct sysmobts_mgr_instance *manager, struct ctrl_connection *ctrl, int critical, int warning) { - int new_state = next_state(manager->state, critical, warning), rc; + int new_state = next_state(manager->state, critical, warning); struct ctrl_cmd *rep; - bool send = false; + char *oml_alert = NULL; /* Nothing changed */ if (new_state < 0) return; - rep = ctrl_cmd_create(tall_mgr_ctx, CTRL_TYPE_SET); - if (!rep) { - LOGP(DTEMP, LOGL_ERROR, "OML alert creation failed.\n"); - } else { - rep->id = talloc_asprintf(rep, "%d", rand()); - rep->variable = "oml-alert"; - } - LOGP(DTEMP, LOGL_NOTICE, "Moving from state %s to %s.\n", get_value_string(state_names, manager->state), get_value_string(state_names, new_state)); @@ -219,22 +211,31 @@ static void sysmobts_mgr_temp_handle(struct sysmobts_mgr_instance *manager, break; case STATE_WARNING: execute_warning_act(manager); - rep->value = "Temperature Warning"; - send = true; + oml_alert = "Temperature Warning"; break; case STATE_CRITICAL: execute_critical_act(manager); - rep->value = "Temperature Critical"; - send = true; + oml_alert = "Temperature Critical"; break; }; - if (send) { - rc = ctrl_cmd_send(&ctrl->write_queue, rep); - LOGP(DTEMP, LOGL_ERROR, "OML alert sent: %d\n", rc); + if (!oml_alert) + return; + + rep = ctrl_cmd_create(tall_mgr_ctx, CTRL_TYPE_SET); + if (!rep) { + LOGP(DTEMP, LOGL_ERROR, "OML alert creation failed for %s.\n", + oml_alert); + return; } + + rep->id = talloc_asprintf(rep, "%d", rand()); + rep->variable = "oml-alert"; + rep->value = oml_alert; + LOGP(DTEMP, LOGL_ERROR, "OML alert sent: %d\n", + ctrl_cmd_send(&ctrl->write_queue, rep)); talloc_free(rep); -} +} static void temp_ctrl_check(struct ctrl_connection *ctrl) { |