bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] readutmp: work around glibc utmpx bug


From: Bruno Haible
Subject: Re: [PATCH] readutmp: work around glibc utmpx bug
Date: Mon, 31 Jul 2023 23:25:26 +0200

>       * tests/test-readutmp.c: New file.

I had missed the fact that the 'ut_line' field is portable (and coreutils
uses it in the 'who' and 'pinky' programs). So, it has to be included in the
unit test.


2023-07-31  Bruno Haible  <bruno@clisp.org>

        readutmp tests: Show also the ut_line field.
        * tests/test-readutmp.c (main): Add a "Device" column to the table.
        Adjust the column widths. Flush stdout before possibly calling abort().

diff --git a/tests/test-readutmp.c b/tests/test-readutmp.c
index 933808b257..b806b47116 100644
--- a/tests/test-readutmp.c
+++ b/tests/test-readutmp.c
@@ -52,9 +52,47 @@ main (int argc, char *argv[])
       return 77;
     }
 
-  printf ("    Time (GMT)           User          PID     Term Exit Boot User 
Process\n");
-  printf ("------------------- --------------- ---------- ---- ---- ---- 
------------\n");
-
+  printf ("Here are the read_utmp results.\n");
+  printf ("Flags: B = Boot, U = User Process\n");
+  printf ("\n");
+  printf ("                                                              
Termi‐      Flags\n");
+  printf ("    Time (GMT)             User          Device        PID    
nation Exit  B U\n");
+  printf ("------------------- ------------------ ----------- ---------- 
------ ----  - -\n");
+
+  /* What do the results look like?
+     * On Alpine Linux, Cygwin, Android, the output is empty.
+     * The entries are usually not sorted according to the Time column, so
+       we do it here.
+     * In the User column, special values exist:
+       - The empty string denotes a system event.
+         Seen on glibc, macOS, FreeBSD, NetBSD, OpenBSD, AIX
+       - The value "reboot" denotes a reboot.
+         Seen on glibc
+       - The value "runlevel" denotes a runlevel change.
+         Seen on glibc
+       - The value "LOGIN" denotes the start of a virtual console.
+         Seen on glibc, Solaris
+       - The value "/usr/libexec/getty" denotes the start of a virtual console.
+         Seen on NetBSD
+     * In the Device column:
+       - The empty string denotes a system event.
+         Seen on macOS, FreeBSD, AIX
+       - The value "~" denotes an event with no associated device.
+         Seen on glibc
+       - The values "system boot", "system down", "run-level N" are
+         seen on NetBSD, AIX, Solaris.
+       - The values "old time", "new time" are
+         seen on Solaris.
+       - Common devices are:
+         - On glibc: "ttyN" (console) and "pts/N" (pseudo-terminals).
+         - On macOS: "ttysNNN" (pseudo-terminals).
+         - On FreeBSD: "ttyvN" (console).
+         - On NetBSD: "ttyEN", "constty" (console).
+         - On OpenBSD: "ttyCN", "console" (console) and "ttypN" 
(pseudo-terminals).
+         - on AIX: "vtyN" (console) and "pts/N" (pseudo-terminals).
+         - On Solaris: "vt/N", "console" (console) and "pts/N" 
(pseudo-terminals).
+     * The PID column is zero on platforms without a 'ut_pid' field: OpenBSD.
+   */
   if (num_entries > 0)
     {
       /* Sort the entries according to increasing UT_TIME_MEMBER (entry).
@@ -68,6 +106,7 @@ main (int argc, char *argv[])
           const STRUCT_UTMP *entry = &entries[i];
 
           char *user = extract_trimmed_name (entry);
+          const char *device = entry->ut_line;
           long pid = UT_PID (entry);
           int termination = UT_EXIT_E_TERMINATION (entry);
           int exit = UT_EXIT_E_EXIT (entry);
@@ -80,15 +119,17 @@ main (int argc, char *argv[])
                  == 0)
             strcpy (timbuf, "---");
 
-          printf ("%s %-15s %10ld %3d  %3d   %c       %c\n",
+          printf ("%-19s %-18s %-11s %10ld %4d   %3d   %c %c\n",
                   timbuf,
                   user,
+                  device,
                   pid,
                   termination,
                   exit,
                   UT_TYPE_BOOT_TIME (entry) ? 'X' : ' ',
                   UT_TYPE_USER_PROCESS (entry) ? 'X' : ' ');
         }
+      fflush (stdout);
 
       /* If the first time is more than 5 years in the past or the last time
          is more than a week in the future, the time_t members are wrong.  */






reply via email to

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