coreutils: fix uptime command

coreutils doesn't handle absent utmp files
fix #6405
This commit is contained in:
Jerome Duval
2021-11-16 10:34:08 +01:00
parent ba7b1cc055
commit 37c40d7a19
2 changed files with 39 additions and 1 deletions

View File

@@ -17,7 +17,7 @@ uptime users vdir wc who whoami yes"
HOMEPAGE="https://www.gnu.org/software/coreutils/"
COPYRIGHT="1994-2017 Free Software Foundation, Inc."
LICENSE="GNU GPL v3"
REVISION="5"
REVISION="6"
SOURCE_URI="https://ftpmirror.gnu.org/coreutils/coreutils-$portVersion.tar.xz
https://ftp.gnu.org/gnu/coreutils/coreutils-$portVersion.tar.xz"
CHECKSUM_SHA256="ce30acdf4a41bc5bb30dd955e9eaa75fa216b4e3deb08889ed32433c7b3b97ce"
@@ -154,6 +154,7 @@ fi
BUILD_PREREQUIRES="
haiku${secondaryArchSuffix}_devel
cmd:awk
cmd:cmp
cmd:gcc$secondaryArchSuffix
cmd:grep
cmd:help2man

View File

@@ -697,3 +697,40 @@ index c7eb740..dde3e4b 100644
--
2.30.2
From ce0ad419f18d006929850e56b6fd2d50f1857789 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Tue, 16 Nov 2021 10:22:30 +0100
Subject: [PATCH] uptime: make utmp error not critical
---
src/uptime.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/uptime.c b/src/uptime.c
index fc0f0a5..779fc09 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -105,7 +105,7 @@ print_uptime (size_t n, const STRUCT_UTMP *this)
#if HAVE_UTMPX_H || HAVE_UTMP_H
/* Loop through all the utmp entries we just read and count up the valid
ones, also in the process possibly gleaning boottime. */
- while (n--)
+ while (this && n--)
{
entries += IS_USER_PROCESS (this);
if (UT_TYPE_BOOT_TIME (this))
@@ -181,7 +181,11 @@ uptime (char const *filename, int options)
#if HAVE_UTMPX_H || HAVE_UTMP_H
if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
+#if HAVE_OS_H
+ ;
+#else
die (EXIT_FAILURE, errno, "%s", quotef (filename));
+#endif
#endif
print_uptime (n_users, utmp_buf);
--
2.30.2