Skip to content

Commit

Permalink
[needs-restarting] Read /proc/uptime rather than /proc/1 (RhBug:2166444)
Browse files Browse the repository at this point in the history
This problem was reported on RHEL-8 for ppc64le.  I confirmed the
reproducer does work.  It also affects RHEL-9.  Fortunately, this
problem was reported and addressed in Fedora.  I confirmed the fix
works for at least RHEL-8 on ppc64le.

The Fedora issue was reported here, along with the proposed fix:

rpm-software-management#468

Signed-off-by: David Cantrell <dcantrell@redhat.com>
  • Loading branch information
dcantrell committed Mar 27, 2023
1 parent dfbda50 commit c6fb5c8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion plugins/needs_restarting.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import os
import re
import stat
import time


# For which package updates we should recommend a reboot
Expand Down Expand Up @@ -199,7 +200,28 @@ def __init__(self):

@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():
Expand Down

0 comments on commit c6fb5c8

Please sign in to comment.