Subject: Re: bug#65255: uptime's boot time is inconsistent after VM sleep & resume

From: Bruno Haible <[email-masked]>
Date: Tue, 15 Aug 2023 15:03:44 +0200

I wrote:
> > I'll provide a NEWS
> > entry afterwards, that summarizes the changes in coreutils + gnulib on the
> > various platforms.
> 
Paul Eggert wrote:
> Thanks, this looks good. A NEWS entry would be welcome.

Actually, it's 4 entries:

* The 'uptime' program is now being built on FreeBSD, Haiku.
* 'who -a' now displays the boot time on Alpine Linux, OpenBSD, Cygwin,
   Haiku, and some distributions of Android.
* 'uptime' now succeeds on some distributions of Android.
* The "up" time displayed by 'uptime' now includes VM saved/sleep time on
  Linux, Hurd, GNU/kFreeBSD, NetBSD, OpenBSD, Minix, Cygwin.

Comments:
Re entry 1: Yes, the 'uptime' program was not being built on FreeBSD. A consequence
of the fact that FreeBSD has <utmpx.h> but no <utmp.h>, and of this commit:
https://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=2984e47c789ebc39f55a3b1cb20b943de88eeedc

Re entry 2, 3: Let's write "some distributions of Android" since for me it works
(under Termux, with an LG Android 11) whereas for Po Lu these two system APIs
don't work (due to SELinux policies).

Re entry 4:
The improvement comes from both
[1] https://lists.gnu.org/archive/html/coreutils/2023-08/msg00028.html
    on NetBSD, OpenBSD, Minix,
[2] https://lists.gnu.org/archive/html/bug-coreutils/2023-08/msg00068.html
    on Linux, Hurd, GNU/kFreeBSD, NetBSD, Minix, Cygwin.

Find below the detailed test results.

> Does this mean Gnulib's 'uptime' module is obsolete?

It can be marked obsolete, yes. But it should not be removed immediately,
since some other package is using it: dc3dd. See
https://codesearch.debian.net/search?q=uptime+path%3Abootstrap.conf&literal=1

Bruno

TEST RESULTS with
  + current gnulib as of today
  + current coreutils + my patches [1][2]:
--------------------------------------------------------------------------------
Fedora Rawhide Cinnamon

$ date +"%Y-%m-%d %H:%M"
2023-08-15 11:11
$ coreutils-9.3/src/who -a
           system boot  2023-08-09 21:03
           run-level 5  2023-08-09 21:03
bruno    + tty1         2023-08-09 21:03  old         1072 (:0)
           pts/3        2023-08-15 11:11            107603 id=ts/3  term=0 exit=0
$ coreutils-9.3/src/uptime
 11:11:14  up 5 days 12:57,  1 user,  load average: 0.08, 0.03, 0.00
Includes VM sleep time? no
$ coreutils-2023-08-13/src/who -a
           system boot  2023-08-09 21:03
           run-level 5  2023-08-09 21:03
bruno    + tty1         2023-08-09 21:03  old         1072 (:0)
           pts/3        2023-08-15 11:11            107603 id=ts/3  term=0 exit=0
$ coreutils-2023-08-13/src/uptime
 11:11:19  up 5 days 14:07,  1 user,  load average: 0.16, 0.04, 0.01
Includes VM sleep time? yes

--------------------------------------------------------------------------------
CentOS 6

$ date +"%Y-%m-%d %H:%M"
2023-08-15 11:18
$ coreutils-9.3/src/who -a
           system boot  2023-08-14 04:45
           run-level 5  2023-08-14 04:45
LOGIN      tty3         2023-08-14 04:45              1889 id=3
LOGIN      tty4         2023-08-14 04:45              1891 id=4
LOGIN      tty2         2023-08-14 04:45              1887 id=2
LOGIN      tty5         2023-08-14 04:45              1893 id=5
LOGIN      tty6         2023-08-14 04:45              1901 id=6
bruno    + tty1         2023-08-14 04:46  old         2072 (:0)
bruno    + pts/0        2023-08-14 04:46   .          2466 (:0.0)
$ coreutils-9.3/src/uptime
 11:18:14  up 1 day  5:26,  2 users,  load average: 0.00, 0.00, 0.00
Includes VM sleep time? no
$ coreutils-2023-08-13/src/who -a
           system boot  2023-08-14 04:45
           run-level 5  2023-08-14 04:45
