coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] build: uptime: avoid issues on systems without utmp.h


From: Pádraig Brady
Subject: [PATCH] build: uptime: avoid issues on systems without utmp.h
Date: Sun, 5 Feb 2023 14:16:33 +0000

* src/uptime.c (print_uptime): Following gnulib commit 9041103
HAVE_UTMP_H will always be defined.  Therefore key on whether
the utmp.ut_type member is present.
* boottime.m4 (GNULIB_BOOT_TIME): Assume utmp.h is present.
---
 m4/boottime.m4 | 5 ++---
 src/uptime.c   | 4 ++--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/m4/boottime.m4 b/m4/boottime.m4
index ac277e0f2..aa440ce1d 100644
--- a/m4/boottime.m4
+++ b/m4/boottime.m4
@@ -27,7 +27,7 @@ AC_DEFUN([GNULIB_BOOT_TIME],
      [#if HAVE_SYS_PARAM_H
        #include <sys/param.h>
       #endif]])
-  AC_CHECK_HEADERS_ONCE([utmp.h utmpx.h OS.h])
+  AC_CHECK_HEADERS_ONCE([utmpx.h OS.h])
   AC_CACHE_CHECK(
     [whether we can get the system boot time],
     [gnulib_cv_have_boot_time],
@@ -43,9 +43,8 @@ AC_DEFUN([GNULIB_BOOT_TIME],
 #endif
 #if HAVE_UTMPX_H
 # include <utmpx.h>
-#elif HAVE_UTMP_H
-# include <utmp.h>
 #endif
+#include <utmp.h>
 #if HAVE_OS_H
 # include <OS.h>
 #endif
diff --git a/src/uptime.c b/src/uptime.c
index b1d9e96c3..061b85c16 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -102,7 +102,7 @@ print_uptime (size_t n, const STRUCT_UTMP *this)
   }
 #endif
 
-#if HAVE_UTMPX_H || HAVE_UTMP_H
+#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--)
@@ -179,7 +179,7 @@ uptime (char const *filename, int options)
   size_t n_users;
   STRUCT_UTMP *utmp_buf = NULL;
 
-#if HAVE_UTMPX_H || HAVE_UTMP_H
+#if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
   if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
     die (EXIT_FAILURE, errno, "%s", quotef (filename));
 #endif
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]