]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cli/stats: add missing trailing LF after "show info json"
authorWilly Tarreau <w@1wt.eu>
Fri, 10 Jun 2022 13:12:21 +0000 (15:12 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 Jun 2022 13:12:21 +0000 (15:12 +0200)
This is the continuation of commit 5a0e7ca5d ("BUG/MINOR: cli/stats: add
missing trailing LF after JSON outputs"). There's also a "show info json"
command which was also missing the trailing LF. It's constructed exactly
like the "show stat json", in that it dumps a series of fields without any
LF. The difference however is that for the stats output, everything was
enclosed in an array which required an LF *after* the closing bracket,
while here there's no such array so we have to emit the LF after the loop.
That makes the two functions a bit inconsistent, it's quite annoying, but
making them better would require sending one LF per line in the stats
output, which is not particularly interesting.

Given that it took 5+ years to spot that this code wasn't working as
expected it doesn't seem worth investing much time trying to refactor
it to make it look cleaner at the risk of breaking other obscure parts.

src/stats.c

index f9a520a8683e59794929f2e8fa0b9bb2c9f3546d..fdbca006556a5d9d207f79164608b2aaa8c696c1 100644 (file)
@@ -691,13 +691,13 @@ static int stats_dump_json_info_fields(struct buffer *out,
                        goto err;
        }
 
-       if (!chunk_strcat(out, "]"))
+       if (!chunk_strcat(out, "]\n"))
                goto err;
        return 1;
 
 err:
        chunk_reset(out);
-       chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}");
+       chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}\n");
        return 0;
 }