LOGIN      tty3         2023-08-14 04:45              1889 id=3
LOGIN      tty4         2023-08-14 04:45              1891 id=4
LOGIN      tty2         2023-08-14 04:45              1887 id=2
LOGIN      tty5         2023-08-14 04:45              1893 id=5
LOGIN      tty6         2023-08-14 04:45              1901 id=6
bruno    + tty1         2023-08-14 04:46  old         2072 (:0)
bruno    + pts/0        2023-08-14 04:46   .          2466 (:0.0)
$ coreutils-2023-08-13/src/uptime
 11:18:19  up 1 day  6:33,  2 users,  load average: 0.00, 0.00, 0.00
Includes VM sleep time? yes

--------------------------------------------------------------------------------
Raspbian

$ date +"%Y-%m-%d %H:%M"
2023-08-15 11:21
$ coreutils-9.2/src/who -a
           system boot  1970-01-01 01:00
pi       - tty1         2023-07-09 19:16  old          445
pi       + tty7         2023-08-10 14:31  old         7911 (:0)
           run-level 5  2023-08-10 13:07
$ coreutils-9.2/src/uptime
 11:21:36  up 4 days 20:41,  2 users,  load average: 0.69, 0.20, 0.06
Includes VM sleep time? no
$ coreutils-2023-08-13/src/who -a
           system boot  2023-08-10 13:07
pi       - tty1         2023-07-09 19:16  old          445
pi       + tty7         2023-08-10 14:31  old         7911 (:0)
           run-level 5  2023-08-10 13:07
$ coreutils-2023-08-13/src/uptime
 11:21:40  up 4 days 22:13,  2 users,  load average: 0.69, 0.20, 0.06
Includes VM sleep time? yes

--------------------------------------------------------------------------------
Alpine Linux 3.18

$ date +"%Y-%m-%d %H:%M"
2023-09-13 23:32
$ coreutils-9.3/src/who -a
$ coreutils-9.3/src/uptime
 23:32:11  up 5 days  6:02,  0 users,  load average: 0.01, 0.01, 0.00
Includes VM sleep time? no
$ coreutils-2023-08-13/src/who -a
           system boot  Aug  9 16:24
$ coreutils-2023-08-13/src/uptime
 23:32:16  up 35 days  7:08,  0 users,  load average: 0.01, 0.01, 0.00
Includes VM sleep time? yes

--------------------------------------------------------------------------------
GNU/Hurd 2022

$ date +"%Y-%m-%d %H:%M"
2023-08-15 11:29
$ coreutils-9.2/src/who -a
                        Aug 15 00:06                18 id=si    term=0 exit=0
           system boot  Aug 15 00:06
           run-level 2  Aug 15 00:06                   last=S
                        Aug 15 00:06               601 id=l2    term=0 exit=0
                        Aug 15 00:06               747 id=6
                        Aug 15 00:06               746 id=5
                        Aug 15 00:06               742 id=1
                        Aug 15 00:06               744 id=3
                        Aug 15 00:06               745 id=4
                        Aug 15 00:06               743 id=2
                        Aug 15 00:06               748 id=c
login    - tty6         Aug 15 00:07 11:22         747
login    - tty4         Aug 15 00:07 11:22         745
login    - tty2         Aug 15 00:07 11:22         743
login    - tty3         Aug 15 00:07 11:22         744
bruno    - tty1         Aug 15 00:06   .           742
login    - tty5         Aug 15 00:07 11:22         746
login    - console      Aug 15 00:07 11:22         748
$ coreutils-9.2/src/uptime
 11:29:11  up  10:13,  7 users,  load average: 0.00, 0.01, 0.01
Includes VM sleep time? no
$ coreutils-2023-08-13/src/who -a
                        Aug 15 00:06                18 id=si    term=0 exit=0
           system boot  Aug 15 00:06
           run-level 2  Aug 15 00:06                   last=S
                        Aug 15 00:06               601 id=l2    term=0 exit=0
                        Aug 15 00:06               747 id=6
                        Aug 15 00:06               746 id=5
                        Aug 15 00:06               742 id=1
                        Aug 15 00:06               744 id=3
                        Aug 15 00:06               745 id=4
                        Aug 15 00:06               743 id=2
                        Aug 15 00:06               748 id=c
login    - tty6         Aug 15 00:07 11:22         747
login    - tty4         Aug 15 00:07 11:22         745
login    - tty2         Aug 15 00:07 11:22         743
login    - tty3         Aug 15 00:07 11:22         744
bruno    - tty1         Aug 15 00:06   .           742
login    - tty5         Aug 15 00:07 11:22         746
login    - console      Aug 15 00:07 11:22         748
$ coreutils-2023-08-13/src/uptime
 11:29:15  up  11:22,  7 users,  load average: 0.00, 0.01, 0.00
Includes VM sleep time? yes

--------------------------------------------------------------------------------
FreeBSD 13.2

$ date +"%Y-%m-%d %H:%M"
2023-08-15 11:34
$ coreutils-9.3/src/who -a
           system boot  2023-08-11 22:49
