]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp: Use classical implementation for files != /var/run/utmp.
authorBruno Haible <bruno@clisp.org>
Tue, 8 Aug 2023 21:27:38 +0000 (23:27 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 8 Aug 2023 21:27:38 +0000 (23:27 +0200)
* lib/readutmp.c (read_utmp_from_systemd): Renamed from read_utmp
[READUTMP_USE_SYSTEMD]. Remove file argument.
(read_utmp): Call it when the file argument is "/var/run/utmp".

ChangeLog
lib/readutmp.c

index 62e281fa9783136b1740b957761108f047224e6b..199c818c186c7515408031dd47f40c1e4ca412ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-08-08  Bruno Haible  <bruno@clisp.org>
+
+       readutmp: Use classical implementation for files != /var/run/utmp.
+       * lib/readutmp.c (read_utmp_from_systemd): Renamed from read_utmp
+       [READUTMP_USE_SYSTEMD]. Remove file argument.
+       (read_utmp): Call it when the file argument is "/var/run/utmp".
+
 2023-08-08  Bruno Haible  <bruno@clisp.org>
 
        readutmp: Get the boot time with higher precision.
index f7e43eb4a6ce351e6741c48690ddfb69fe3e5574..66b25bc7ae2c1cea13ce0392aba6d136010828c2 100644 (file)
@@ -439,17 +439,9 @@ guess_pty_name (uid_t uid, const struct timespec at)
   return NULL;
 }
 
-int
-read_utmp (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf,
-           int options)
+static int
+read_utmp_from_systemd (idx_t *n_entries, STRUCT_UTMP **utmp_buf, int options)
 {
-  /* The current implementation can imitate only UTMP_FILE.  */
-  if (strcmp (file, UTMP_FILE) != 0)
-    {
-      errno = ENOTSUP;
-      return -1;
-    }
-
   /* Fill entries, simulating what a utmp file would contain.  */
   struct utmp_alloc a = {0};
 
@@ -602,7 +594,9 @@ read_utmp (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf,
   return 0;
 }
 
-# elif defined UTMP_NAME_FUNCTION /* glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, IRIX, Solaris, Cygwin, Android */
+# endif
+
+# if defined UTMP_NAME_FUNCTION /* glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, IRIX, Solaris, Cygwin, Android */
 
 #  if !HAVE_UTMPX_H && HAVE_UTMP_H && !HAVE_DECL_GETUTENT
 struct utmp *getutent (void);
@@ -612,6 +606,12 @@ int
 read_utmp (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf,
            int options)
 {
+#  if READUTMP_USE_SYSTEMD
+  if (strcmp (file, UTMP_FILE) == 0)
+    /* Imitate reading UTMP_FILE, using systemd and Linux APIs.  */
+    return read_utmp_from_systemd (n_entries, utmp_buf, options);
+#  endif
+
   /* Ignore the return value for now.
      Solaris' utmpname returns 1 upon success -- which is contrary
      to what the GNU libc version does.  In addition, older GNU libc