I wrote: > It works well enough, that I'm adding it to Gnulib, through the attached > patch.
A small tweak, to make it respect the 'options' parameter and to make it more future-proof: 2023-08-10 Bruno Haible <[email protected]> readutmp: Tweak the Android specific addition. * lib/readutmp.c (read_utmp_from_file) [__ANDROID__]: Don't fake a BOOT_TIME entry if the options request to omit it or if a BOOT_TIME entry is already present. diff --git -w a/lib/readutmp.c b/lib/readutmp.c index e383531474..eabd3e7678 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -526,6 +526,20 @@ read_utmp_from_file (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf, to system files. Therefore use the kernel's uptime counter, although it produces wrong values after the date has been bumped in the running system. */ + if ((options & (READ_UTMP_USER_PROCESS | READ_UTMP_NO_BOOT_TIME)) == 0 + && strcmp (file, UTMP_FILE) == 0) + { + bool have_boot_time = false; + for (idx_t i = 0; i < a.filled; i++) + { + struct gl_utmp *ut = &a.utmp[i]; + if (UT_TYPE_BOOT_TIME (ut)) + { + have_boot_time = true; + break; + } + } + if (!have_boot_time) { struct timespec uptime; if (get_linux_uptime (&uptime) >= 0) @@ -550,6 +564,7 @@ read_utmp_from_file (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf, } } } + } # endif # else /* old FreeBSD, OpenBSD, HP-UX */