bruno    - ttyv0        2023-08-11 23:02   .           857
$ coreutils-9.3/src/uptime
sh: coreutils-9.3/src/uptime: not found
Includes VM sleep time? n/a
$ coreutils-2023-08-13/src/who -a
           system boot  2023-08-11 22:49
bruno    - ttyv0        2023-08-11 23:02   .           857
$ coreutils-2023-08-13/src/uptime
 11:34:23  up 3 days 12:45,  1 user,  load average: 0.48, 0.61, 0.55
Includes VM sleep time? yes

--------------------------------------------------------------------------------
GNU/kFreeBSD 7

$ date +"%Y-%m-%d %H:%M"
2023-08-15 13:37
$ coreutils-9.3/src/who -a
                        2023-08-14 05:54                17 id=si    term=0 exit=0
           system boot  2023-08-14 05:54
           run-level 2  2023-08-14 05:54                   last=S
                        2023-08-14 05:54              1554 id=l2    term=0 exit=0
LOGIN      ttyv1        2023-08-14 05:54              2168 id=2
LOGIN      ttyv2        2023-08-14 05:54              2169 id=3
LOGIN      ttyv3        2023-08-14 05:54              2170 id=4
LOGIN      ttyv4        2023-08-14 05:54              2171 id=5
LOGIN      ttyv5        2023-08-14 05:54              2172 id=6
bruno    - ttyv0        2023-08-14 05:55   .          2173
$ coreutils-9.3/src/uptime
 13:37:15  up 1 day  6:35,  1 user,  load average: 0.00, 0.00, 0.00
Includes VM sleep time? no
$ coreutils-2023-08-13/src/who -a
                        2023-08-14 05:54                17 id=si    term=0 exit=0
           system boot  2023-08-14 05:54
           run-level 2  2023-08-14 05:54                   last=S
                        2023-08-14 05:54              1554 id=l2    term=0 exit=0
LOGIN      ttyv1        2023-08-14 05:54              2168 id=2
LOGIN      ttyv2        2023-08-14 05:54              2169 id=3
LOGIN      ttyv3        2023-08-14 05:54              2170 id=4
LOGIN      ttyv4        2023-08-14 05:54              2171 id=5
LOGIN      ttyv5        2023-08-14 05:54              2172 id=6
bruno    - ttyv0        2023-08-14 05:55   .          2173
$ coreutils-2023-08-13/src/uptime
 13:37:19  up 1 day  7:42,  1 user,  load average: 0.00, 0.00, 0.00
Includes VM sleep time? yes

--------------------------------------------------------------------------------
NetBSD 9.3

$ date +"%Y-%m-%d %H:%M"
2023-08-15 11:55
$ coreutils-9.3/src/who -a
           system boot  Aug 11 22:48
           run-level    Aug 11 22:48
bruno    - constty      Aug 11 23:02   .           582
LOGIN      ttyE1        Aug 11 22:48               647 id=tyE1
LOGIN      ttyE2        Aug 11 22:48               657 id=tyE2
LOGIN      ttyE3        Aug 11 22:48               635 id=tyE3
$ coreutils-9.3/src/uptime
 11:55:13  up 3 days 10:17,  1 user,  load average: 0.00, 0.00, 0.00
Includes VM sleep time? no
$ coreutils-2023-08-13/src/who -a
           system boot  Aug 11 22:48
           run-level    Aug 11 22:48
bruno    - constty      Aug 11 23:02   .           582
LOGIN      ttyE1        Aug 11 22:48               647 id=tyE1
LOGIN      ttyE2        Aug 11 22:48               657 id=tyE2
LOGIN      ttyE3        Aug 11 22:48               635 id=tyE3
$ coreutils-2023-08-13/src/uptime
 11:55:18  up 3 days 13:06,  1 user,  load average: 0.00, 0.00, 0.00
Includes VM sleep time? yes

--------------------------------------------------------------------------------
OpenBSD 7.2

$ date +"%Y-%m-%d %H:%M"
2023-09-14 13:01
$ coreutils-9.3/src/who -a
bruno    - ttyC0        Aug  9 20:24   .
$ coreutils-9.3/src/uptime
 13:02:12  up 5 days 16:14,  0 users,  load average: 0.02, 0.01, 0.00
Includes VM sleep time? no
$ coreutils-2023-08-13/src/who -a
bruno    - ttyC0        Aug  9 20:24   .
           system boot  Aug  9 20:24
$ coreutils-2023-08-13/src/uptime
 13:02:34  up 35 days 16:38,  1 user,  load average: 0.01, 0.01, 0.00
Includes VM sleep time? yes

--------------------------------------------------------------------------------
Solaris 11.4

