From owner-svn-src-all@FreeBSD.ORG Wed Jan 13 18:17:12 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F1A9F10656A7; Wed, 13 Jan 2010 18:17:12 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C7AFF8FC15; Wed, 13 Jan 2010 18:17:12 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0DIHC4s084607; Wed, 13 Jan 2010 18:17:12 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0DIHC44084604; Wed, 13 Jan 2010 18:17:12 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201001131817.o0DIHC44084604@svn.freebsd.org> From: Ed Schouten Date: Wed, 13 Jan 2010 18:17:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202205 - head/usr.sbin/lastlogin X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jan 2010 18:17:13 -0000 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 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 #include #include -#include #include +#include 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