diff options
-rw-r--r-- | include/osmocom/bsc/lchan_fsm.h | 9 | ||||
-rw-r--r-- | src/osmo-bsc/lchan_fsm.c | 25 | ||||
-rw-r--r-- | src/osmo-bsc/lchan_rtp_fsm.c | 2 |
3 files changed, 12 insertions, 24 deletions
diff --git a/include/osmocom/bsc/lchan_fsm.h b/include/osmocom/bsc/lchan_fsm.h index ded7f5481..2d5307a23 100644 --- a/include/osmocom/bsc/lchan_fsm.h +++ b/include/osmocom/bsc/lchan_fsm.h @@ -12,6 +12,13 @@ LOGP(DRSL, level, "%s (not initialized) " fmt, gsm_lchan_name(lchan), ## args); \ } while(0) +#define LCHAN_SET_LAST_ERROR(LCHAN, fmt, args...) do { \ + if ((LCHAN)->last_error) \ + talloc_free((LCHAN)->last_error); \ + (LCHAN)->last_error = talloc_asprintf((LCHAN)->ts->trx, fmt, ##args); \ + LOG_LCHAN(LCHAN, LOGL_ERROR, "%s\n", (LCHAN)->last_error); \ + } while(0) + enum lchan_fsm_state { LCHAN_ST_UNUSED, LCHAN_ST_CBCH, /*< Blocked by CBCH channel combination, not usable as SDCCH. */ @@ -74,6 +81,4 @@ bool lchan_may_receive_data(struct gsm_lchan *lchan); void lchan_forget_conn(struct gsm_lchan *lchan); -void lchan_set_last_error(struct gsm_lchan *lchan, const char *fmt, ...); - void lchan_fsm_skip_error(struct gsm_lchan *lchan); diff --git a/src/osmo-bsc/lchan_fsm.c b/src/osmo-bsc/lchan_fsm.c index 4eb95ff05..94f7821fd 100644 --- a/src/osmo-bsc/lchan_fsm.c +++ b/src/osmo-bsc/lchan_fsm.c @@ -66,25 +66,6 @@ bool lchan_may_receive_data(struct gsm_lchan *lchan) } } -void lchan_set_last_error(struct gsm_lchan *lchan, const char *fmt, ...) -{ - va_list ap; - /* This dance allows using an existing error reason in above fmt */ - char *last_error_was = lchan->last_error; - lchan->last_error = NULL; - - if (fmt) { - va_start(ap, fmt); - lchan->last_error = talloc_vasprintf(lchan->ts->trx, fmt, ap); - va_end(ap); - - LOG_LCHAN(lchan, LOGL_ERROR, "%s\n", lchan->last_error); - } - - if (last_error_was) - talloc_free(last_error_was); -} - /* The idea here is that we must not require to change any lchan state in order to deny a request. */ #define lchan_on_activation_failure(lchan, for_conn, activ_for) \ _lchan_on_activation_failure(lchan, for_conn, activ_for, \ @@ -240,7 +221,7 @@ struct osmo_tdef_state_timeout lchan_fsm_timeouts[32] = { const uint32_t state_chg = STATE_CHG; \ LOG_LCHAN(_lchan, LOGL_DEBUG, "Handling failure, will then transition to state %s\n", \ osmo_fsm_state_name(fsm, state_chg)); \ - lchan_set_last_error(_lchan, "lchan %s in state %s: " fmt, \ + LCHAN_SET_LAST_ERROR(_lchan, "lchan %s in state %s: " fmt, \ _lchan->activate.concluded ? "failure" : "allocation failed", \ osmo_fsm_state_name(fsm, state_was), ## args); \ lchan_on_activation_failure(_lchan, _lchan->activate.info.activ_for, _lchan->conn); \ @@ -547,7 +528,9 @@ static void lchan_fsm_unused(struct osmo_fsm_inst *fi, uint32_t event, void *dat OSMO_ASSERT(info); OSMO_ASSERT(!lchan->conn); OSMO_ASSERT(!lchan->mgw_endpoint_ci_bts); - lchan_set_last_error(lchan, NULL); + if (lchan->last_error) + talloc_free(lchan->last_error); + lchan->last_error = NULL; lchan->release.requested = false; lchan->activate.info = *info; diff --git a/src/osmo-bsc/lchan_rtp_fsm.c b/src/osmo-bsc/lchan_rtp_fsm.c index cd195d021..8991acccd 100644 --- a/src/osmo-bsc/lchan_rtp_fsm.c +++ b/src/osmo-bsc/lchan_rtp_fsm.c @@ -63,7 +63,7 @@ struct osmo_tdef_state_timeout lchan_rtp_fsm_timeouts[32] = { #define lchan_rtp_fail(fmt, args...) do { \ struct gsm_lchan *_lchan = fi->priv; \ uint32_t state_was = fi->state; \ - lchan_set_last_error(_lchan, "lchan-rtp failure in state %s: " fmt, \ + LCHAN_SET_LAST_ERROR(_lchan, "lchan-rtp failure in state %s: " fmt, \ osmo_fsm_state_name(fi->fsm, state_was), ## args); \ osmo_fsm_inst_dispatch(_lchan->fi, LCHAN_EV_RTP_ERROR, 0); \ } while(0) |