On 2023-07-30 11:41, Pádraig Brady wrote:
I'm fine with the change, but we'll also need to adjust
the sc_prohibit_always_true_header_tests syntax check in gnulib
I looked into that but it's such a hassle that I came up with the
attached simpler patch to Coreutils. How about installing it instead? No
Gnulib change should be needed.From 08cb549b6089519c1900339189398e66521b19ea Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 30 Jul 2023 16:30:08 +0200
Subject: [PATCH] uptime: output correct user count on OpenBSD
* src/uptime.c (print_uptime, uptime): Always call read_utmp
and count the result.
* NEWS: Mention the fix (text by Bruno Haible).
---
NEWS | 3 +++
src/uptime.c | 7 -------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/NEWS b/NEWS
index 92e591ee2..41205fa88 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,9 @@ GNU coreutils NEWS -*- outline -*-
'pr --length=1 --double-space' no longer enters an infinite loop.
[This bug was present in "the beginning".]
+ 'uptime' no longer incorrectly prints "0 users" on OpenBSD.
+ [bug introduced in coreutils-9.2]
+
'wc -l' and 'cksum' no longer crash with an "Illegal instruction" error
on x86 Linux kernels that disable XSAVE YMM. This was seen on Xen VMs.
[bug introduced in coreutils-9.0]
diff --git a/src/uptime.c b/src/uptime.c
index bc31026c0..b9d5e3c02 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -100,7 +100,6 @@ print_uptime (size_t n, const STRUCT_UTMP *this)
}
#endif
-#if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
/* Loop through all the utmp entries we just read and count up the valid
ones, also in the process possibly gleaning boottime. */
while (n--)
@@ -110,10 +109,6 @@ print_uptime (size_t n, const STRUCT_UTMP *this)
boot_time = UT_TIME_MEMBER (this);
++this;
}
-#else
- (void) n;
- (void) this;
-#endif
time_now = time (nullptr);
#if defined HAVE_PROC_UPTIME
@@ -177,10 +172,8 @@ uptime (char const *filename, int options)
size_t n_users;
STRUCT_UTMP *utmp_buf = nullptr;
-#if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
error (EXIT_FAILURE, errno, "%s", quotef (filename));
-#endif
print_uptime (n_users, utmp_buf);
--
2.39.2