From ccd6d5c8a66d4b24f309b50f3c77a3cb9a6289a8 Mon Sep 17 00:00:00 2001 From: Wenhua Huang Date: Thu, 11 Jul 2024 17:19:24 +0800 Subject: [PATCH] Fix boot time derivation for systems with no rtc --- ...e-derivation-for-systems-with-no-rtc.patch | 55 +++++++++++++++++++ dnf-plugins-core.spec | 9 ++- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 backport-Fix-boot-time-derivation-for-systems-with-no-rtc.patch diff --git a/backport-Fix-boot-time-derivation-for-systems-with-no-rtc.patch b/backport-Fix-boot-time-derivation-for-systems-with-no-rtc.patch new file mode 100644 index 0000000..07b599f --- /dev/null +++ b/backport-Fix-boot-time-derivation-for-systems-with-no-rtc.patch @@ -0,0 +1,55 @@ +From eb0a223c84d4a065ec7b54faa28679d88aef559d Mon Sep 17 00:00:00 2001 +From: Todd Lewis +Date: Wed, 16 Nov 2022 10:45:39 -0500 +Subject: [PATCH 1/1] Fix boot time derivation for systems with no rtc + +That addresses https://bugzilla.redhat.com/show_bug.cgi?id=2137935 +--- + plugins/needs_restarting.py | 24 +++++++++++++++++++++++- + 1 file changed, 23 insertions(+), 1 deletion(-) + +diff --git a/plugins/needs_restarting.py b/plugins/needs_restarting.py +index 91dbe66..03831fa 100644 +--- a/plugins/needs_restarting.py ++++ b/plugins/needs_restarting.py +@@ -34,6 +34,7 @@ import functools + import os + import re + import stat ++import time + + + # For which package updates we should recommend a reboot +@@ -199,7 +200,28 @@ class ProcessStart(object): + + @staticmethod + def get_boot_time(): +- return int(os.stat('/proc/1').st_mtime) ++ """ ++ We have two sources from which to derive the boot time. These values vary ++ depending on containerization, existence of a Real Time Clock, etc. ++ For our purposes we want the latest derived value. ++ - st_mtime of /proc/1 ++ Reflects the time the first process was run after booting ++ This works for all known cases except machines without ++ a RTC - they awake at the start of the epoch. ++ - /proc/uptime ++ Seconds field of /proc/uptime subtracted from the current time ++ Works for machines without RTC iff the current time is reasonably correct. ++ Does not work on containers which share their kernel with the ++ host - there the host kernel uptime is returned ++ """ ++ ++ proc_1_boot_time = int(os.stat('/proc/1').st_mtime) ++ if os.path.isfile('/proc/uptime'): ++ with open('/proc/uptime', 'rb') as f: ++ uptime = f.readline().strip().split()[0].strip() ++ proc_uptime_boot_time = int(time.time() - float(uptime)) ++ return max(proc_1_boot_time, proc_uptime_boot_time) ++ return proc_1_boot_time + + @staticmethod + def get_sc_clk_tck(): +-- +2.25.1 + diff --git a/dnf-plugins-core.spec b/dnf-plugins-core.spec index ce9e970..b71b48c 100644 --- a/dnf-plugins-core.spec +++ b/dnf-plugins-core.spec @@ -7,13 +7,14 @@ Name: dnf-plugins-core Version: 4.3.1 -Release: 4 +Release: 5 Summary: Core Plugins for DNF License: GPLv2+ URL: https://github.com/rpm-software-management/dnf-plugins-core Source0: %{url}/archive/%{version}/%{name}-%{version}.tar.gz patch6000: backport-download-plugin-respect-install_weak_deps-option-value.patch +patch6001: backport-Fix-boot-time-derivation-for-systems-with-no-rtc.patch patch9000: 9000-Replace-COPR-hub-with-openeuler.patch @@ -347,6 +348,12 @@ popd %{_mandir}/man8/dnf-local.* %changelog +* Thu Jul 11 2024 Wenhua Huang - 4.3.1-5 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:Fix boot time derivation for systems with no rtc + * Wed May 8 2024 wangyueliang - 4.3.1-4 - Type:bugfix - CVE:NA -- Gitee