]> granicus.if.org Git - sysstat/commitdiff
Fix #128: Use decimal point for FP values in JSON output
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 21 Oct 2016 12:52:04 +0000 (14:52 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 21 Oct 2016 12:52:04 +0000 (14:52 +0200)
This patch sets LC_NUMERIC variable to "C" to make sure JSON output (as
displayed by sadf -j) is locale-independent and floating-point values
use a decimal point.
This should make JSON output compliant with RFC7159.

Reported-by: @andy-maier
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sadf.c

diff --git a/sadf.c b/sadf.c
index fc7a9756bbe0b08700c6e9b9d5d9cf70795d80d6..4b05a8b17301ca6c3a442e4b4666143b852d89e9 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -949,6 +949,11 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file,
        long cnt = 1;
        off_t fpos;
 
+       if (format == F_JSON_OUTPUT) {
+               /* Use a decimal point to make JSON code compliant with RFC7159 */
+               setlocale(LC_NUMERIC, "C");
+       }
+
        /* Save current file position */
        if ((fpos = lseek(ifd, 0, SEEK_CUR)) < 0) {
                perror("lseek");