]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp: On Linux, don't fail if /var/run/utmp is not accessible.
authorBruno Haible <bruno@clisp.org>
Sat, 12 Aug 2023 21:44:23 +0000 (23:44 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 12 Aug 2023 21:44:23 +0000 (23:44 +0200)
* lib/boot-time-aux.h (get_linux_boot_time_final_fallback): Don't test
NEED_BOOT_TIME_FINAL_FALLBACK.
* lib/boot-time.c (NEED_BOOT_TIME_FINAL_FALLBACK): Remove macro.
* lib/readutmp.c (NEED_BOOT_TIME_FINAL_FALLBACK): Remove macro.
(read_utmp_from_file): As a fallback on Linux, invoke
get_linux_boot_time_final_fallback.
(get_boot_time_uncached): Don't do it here.
* m4/readutmp.m4 (gl_READUTMP): Add $CLOCK_TIME_LIB to READUTMP_LIB.

ChangeLog
lib/boot-time-aux.h
lib/boot-time.c
lib/readutmp.c
m4/readutmp.m4

index 30bf3bef826f664a09ea8f9cfef43347bf210b7d..3f47da62fbdb93aff3e37a9efaa98d4d9874064a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2023-08-12  Bruno Haible  <bruno@clisp.org>
+
+       readutmp: On Linux, don't fail if /var/run/utmp is not accessible.
+       * lib/boot-time-aux.h (get_linux_boot_time_final_fallback): Don't test
+       NEED_BOOT_TIME_FINAL_FALLBACK.
+       * lib/boot-time.c (NEED_BOOT_TIME_FINAL_FALLBACK): Remove macro.
+       * lib/readutmp.c (NEED_BOOT_TIME_FINAL_FALLBACK): Remove macro.
+       (read_utmp_from_file): As a fallback on Linux, invoke
+       get_linux_boot_time_final_fallback.
+       (get_boot_time_uncached): Don't do it here.
+       * m4/readutmp.m4 (gl_READUTMP): Add $CLOCK_TIME_LIB to READUTMP_LIB.
+
 2023-08-12  Bruno Haible  <bruno@clisp.org>
 
        readutmp, boot-time: On Haiku, return the boot time.
index 8006b7213416f03aed21deaf0f60a8f4848b3d80..e9f58e9d7e58a074c3d2b0ca41ca6596208fc34b 100644 (file)
@@ -101,8 +101,6 @@ get_linux_boot_time_fallback (struct timespec *p_boot_time)
   return -1;
 }
 
-# if NEED_BOOT_TIME_FINAL_FALLBACK
-
 /* The following approach is only usable as a fallback, because it is of
    the form
      boot_time = (time now) - (kernel's ktime_get_boottime[_ts64] ())
@@ -136,8 +134,6 @@ get_linux_boot_time_final_fallback (struct timespec *p_boot_time)
   return -1;
 }
 
-# endif
-
 #endif
 
 #if defined __ANDROID__
index 53bd8b148bc09719f3c73c04d43a08070ad36371..d813bfa5825702f6ac249353b38c6831a216e11b 100644 (file)
@@ -51,7 +51,6 @@
 #include "unlocked-io.h"
 
 /* Some helper functions.  */
-#define NEED_BOOT_TIME_FINAL_FALLBACK 1
 #include "boot-time-aux.h"
 
 /* The following macros describe the 'struct UTMP_STRUCT_NAME',
index d0c63034663efce39c587a4ab24bfae87feb165b..ef9f0aff43415f02b79479158bd980b23cc0cc8d 100644 (file)
@@ -58,7 +58,6 @@
 #include "unlocked-io.h"
 
 /* Some helper functions.  */
-#define NEED_BOOT_TIME_FINAL_FALLBACK READUTMP_USE_SYSTEMD
 #include "boot-time-aux.h"
 
 /* The following macros describe the 'struct UTMP_STRUCT_NAME',
@@ -587,6 +586,23 @@ read_utmp_from_file (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf,
 
 #  endif
 
+#  if defined __linux__ && !defined __ANDROID__
+  if ((options & (READ_UTMP_USER_PROCESS | READ_UTMP_NO_BOOT_TIME)) == 0
+      && strcmp (file, UTMP_FILE) == 0
+      && !have_boot_time (a))
+    {
+      struct timespec boot_time;
+      if (get_linux_boot_time_final_fallback (&boot_time) >= 0)
+        a = add_utmp (a, options,
+                      "reboot", strlen ("reboot"),
+                      "", 0,
+                      "~", strlen ("~"),
+                      "", 0,
+                      0, BOOT_TIME, boot_time, 0, 0, 0);
+    }
+
+#  endif
+
 #  if HAVE_SYS_SYSCTL_H && HAVE_SYSCTL \
       && defined CTL_KERN && defined KERN_BOOTTIME \
       && !defined __minix
@@ -683,12 +699,6 @@ get_boot_time_uncached (void)
     free (utmp);
   }
 
-  {
-    struct timespec boot_time;
-    if (get_linux_boot_time_final_fallback (&boot_time) >= 0)
-      return boot_time;
-  }
-
   /* We shouldn't get here.  */
   return (struct timespec) {0};
 }
index 827b573f46cf77d71a99c9a6526e096677a3124d..c1803740444d9ef166358d2c5182f631732e7fc7 100644 (file)
@@ -1,4 +1,4 @@
-# readutmp.m4 serial 26
+# readutmp.m4 serial 27
 dnl Copyright (C) 2002-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -40,6 +40,8 @@ AC_DEFUN([gl_READUTMP],
       fi
     fi
   fi
+  AC_REQUIRE([gl_CLOCK_TIME])
+  READUTMP_LIB="$READUTMP_LIB $CLOCK_TIME_LIB"
   AC_SUBST([READUTMP_LIB])
 
   gl_PREREQ_READUTMP_H