Module: kamailio Branch: master Commit: 934a5dd1347c7b54a2d5e4437e1d3ab581f90596 URL: https://github.com/kamailio/kamailio/commit/934a5dd1347c7b54a2d5e4437e1d3ab5...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2023-12-27T09:24:33+01:00
xhttp_prom: renamed global ctx variable
- avoid short name code scanner warning and shadowing with function parameter
---
Modified: src/modules/xhttp_prom/xhttp_prom.c
---
Diff: https://github.com/kamailio/kamailio/commit/934a5dd1347c7b54a2d5e4437e1d3ab5... Patch: https://github.com/kamailio/kamailio/commit/934a5dd1347c7b54a2d5e4437e1d3ab5...
---
diff --git a/src/modules/xhttp_prom/xhttp_prom.c b/src/modules/xhttp_prom/xhttp_prom.c index 198fea7d09d..ee5a5520f3c 100644 --- a/src/modules/xhttp_prom/xhttp_prom.c +++ b/src/modules/xhttp_prom/xhttp_prom.c @@ -114,7 +114,7 @@ int prom_histogram_param(modparam_t type, void *val); * being currently processed. * @sa prom_ctx */ -static prom_ctx_t ctx; +static prom_ctx_t _prom_ctx;
static xhttp_api_t xhttp_api;
@@ -251,6 +251,8 @@ static int mod_init(void) if(buf_size == 0) buf_size = pkg_mem_size / 3;
+ memset(&_prom_ctx, 0, sizeof(prom_ctx_t)); + /* Initialize Prometheus metrics. */ if(prom_metric_init()) { LM_ERR("Cannot initialize Prometheus metrics\n"); @@ -441,22 +443,22 @@ static int ki_xhttp_prom_dispatch(sip_msg_t *msg) }
/* Init xhttp_prom context */ - if(ctx.reply.buf.s) { - LM_ERR("Unexpected buf value [%p][%d]\n", ctx.reply.buf.s, - ctx.reply.buf.len); + if(_prom_ctx.reply.buf.s) { + LM_ERR("Unexpected buf value [%p][%d]\n", _prom_ctx.reply.buf.s, + _prom_ctx.reply.buf.len);
/* Something happened and this memory was not freed. */ - xhttp_prom_reply_free(&ctx); + xhttp_prom_reply_free(&_prom_ctx); } - memset(&ctx, 0, sizeof(prom_ctx_t)); - ctx.msg = msg; - if(init_xhttp_prom_reply(&ctx) < 0) { + memset(&_prom_ctx, 0, sizeof(prom_ctx_t)); + _prom_ctx.msg = msg; + if(init_xhttp_prom_reply(&_prom_ctx) < 0) { goto send_reply; }
send_reply: - if(!ctx.reply_sent) { - ret = prom_send(&ctx); + if(!_prom_ctx.reply_sent) { + ret = prom_send(&_prom_ctx); } if(ret < 0) { return -1; @@ -2317,18 +2319,18 @@ static void rpc_prom_histogram_observe(rpc_t *rpc, void *ct) static void rpc_prom_metric_list_print(rpc_t *rpc, void *ct) { /* We reuse ctx->reply for the occasion. */ - if(init_xhttp_prom_reply(&ctx) < 0) { + if(init_xhttp_prom_reply(&_prom_ctx) < 0) { goto clean; }
- if(prom_metric_list_print(&ctx)) { + if(prom_metric_list_print(&_prom_ctx)) { LM_ERR("Cannot print a list of metrics\n"); goto clean; }
/* Convert to zero terminated string. */ struct xhttp_prom_reply *reply; - reply = &(ctx.reply); + reply = &(_prom_ctx.reply); reply->body.s[reply->body.len] = '\0';
/* Print content of reply buffer. */ @@ -2339,7 +2341,7 @@ static void rpc_prom_metric_list_print(rpc_t *rpc, void *ct)
clean:
- xhttp_prom_reply_free(&ctx); + xhttp_prom_reply_free(&_prom_ctx);
return; }