Testing the current 'readutmp' module on systems with various init systems
  - sysvinit, openrc, runit     (via Devuan)
  - GNU shepherd                (via GNU GuixSD)
  - dinit, s6                   (via Artix Linux)
I see that the returned boot time is wrong on 'runit' and on 's6'.

In both cases, /var/run/utmp has some entries, but no boot time.
But unlike in Alpine Linux, where the file was empty, here it is
modified after boot. Therefore it's time stamp is not an indicator
of the boot time.

Which files are touched during the boot process?

* On Devuan 5 with 'runit':
  /var/log/fsck/checkfs
  /var/lib/urandom/random-seed
  /var/log/dmesg
  /var/log/boot

* On Artix Linux with 's6':
  /var/log/bluetoothd/current
  /var/lib/random-seed

With the patch below, things are fixed on both of these platforms.


2023-08-20  Bruno Haible  <[email protected]>

        readutmp, boot-time: Fix the result on runit and s6 init systems.
        * lib/boot-time-aux.h (get_linux_boot_time_fallback): Try also
        /var/lib/urandom/random-seed. Try /var/run/utmp last.

diff --git a/lib/boot-time-aux.h b/lib/boot-time-aux.h
index e59a0fd03c..e88e7a1e19 100644
--- a/lib/boot-time-aux.h
+++ b/lib/boot-time-aux.h
@@ -86,15 +86,21 @@ get_linux_uptime (struct timespec *p_uptime)
 static int
 get_linux_boot_time_fallback (struct timespec *p_boot_time)
 {
-  /* On Alpine Linux, UTMP_FILE is not filled.  It is always empty.
-     So, get the time stamp of a file that gets touched only during the
-     boot process.  */
+  /* On Devuan with the 'runit' init system and on Artix with the 's6' init
+     system, UTMP_FILE contains USER_PROCESS and other entries, but no
+     BOOT_TIME entry.
+     On Alpine Linux, UTMP_FILE is not filled.  It is always empty.
+     So, in both cases, get the time stamp of a file that gets touched only
+     during the boot process.  */
 
   const char * const boot_touched_files[] =
     {
       "/var/lib/systemd/random-seed", /* seen on distros with systemd */
-      "/var/run/utmp",                /* seen on distros with OpenRC */
-      "/var/lib/random-seed"          /* seen on older distros */
+      "/var/lib/urandom/random-seed", /* seen on Devuan with runit */
+      "/var/lib/random-seed",         /* seen on Artix with s6 */
+      /* This must come last, since on several distros /var/run/utmp is
+         modified when a user logs in, i.e. long after boot.  */
+      "/var/run/utmp"                 /* seen on Alpine Linux with OpenRC */
     };
   for (idx_t i = 0; i < SIZEOF (boot_touched_files); i++)
     {




Reply via email to