From b214af5360439ebd36f5ae3439acacdaf3055433 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 24 Nov 2017 13:51:57 +0100 Subject: ctrl: log incorrect interval values This should never happen with the current code, but if it ever does, we should log the error instead of silently returning 0. Change-Id: I544001d3072e5f12a96a67e4178f9b945c5f6b6c Related: OS#2550 --- src/ctrl/control_if.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/ctrl/control_if.c') diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c index 665239a2..590f74d0 100644 --- a/src/ctrl/control_if.c +++ b/src/ctrl/control_if.c @@ -483,10 +483,13 @@ static int listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what) return ret; } -static uint64_t get_rate_ctr_value(const struct rate_ctr *ctr, int intv) +static uint64_t get_rate_ctr_value(const struct rate_ctr *ctr, int intv, const char *grp) { - if (intv >= RATE_CTR_INTV_NUM) + if (intv >= RATE_CTR_INTV_NUM) { + LOGP(DLCTRL, LOGL_ERROR, "Unexpected interval value %d while trying to get rate counter value in %s\n", + intv, grp); return 0; + } /* Absolute value */ if (intv == -1) { @@ -507,7 +510,7 @@ static char *get_all_rate_ctr_in_group(void *ctx, const struct rate_ctr_group *c counters = talloc_asprintf_append(counters, "\n%s.%u.%s %"PRIu64, ctrg->desc->group_name_prefix, ctrg->idx, ctrg->desc->ctr_desc[i].name, - get_rate_ctr_value(&ctrg->ctr[i], intv)); + get_rate_ctr_value(&ctrg->ctr[i], intv, ctrg->desc->group_name_prefix)); if (!counters) return NULL; } @@ -630,7 +633,7 @@ static int get_rate_ctr(struct ctrl_cmd *cmd, void *data) talloc_free(dup); - cmd->reply = talloc_asprintf(cmd, "%"PRIu64, get_rate_ctr_value(ctr, intv)); + cmd->reply = talloc_asprintf(cmd, "%"PRIu64, get_rate_ctr_value(ctr, intv, ctrg->desc->group_name_prefix)); if (!cmd->reply) goto oom; -- cgit v1.2.3