]> granicus.if.org Git - sysstat/commitdiff
sar: Fix timestamp format in report output
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 26 Aug 2018 13:54:33 +0000 (15:54 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 26 Aug 2018 13:54:33 +0000 (15:54 +0200)
The contents of environment variable S_TIME_FORMAT was not taken into
account when displaying a RESTART or a COMMENT message if this message
was the first line displayed in the report by sar:

$ sar
Linux 4.17.11-200.fc28.x86_64 (xxx)  08/25/2018  _x86_64_ (8 CPU)

14:10:50     LINUX RESTART (8 CPU)

02:15:47 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
02:20:00 PM     all      6.27      0.00      2.17      3.85      0.00     87.71
...

This patch fixes the problem by testing the environment variable sooner.

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

diff --git a/sar.c b/sar.c
index b387887e5d10f3bc0b5737d185496f234448b2da..49566da3181a3884c1a6bddc8d8f433348e43f74 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -449,9 +449,6 @@ int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
                        return 0;
        }
 
-       if (!is_iso_time_fmt())
-               flags |= S_F_PREFD_TIME_OUTPUT;
-
        /* Get then set previous timestamp */
        if (sa_get_record_timestamp_struct(flags + S_F_LOCAL_TIME, &record_hdr[!curr],
                                           &rectime, NULL))
@@ -1512,6 +1509,10 @@ int main(int argc, char **argv)
        /* Default is CPU activity... */
        select_default_activity(act);
 
+       /* Check S_TIME_FORMAT variable contents */
+       if (!is_iso_time_fmt())
+               flags |= S_F_PREFD_TIME_OUTPUT;
+
        /* Reading stats from file: */
        if (from_file[0]) {
                if (interval < 0) {