|
From: | Bruno Haible |
Subject: | Re: boot time on Linux |
Date: | Wed, 09 Aug 2023 22:59:10 +0200 |
I wrote: > So, all approaches that compute the boot time through a subtraction are > going to be wrong in these scenarios. > > The better approach is really to read the boot time from a time stamp — > inside a file such as /var/run/utmp or /var/log/wtmp, or attached to > a file such as > /var/lib/systemd/random-seed (first file touched during boot) > /var/log/boot.log (one of the last files touched during boot). > > And on Alpine Linux, while /var/run/utmp is empty, its time stamp is > essentially the boot time. With the attached patches, the boot time returned by read_utmp() is stable across 'sudo date MMDDhhmm' invocations. On Linux distros, I found these files to be touched after boot: /var/lib/systemd/random-seed (seen on distros with systemd, e.g. CentOS 7, Fedora 27, Debian 9, Ubuntu 17.10, Arch 19.11, Manjaro 17) /var/run/utmp (seen on distros with OpenRC, e.g. Alpine Linux) /var/lib/random-seed (seen on OpenSUSE 12.1, CentOS 5) And, while at it, also on OpenBSD. It touches /var/db/host.random and /var/run/utmp. Bruno 2023-08-09 Bruno Haible <bruno@clisp.org> readutmp: Return a boot time also on OpenBSD. * lib/readutmp.h (BOOT_TIME, USER_PROCESS): Provide fallback definitions. * lib/readutmp.c (read_utmp_from_file) [__OpenBSD__]: Fake a BOOT_TIME entry by looking at the time stamp of a specific file. readutmp: Return a boot time also on Alpine Linux. * lib/readutmp.c: Include stat-time.h. (SIZEOF): New macro. (read_utmp_from_file) [__linux__]: Fake a BOOT_TIME entry by looking at the time stamp of a specific file. * modules/readutmp (Depends-on): Add stat-time. readutmp: Fix boot time in VMs after sleep state and date update. * lib/readutmp.c (read_utmp_from_file): New function, extracted from read_utmp. (get_boot_time_uncached): Before all other approaches, try to find the boot time in the /var/run/utmp file. (read_utmp): Invoke read_utmp_from_file. readutmp: Make it easier to filter for/against the boot-time entry. * lib/readutmp.h (READ_UTMP_BOOT_TIME, READ_UTMP_NO_BOOT_TIME): New enum items. * lib/readutmp.c (desirable_utmp_entry, read_utmp_from_systemd): Implement them. (read_utmp): If no entries can match the given options, return immediately.
0001-readutmp-Make-it-easier-to-filter-for-against-the-bo.patch
Description: Text Data
0002-readutmp-Fix-boot-time-in-VMs-after-sleep-state-and-.patch
Description: Text Data
0003-readutmp-Return-a-boot-time-also-on-Alpine-Linux.patch
Description: Text Data
0004-readutmp-Return-a-boot-time-also-on-OpenBSD.patch
Description: Text Data
[Prev in Thread] | Current Thread | [Next in Thread] |