On 12/08/2023 14:22, Bruno Haible wrote:
The best approaches to get the boot time access some files. For the
case of programs that execute in Docker containers on Linux, we have
the fallback that relies on the kernel's uptime counter — although it
produces wrong values in a VM that has been put to sleep and then resumed.
Similarly, it is useful to have a fallback for BSD 'jails' on *BSD systems.
There is a sysctl named KERN_BOOTTIME, that coreutils/src/uptime.c already
uses. For consistency between 'who' and 'uptime', it is good to have this
fallback in the 'readutmp' module.
This sysctl exists on macOS, FreeBSD, NetBSD, OpenBSD, GNU/kFreeBSD, Minix.
But note:
- The boot time that this sysctl reports changes after a VM has been
put to sleep, then resumed, then its 'date' changed. I've verified
this on FreeBSD, NetBSD, OpenBSD, GNU/kFreeBSD. It's probably the
same thing on macOS (but I can't test it).
- On Minix 3.3, the result of this system call is garbage. When I compile
the attached program, it produces completely different results when
invoked as
$ ./a.out
vs.
$ TZ=UTC ./a.out
I notice coreutils CI now failing with:
In file included from lib/readutmp.c:47:
/usr/include/x86_64-linux-gnu/sys/sysctl.h:21:2: error:
#warning "The <sys/sysctl.h> header is deprecated and will be removed."
[-Werror=cpp]
21 | #warning "The <sys/sysctl.h> header is deprecated and will be removed."
| ^~~~~~~
This deprecation of sysctl on glibc >= 2.30 was dealt with in coreutils before
like:
https://github.com/coreutils/coreutils/commit/18c938280
Perhaps we should avoid this fallback similarly if defined __GLIBC__ ?
thanks,
Pádraig