From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sat, 11 Sep 2021 17:36:22 +0200
Subject: [PATCH] Use UTMPX instead of legacy UTMP

We still have to include <utmp.h> because <utmpx.h> doesn't define
_PATH_WTMP. However, <utmp.h> includes <utmpx.h>, so it doesn't matter
so mach.

--- a/mingetty.c
+++ b/mingetty.c
@@ -94,12 +97,12 @@
 /* update_utmp() - update our utmp entry */
 static void update_utmp (void)
 {
-	struct utmp ut;
-	struct utmp *utp;
-	time_t cur_time;
+	struct utmpx ut;
+	struct utmpx *utp;
+	struct timeval tv;
 
-	setutent ();
-	while ((utp = getutent ()))
+	setutxent ();
+	while ((utp = getutxent ()))
 		if (utp->ut_type == INIT_PROCESS && utp->ut_pid == pid)
 			break;
 
@@ -118,16 +121,17 @@
 
 	strncpy (ut.ut_user, "LOGIN", sizeof (ut.ut_user));
 	strncpy (ut.ut_line, tty, sizeof (ut.ut_line));
-	time (&cur_time);
-	ut.ut_time = cur_time;
+	gettimeofday (&tv, NULL);
+	ut.ut_tv.tv_sec = tv.tv_sec;
+	ut.ut_tv.tv_usec = tv.tv_usec;
 	ut.ut_type = LOGIN_PROCESS;
 	ut.ut_pid = pid;
 	ut.ut_session = sid;
 
-	pututline (&ut);
-	endutent ();
+	pututxline (&ut);
+	endutxent ();
 
-	updwtmp (_PATH_WTMP, &ut);
+	updwtmpx (_PATH_WTMP, &ut);
 }
 
 /* open_tty - set up tty as standard { input, output, error } */
@@ -256,12 +260,12 @@
 	case 'U':
 		{
 			int users = 0;
-			struct utmp *ut;
-			setutent ();
-			while ((ut = getutent ()))
+			struct utmpx *ut;
+			setutxent ();
+			while ((ut = getutxent ()))
 				if (ut->ut_type == USER_PROCESS)
 					users++;
-			endutent ();
+			endutxent ();
 			printf ("%d", users);
 			if (c == 'U')
 				printf (" user%s", users == 1 ? "" : "s");
