Blame SOURCES/0005-Move-the-initialization-of-boot_date-to-task_init.patch

8c35ac
From d16dc6fff0260ec26002046fae4aeb546d6b9a0e Mon Sep 17 00:00:00 2001
8c35ac
From: Lianbo Jiang <lijiang@redhat.com>
8c35ac
Date: Mon, 17 Jan 2022 15:14:00 +0800
8c35ac
Subject: [PATCH 05/10] Move the initialization of "boot_date" to task_init()
8c35ac
8c35ac
The "boot_date" is initialized conditionally in the cmd_log(), which may
8c35ac
display incorrect "boot_date" value with the following command before
8c35ac
running the "log -T" command:
8c35ac
8c35ac
crash> help -k | grep date
8c35ac
          date: Wed Dec 22 13:39:29 IST 2021
8c35ac
     boot_date: Thu Jan  1 05:30:00 IST 1970
8c35ac
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8c35ac
The calculation of "boot_date" depends on the HZ value, and the HZ will
8c35ac
be calculated in task_init() at the latest, so let's move it here.
8c35ac
8c35ac
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
8c35ac
---
8c35ac
 kernel.c | 18 +++---------------
8c35ac
 task.c   | 10 ++++++++++
8c35ac
 2 files changed, 13 insertions(+), 15 deletions(-)
8c35ac
8c35ac
diff --git a/kernel.c b/kernel.c
8c35ac
index 36c57ed501ad..094fe9b2efad 100644
8c35ac
--- a/kernel.c
8c35ac
+++ b/kernel.c
8c35ac
@@ -5025,21 +5025,9 @@ cmd_log(void)
8c35ac
         if (argerrs)
8c35ac
                 cmd_usage(pc->curcmd, SYNOPSIS);
8c35ac
 
8c35ac
-	if (msg_flags & SHOW_LOG_CTIME) {
8c35ac
-		if (pc->flags & MINIMAL_MODE) {
8c35ac
-			error(WARNING, "the option '-T' is not available in minimal mode\n");
8c35ac
-			return;
8c35ac
-		}
8c35ac
-
8c35ac
-		if (kt->boot_date.tv_sec == 0) {
8c35ac
-			ulonglong uptime_jiffies;
8c35ac
-			ulong  uptime_sec;
8c35ac
-
8c35ac
-			get_uptime(NULL, &uptime_jiffies);
8c35ac
-			uptime_sec = (uptime_jiffies)/(ulonglong)machdep->hz;
8c35ac
-			kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec;
8c35ac
-			kt->boot_date.tv_nsec = 0;
8c35ac
-		}
8c35ac
+	if (msg_flags & SHOW_LOG_CTIME && pc->flags & MINIMAL_MODE) {
8c35ac
+		error(WARNING, "the option '-T' is not available in minimal mode\n");
8c35ac
+		return;
8c35ac
 	}
8c35ac
 
8c35ac
 	if (msg_flags & SHOW_LOG_AUDIT) {
8c35ac
diff --git a/task.c b/task.c
8c35ac
index 76e184ae70b1..263a8344dd94 100644
8c35ac
--- a/task.c
8c35ac
+++ b/task.c
8c35ac
@@ -692,6 +692,16 @@ task_init(void)
8c35ac
 
8c35ac
 	stack_overflow_check_init();
8c35ac
 
8c35ac
+	if (machdep->hz) {
8c35ac
+		ulonglong uptime_jiffies;
8c35ac
+		ulong  uptime_sec;
8c35ac
+
8c35ac
+		get_uptime(NULL, &uptime_jiffies);
8c35ac
+		uptime_sec = (uptime_jiffies)/(ulonglong)machdep->hz;
8c35ac
+		kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec;
8c35ac
+		kt->boot_date.tv_nsec = 0;
8c35ac
+	}
8c35ac
+
8c35ac
 	tt->flags |= TASK_INIT_DONE;
8c35ac
 }
8c35ac
 
8c35ac
-- 
8c35ac
2.20.1
8c35ac