From 5adec60758ccc92fa1477e42d545d4820ba4ae56 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 3 Mar 2019 17:04:26 +0100 Subject: [PATCH] iostat, mpstat: Fix JSON output when stopped by SIGINT Remove extra comma in JSON output displayed by iostat and mpstat when stopped by SIGINT. Signed-off-by: Sebastien GODARD --- iostat.c | 11 ++++------- mpstat.c | 7 +++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/iostat.c b/iostat.c index 543beaf..c916d7e 100644 --- a/iostat.c +++ b/iostat.c @@ -1900,12 +1900,6 @@ void rw_io_stat_loop(long int count, struct tm *rectime) if (count > 0) { count--; } - if (DISPLAY_JSON_OUTPUT(flags)) { - if (count) { - printf(","); - } - printf("\n"); - } } else { skip = 0; @@ -1918,9 +1912,12 @@ void rw_io_stat_loop(long int count, struct tm *rectime) if (sigint_caught) { /* SIGINT signal caught => Terminate JSON output properly */ count = 0; - printf("\n"); /* Skip "^C" displayed on screen */ + } + else if (DISPLAY_JSON_OUTPUT(flags) && count) { + printf(","); } } + printf("\n"); } while (count); diff --git a/mpstat.c b/mpstat.c index 0a10790..9e2a393 100644 --- a/mpstat.c +++ b/mpstat.c @@ -1930,17 +1930,16 @@ void rw_mpstat_loop(int dis_hdr, int rows) if (count) { - if (DISPLAY_JSON_OUTPUT(flags)) { - printf(",\n"); - } pause(); if (sigint_caught) { /* SIGINT signal caught => Display average stats */ count = 0; - printf("\n"); /* Skip "^C" displayed on screen */ } else { + if (DISPLAY_JSON_OUTPUT(flags)) { + printf(",\n"); + } curr ^= 1; } } -- 2.40.0