From eb7547c74287151842ac1b018a44c0e8d531c7c4 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Tue, 7 Nov 2017 10:41:53 +0000 Subject: [PATCH] output: json nan values need quoting Signed-off-by: Sami Kerola --- src/output.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/output.c b/src/output.c index 9a65144..4fd5fff 100644 --- a/src/output.c +++ b/src/output.c @@ -540,14 +540,23 @@ static int output_json(const int print_mac_addreses) fprintf(outfile, "\"used\":%g, ", shared_p->used); fprintf(outfile, "\"touched\":%g, ", shared_p->touched); fprintf(outfile, "\"free\":%g, ", shared_p->available - shared_p->used); - fprintf(outfile, "\"percent\":%g, ", oh.percent); - fprintf(outfile, "\"touch_count\":%g, ", oh.tc); - fprintf(outfile, "\"touch_percent\":%g, ", oh.tcp); - if (config.backups_found == 1) { - fprintf(outfile, "\"backup_count\":%g, ", shared_p->backups); - fprintf(outfile, "\"backup_percent\":%g, ", oh.bup); - } - fprintf(outfile, "\"status\":%d ", oh.status); + if (shared_p->available == 0) + fprintf(outfile, "\"percent\":\"%g\", ", oh.percent); + else + fprintf(outfile, "\"percent\":%g, ", oh.percent); + fprintf(outfile, "\"touch_count\":%g, ", oh.tc); + if (shared_p->available == 0) + fprintf(outfile, "\"touch_percent\":\"%g\", ", oh.tcp); + else + fprintf(outfile, "\"touch_percent\":%g, ", oh.tcp); + if (config.backups_found == 1) { + fprintf(outfile, "\"backup_count\":%g, ", shared_p->backups); + if (shared_p->available == 0) + fprintf(outfile, "\"backup_percent\":\"%g\", ", oh.bup); + else + fprintf(outfile, "\"backup_percent\":%g, ", oh.bup); + } + fprintf(outfile, "\"status\":%d ", oh.status); if (i + 1 < num_shared_networks) fprintf(outfile, "},\n"); else