summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2010-01-13 18:17:12 +0000
committered <ed@FreeBSD.org>2010-01-13 18:17:12 +0000
commit7297d6b5779271a7e43264e39e539c880d9d50fa (patch)
treed517e6759cb842f8b2c3b42260e816375e28b76d /usr.sbin
parentf9e9ecaea9305b47e0ad07a9a069b4e11f6bf788 (diff)
downloadFreeBSD-src-7297d6b5779271a7e43264e39e539c880d9d50fa.zip
FreeBSD-src-7297d6b5779271a7e43264e39e539c880d9d50fa.tar.gz
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.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/lastlogin/Makefile3
-rw-r--r--usr.sbin/lastlogin/lastlogin.c28
2 files changed, 14 insertions, 17 deletions
diff --git a/usr.sbin/lastlogin/Makefile b/usr.sbin/lastlogin/Makefile
index 4c65ab9..715badd 100644
--- a/usr.sbin/lastlogin/Makefile
+++ b/usr.sbin/lastlogin/Makefile
@@ -3,7 +3,4 @@
PROG= lastlogin
MAN= lastlogin.8
-DPADD= ${LIBULOG}
-LDADD= -lulog
-
.include <bsd.prog.mk>
diff --git a/usr.sbin/lastlogin/lastlogin.c b/usr.sbin/lastlogin/lastlogin.c
index d0a9b4d..9cc6b9f 100644
--- a/usr.sbin/lastlogin/lastlogin.c
+++ b/usr.sbin/lastlogin/lastlogin.c
@@ -41,62 +41,62 @@ __RCSID("$NetBSD: lastlogin.c,v 1.4 1998/02/03 04:45:35 perry Exp $");
#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
OpenPOWER on IntegriCloud