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

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
iostat.c
mpstat.c

index 1827ec03d9f8ab2427041e8420d77a91281cf5d9..21db950eaf86dae986e980694ffb438c99974e2c 100644 (file)
--- a/iostat.c
+++ b/iostat.c
@@ -1857,6 +1857,11 @@ int main(int argc, char **argv)
                dm_major = get_devmap_major();
        }
 
+       if (DISPLAY_JSON_OUTPUT(flags)) {
+               /* Use a decimal point to make JSON code compliant with RFC7159 */
+               setlocale(LC_NUMERIC, "C");
+       }
+
        /* Init structures according to machine architecture */
        io_sys_init();
        if (group_nr > 0) {
index 8fa3fc151343e3b60f9c6a5e067dd5683f599c99..6c38e00d8f169b4af9183b9ad632ff58c9392f28 100644 (file)
--- a/mpstat.c
+++ b/mpstat.c
@@ -1729,6 +1729,11 @@ int main(int argc, char **argv)
                interval = 0;
        }
 
+       if (DISPLAY_JSON_OUTPUT(flags)) {
+               /* Use a decimal point to make JSON code compliant with RFC7159 */
+               setlocale(LC_NUMERIC, "C");
+       }
+
        /* Get time */
        get_localtime(&(mp_tstamp[0]), 0);