This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Max gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/5023 ctrl: make response easier to parse Previously ctrl request for all counters in group (e. g. 'rate_ctr.abs.msc.0') will result in human-readable description which is not regular enough and is hard to both parse and generate. The ctrl interface is intended for m2m, not for human interaction. Let's simplify things by making response similar to counter group request ('rate_ctr.*'). While at it, also 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: I7a24cc307450efdcd28168fffe477320c59fcd36 Related: OS#2550 --- M src/ctrl/control_if.c 1 file changed, 17 insertions(+), 35 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/23/5023/1 diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c index 665239a..6459ce1 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) { @@ -496,42 +499,21 @@ } } -static char *get_all_rate_ctr_in_group(void *ctx, const struct rate_ctr_group *ctrg, int intv) -{ - int i; - char *counters = talloc_strdup(ctx, ""); - if (!counters) - return NULL; - - for (i=0;i<ctrg->desc->num_ctr;i++) { - 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)); - if (!counters) - return NULL; - } - return counters; -} - static int get_rate_ctr_group_idx(const struct rate_ctr_group *ctrg, int intv, struct ctrl_cmd *cmd) { - char *counters; - - counters = get_all_rate_ctr_in_group(cmd, ctrg, intv); - if (!counters) - goto oom; - - cmd->reply = talloc_asprintf(cmd, "All counters in %s.%u%s", - ctrg->desc->group_name_prefix, ctrg->idx, counters); - talloc_free(counters); - if (!cmd->reply) - goto oom; + unsigned int i; + for (i = 0; i < ctrg->desc->num_ctr; i++) { + cmd->reply = talloc_asprintf_append(cmd->reply, "%s %"PRIu64";", + ctrg->desc->ctr_desc[i].name, + get_rate_ctr_value(&ctrg->ctr[i], intv, + ctrg->desc->group_name_prefix)); + if (!cmd->reply) { + cmd->reply = "OOM"; + return CTRL_CMD_ERROR; + } + } return CTRL_CMD_REPLY; -oom: - cmd->reply = "OOM."; - return CTRL_CMD_ERROR; } static int ctrl_rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *data) @@ -630,7 +612,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/5023 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7a24cc307450efdcd28168fffe477320c59fcd36 Gerrit-PatchSet: 1 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Max <msuraev at sysmocom.de>