$ date +"%Y-%m-%d %H:%M"
2023-08-15 14:27
$ coreutils-9.3/src/who -a
           system boot  2023-08-11 04:48
           run-level    2023-08-11 04:48
bruno    + console      2023-08-11 05:23   .          1109
LOGIN      vt/5         2023-08-11 04:49              1004 id=co20
LOGIN      vt/3         2023-08-11 04:49              1010 id=co30
LOGIN      vt/2         2023-08-11 04:49              1030 id=co40
LOGIN      vt/6         2023-08-11 04:49              1039 id=co50
LOGIN      vt/4         2023-08-11 04:49              1058 id=co60
           clock change 2023-08-15 14:27
$ coreutils-9.3/src/uptime
 14:27:10  up 4 days  9:38,  1 user,  load average: 0.04, 0.02, 0.01
Includes VM sleep time? yes
$ coreutils-2023-08-13/src/who -a
           system boot  2023-08-11 04:48
           run-level    2023-08-11 04:48
bruno    + console      2023-08-11 05:23   .          1109
LOGIN      vt/5         2023-08-11 04:49              1004 id=co20
LOGIN      vt/3         2023-08-11 04:49              1010 id=co30
LOGIN      vt/2         2023-08-11 04:49              1030 id=co40
LOGIN      vt/6         2023-08-11 04:49              1039 id=co50
LOGIN      vt/4         2023-08-11 04:49              1058 id=co60
           clock change 2023-08-15 14:27
$ coreutils-2023-08-13/src/uptime
 14:27:15  up 4 days  9:38,  1 user,  load average: 0.04, 0.02, 0.01
Includes VM sleep time? yes

--------------------------------------------------------------------------------
Minix 3.3

$ date +"%Y-%m-%d %H:%M"
2023-08-15 12:31
$ coreutils-9.3/src/who -a
           system boot  Jan  1 00:00
           run-level    Aug 12 02:46
bruno    - console      Aug 14 17:44  old          196
LOGIN      ttyc1        Aug 12 02:46               197 id=tyc1
LOGIN      ttyc2        Aug 12 02:46               198 id=tyc2
LOGIN      ttyc3        Aug 12 02:46               199 id=tyc3
$ coreutils-9.3/src/uptime
 12:31:09  up  15:02,  1 user,  load average: 0.00, 0.00, 0.00
Includes VM sleep time? no
$ coreutils-2023-08-13/src/who -a
           system boot  Aug 12 02:46
           run-level    Aug 12 02:46
bruno    - console      Aug 14 17:44  old          196
LOGIN      ttyc1        Aug 12 02:46               197 id=tyc1
LOGIN      ttyc2        Aug 12 02:46               198 id=tyc2
LOGIN      ttyc3        Aug 12 02:46               199 id=tyc3
$ coreutils-2023-08-13/src/uptime
 12:31:14  up 3 days  9:44,  1 user,  load average: 0.00, 0.00, 0.00
Includes VM sleep time? yes

--------------------------------------------------------------------------------
Cygwin 2.9.0

$ date +"%Y-%m-%d %H:%M"
2023-08-15 14:35
$ coreutils-9.3/src/who -a
$ coreutils-9.3/src/uptime
 14:35:58  up 3 days 23:04,  0 users,  load average: 0.00, 0.00, 0.00
Includes VM sleep time? no
$ coreutils-2023-08-13/src/who -a
           system boot  2023-08-11 10:56
$ coreutils-2023-08-13/src/uptime
 14:36:02  up 4 days  3:40,  0 users,  load average: 0.00, 0.00, 0.00
Includes VM sleep time? yes

--------------------------------------------------------------------------------
Haiku r1beta4

$ date +"%Y-%m-%d %H:%M"
2023-08-15 14:39
$ coreutils-9.3/src/who -a
who: /etc/utmp: No such file or directory
$ coreutils-9.3/src/uptime
bash: coreutils-9.3/src/uptime: No such file or directory
Includes VM sleep time? n/a
$ coreutils-2023-08-13/src/who -a
           system boot  2023-08-12 17:02
$ coreutils-2023-08-13/src/uptime
 14:40:01  up 2 days 21:37,  0 users
Includes VM sleep time? yes

--------------------------------------------------------------------------------
Android 11

$ date +"%Y-%m-%d %H:%M"
2023-08-15 10:52
$ coreutils-9.2/src/who -a
$ coreutils-9.2/src/uptime
uptime: couldn't get boot time: No such file or directory
$ coreutils-2023-08-13/src/who -a
           system boot  2023-08-09 23:32
$ coreutils-2023-08-13/src/uptime
 10:53:52  up 5 days 11:21,  0 users

--------------------------------------------------------------------------------