From 55b28c00f9afc68b9a62f5e4ddd1df328c2a55b6 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 26 Aug 2018 15:54:33 +0200 Subject: [PATCH] sar: Fix timestamp format in report output 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 --- sar.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sar.c b/sar.c index b387887..49566da 100644 --- 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) { -- 2.40.0