mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-04 11:12:02 +00:00
MINOR: stats: make show info json future-proof
This is a follow up of "BUG/MINOR: stats: fix show stat json buffer limitation" However this time this is purely preemptive as we did not reach the buffer limitation yet. But now is the proper time so that this won't be an issue in the upcoming versions. No backport needed.
This commit is contained in:
parent
42b18fb645
commit
16c9ca94ef
23
src/stats.c
23
src/stats.c
@ -661,14 +661,15 @@ static int stats_dump_json_info_fields(struct buffer *out,
|
||||
const struct field *info,
|
||||
struct show_stat_ctx *ctx)
|
||||
{
|
||||
int field;
|
||||
int started = 0;
|
||||
int started = (ctx->field) ? 1 : 0;
|
||||
int ready_data = 0;
|
||||
|
||||
if (!chunk_strcat(out, "["))
|
||||
if (!started && !chunk_strcat(out, "["))
|
||||
return 0;
|
||||
|
||||
for (field = 0; field < INF_TOTAL_FIELDS; field++) {
|
||||
for (; ctx->field < INF_TOTAL_FIELDS; ctx->field++) {
|
||||
int old_len;
|
||||
int field = ctx->field;
|
||||
|
||||
if (!field_format(info, field))
|
||||
continue;
|
||||
@ -694,16 +695,24 @@ static int stats_dump_json_info_fields(struct buffer *out,
|
||||
|
||||
if (!chunk_strcat(out, "}"))
|
||||
goto err;
|
||||
ready_data = out->data;
|
||||
}
|
||||
|
||||
if (!chunk_strcat(out, "]\n"))
|
||||
goto err;
|
||||
ctx->field = 0; /* we're done */
|
||||
return 1;
|
||||
|
||||
err:
|
||||
chunk_reset(out);
|
||||
chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}\n");
|
||||
return 0;
|
||||
if (!ready_data) {
|
||||
/* not enough buffer space for a single entry.. */
|
||||
chunk_reset(out);
|
||||
chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}\n");
|
||||
return 0; /* hard error */
|
||||
}
|
||||
/* push ready data and wait for a new buffer to complete the dump */
|
||||
out->data = ready_data;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void stats_print_proxy_field_json(struct buffer *out,
|
||||
|
Loading…
Reference in New Issue
Block a user