]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp: In systemd mode, fix the ut_host contents (regr. yesterday).
authorBruno Haible <bruno@clisp.org>
Fri, 4 Aug 2023 13:26:37 +0000 (15:26 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 4 Aug 2023 13:26:37 +0000 (15:26 +0200)
* lib/readutmp.c (add_utmp): Fix ut_host contents.
* tests/test-readutmp.c (main): Show also the contents of the ut_host
field.

ChangeLog
lib/readutmp.c
tests/test-readutmp.c

index 7e9c04111ee690f094b234aba8ec7a85137fdf89..9c99c673a93d8fbe970884f0923a85d7e1aea190 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-08-04  Bruno Haible  <bruno@clisp.org>
+
+       readutmp: In systemd mode, fix the ut_host contents (regr. yesterday).
+       * lib/readutmp.c (add_utmp): Fix ut_host contents.
+       * tests/test-readutmp.c (main): Show also the contents of the ut_host
+       field.
+
 2023-08-04  Bruno Haible  <bruno@clisp.org>
 
        readutmp: Ensure multithread-safety.
index 01c02ad36e1d4b8b6d2dbefe7bcbd71673e3133a..ac1c851e97fce779bbcd46e5da4feba3387fbad0 100644 (file)
@@ -280,7 +280,7 @@ add_utmp (struct utmp_alloc a, int options,
   ut->ut_user = p = memcpy (p - usersize, user, usersize);
   ut->ut_id   = p = memcpy (p -   idsize,   id,   idsize);
   ut->ut_line = p = memcpy (p - linesize, line, linesize);
-  ut->ut_host = memcpy (p - hostsize, line, hostsize);
+  ut->ut_host =     memcpy (p - hostsize, host, hostsize);
   ut->ut_ts = ts;
   ut->ut_pid = pid;
   ut->ut_session = session;
index 7afba18b87bd89b3a0e4ca40659d0bca3addde22..a11e247bf507d07961c11ffb9909a8fea7516511 100644 (file)
@@ -57,8 +57,8 @@ main (int argc, char *argv[])
   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");
+  printf ("    Time (GMT)             User          Device        PID    nation Exit  B U  Host\n");
+  printf ("------------------- ------------------ ----------- ---------- ------ ----  - -  ----\n");
 
   /* What do the results look like?
      * On Alpine Linux, Cygwin, Android, the output is empty.
@@ -111,6 +111,7 @@ main (int argc, char *argv[])
           long pid = UT_PID (entry);
           int termination = UT_EXIT_E_TERMINATION (entry);
           int exit = UT_EXIT_E_EXIT (entry);
+          const char *host = entry->ut_host;
 
           time_t tim = UT_TIME_MEMBER (entry);
           struct tm *gmt = gmtime (&tim);
@@ -120,7 +121,7 @@ main (int argc, char *argv[])
                  == 0)
             strcpy (timbuf, "---");
 
-          printf ("%-19s %-18s %-11s %10ld %4d   %3d   %c %c\n",
+          printf ("%-19s %-18s %-11s %10ld %4d   %3d   %c %c  %s\n",
                   timbuf,
                   user,
                   device,
@@ -128,7 +129,8 @@ main (int argc, char *argv[])
                   termination,
                   exit,
                   UT_TYPE_BOOT_TIME (entry) ? 'X' : ' ',
-                  UT_TYPE_USER_PROCESS (entry) ? 'X' : ' ');
+                  UT_TYPE_USER_PROCESS (entry) ? 'X' : ' ',
+                  host);
         }
       fflush (stdout);