From 911c345724b62e2cdc603e5f0df5671a794daf7b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 4 Aug 2023 15:26:37 +0200 Subject: [PATCH] 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. --- ChangeLog | 7 +++++++ lib/readutmp.c | 2 +- tests/test-readutmp.c | 10 ++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e9c04111e..9c99c673a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-08-04 Bruno Haible + + 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 readutmp: Ensure multithread-safety. diff --git a/lib/readutmp.c b/lib/readutmp.c index 01c02ad36e..ac1c851e97 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -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; diff --git a/tests/test-readutmp.c b/tests/test-readutmp.c index 7afba18b87..a11e247bf5 100644 --- a/tests/test-readutmp.c +++ b/tests/test-readutmp.c @@ -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); -- 2.39.5