Max has submitted this change and it was merged.

Change subject: ctrl: log incorrect interval values
......................................................................


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
---
M src/ctrl/control_if.c
1 file changed, 7 insertions(+), 4 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c
index 665239a..590f74d 100644
--- a/src/ctrl/control_if.c
+++ b/src/ctrl/control_if.c
@@ -483,10 +483,13 @@
        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 @@
                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 @@
 
        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;
 

-- 
To view, visit https://gerrit.osmocom.org/5025
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I544001d3072e5f12a96a67e4178f9b945c5f6b6c
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <[email protected]>

Reply via email to