svn commit: r202205 - head/usr.sbin/lastlogin

Ed Schouten ed at FreeBSD.org
Wed Jan 13 18:17:13 UTC 2010


Author: ed
Date: Wed Jan 13 18:17:12 2010
New Revision: 202205
URL: http://svn.freebsd.org/changeset/base/202205

Log:
  Port lastlogin(8) to utmpx.
  
  While there, fix a bug I introduced previously. We must reopen the
  database for each username passed on the command line. We must rewind
  the database and search from the beginning.

Modified:
  head/usr.sbin/lastlogin/Makefile
  head/usr.sbin/lastlogin/lastlogin.c

Modified: head/usr.sbin/lastlogin/Makefile
==============================================================================
--- head/usr.sbin/lastlogin/Makefile	Wed Jan 13 18:15:46 2010	(r202204)
+++ head/usr.sbin/lastlogin/Makefile	Wed Jan 13 18:17:12 2010	(r202205)
@@ -3,7 +3,4 @@
 PROG=	lastlogin
 MAN=	lastlogin.8
 
-DPADD=	${LIBULOG}
-LDADD=	-lulog
-
 .include <bsd.prog.mk>

Modified: head/usr.sbin/lastlogin/lastlogin.c
==============================================================================
--- head/usr.sbin/lastlogin/lastlogin.c	Wed Jan 13 18:15:46 2010	(r202204)
+++ head/usr.sbin/lastlogin/lastlogin.c	Wed Jan 13 18:17:12 2010	(r202205)
@@ -41,62 +41,62 @@ __RCSID("$NetBSD: lastlogin.c,v 1.4 1998
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-#include <ulog.h>
 #include <unistd.h>
+#include <utmpx.h>
 
 	int	main(int, char **);
-static	void	output(struct ulog_utmpx *);
+static	void	output(struct utmpx *);
 static	void	usage(void);
 
 int
 main(int argc, char *argv[])
 {
 	int	ch, i;
-	struct ulog_utmpx *u;
+	struct utmpx *u;
 
 	while ((ch = getopt(argc, argv, "")) != -1) {
 		usage();
 	}
 
-	if (ulog_setutxfile(UTXI_USER, NULL) != 0)
-		errx(1, "failed to open lastlog database");
-
 	setpassent(1);	/* Keep passwd file pointers open */
 
 	/* Process usernames given on the command line. */
 	if (argc > 1) {
 		for (i = 1; i < argc; ++i) {
-			if ((u = ulog_getutxuser(argv[i])) == NULL) {
+			if (setutxdb(UTXDB_LASTLOGIN, NULL) != 0)
+				errx(1, "failed to open lastlog database");
+			if ((u = getutxuser(argv[i])) == NULL) {
 				warnx("user '%s' not found", argv[i]);
 				continue;
 			}
 			output(u);
+			endutxent();
 		}
 	}
 	/* Read all lastlog entries, looking for active ones */
 	else {
-		while ((u = ulog_getutxent()) != NULL) {
+		if (setutxdb(UTXDB_LASTLOGIN, NULL) != 0)
+			errx(1, "failed to open lastlog database");
+		while ((u = getutxent()) != NULL) {
 			if (u->ut_type != USER_PROCESS)
 				continue;
 			output(u);
 		}
+		endutxent();
 	}
 
 	setpassent(0);	/* Close passwd file pointers */
-
-	ulog_endutxent();
 	exit(0);
 }
 
 /* Duplicate the output of last(1) */
 static void
-output(struct ulog_utmpx *u)
+output(struct utmpx *u)
 {
 	time_t t = u->ut_tv.tv_sec;
 
-	printf("%-16s  %-8s %-16s   %s",
-		u->ut_user, u->ut_line, u->ut_host,
-		(u->ut_type == USER_PROCESS) ? ctime(&t) : "Never logged in\n");
+	printf("%-10s %-8s %-22s %s",
+		u->ut_user, u->ut_line, u->ut_host, ctime(&t));
 }
 
 static void


More information about the svn-src-head mailing list