]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
uptime: output correct user count on OpenBSD
authorBruno Haible <bruno@clisp.org>
Sun, 30 Jul 2023 14:30:08 +0000 (16:30 +0200)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jul 2023 16:28:04 +0000 (09:28 -0700)
* src/uptime.c (print_uptime, uptime): Always call read_utmp
and count the result.
* NEWS: Mention the fix (text by Bruno Haible).

NEWS
src/uptime.c

diff --git a/NEWS b/NEWS
index 92e591ee2ec9e707045839b11df91e08aa9d97ed..41205fa88594b6fc2ddc68901ebcbdfacbb1166b 100644 (file)
--- 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]
index bc31026c0e7f7aa1cf781c3e1046807e5ccca624..b9d5e3c02f8e06ae0cd30e2ba0913d2018eed034 100644 (file)
@@ -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);