From 5c543845da80312ed0bc61b8c51fccd33bde5464 Mon Sep 17 00:00:00 2001 From: christos Date: Fri, 4 Mar 2005 17:16:13 +0000 Subject: [PATCH] PR/26934: Curt Sampson: Add -x flag to process wtmpx files that don't end in `x'. --- usr.bin/last/last.1 | 18 +++++++++++++----- usr.bin/last/last.c | 14 +++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/usr.bin/last/last.1 b/usr.bin/last/last.1 index 9b92bb205615..c9e977282b6f 100644 --- a/usr.bin/last/last.1 +++ b/usr.bin/last/last.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: last.1,v 1.14 2004/11/11 01:00:34 wiz Exp $ +.\" $NetBSD: last.1,v 1.15 2005/03/04 17:16:13 christos Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)last.1 8.1 (Berkeley) 6/6/93 .\" -.Dd November 10, 2004 +.Dd March 4, 2005 .Dt LAST 1 .Os .Sh NAME @@ -38,7 +38,7 @@ .Sh SYNOPSIS .Nm .Op Fl Ns Ar n -.Op Fl nT +.Op Fl nTx .Op Fl f Ar file .Op Fl H Ar hostsize .Op Fl h Ar host @@ -94,8 +94,12 @@ Use the provided linesize as the width to format the tty field. Use the provided namesize as the width to format the login name field. .It Fl n Print host addresses numerically. -This option works only on wtmpx entries, -and prints nothing on wtmp entries. +This option works only on +.Xr wtmpx 5 +entries, +and prints nothing on +.Xr wtmp 5 +entries. .It Fl T Display better time information, including the year and seconds. .It Fl t Ar tty @@ -105,6 +109,10 @@ Tty names may be given fully or abbreviated, for example, .Dq Li "last -t 03" is equivalent to .Dq Li "last -t tty03" . +.It Fl x +Assume that the file given is +.Xr wtmpx 5 +format, even if the filename does not end with an `x'. .El .Pp If multiple arguments are given, the information which applies to any of the diff --git a/usr.bin/last/last.c b/usr.bin/last/last.c index f53ff4681748..e1f3bd9defd1 100644 --- a/usr.bin/last/last.c +++ b/usr.bin/last/last.c @@ -1,4 +1,4 @@ -/* $NetBSD: last.c,v 1.25 2004/11/19 21:41:25 christos Exp $ */ +/* $NetBSD: last.c,v 1.26 2005/03/04 17:16:13 christos Exp $ */ /* * Copyright (c) 1987, 1993, 1994 @@ -40,7 +40,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94"; #endif -__RCSID("$NetBSD: last.c,v 1.25 2004/11/19 21:41:25 christos Exp $"); +__RCSID("$NetBSD: last.c,v 1.26 2005/03/04 17:16:13 christos Exp $"); #endif /* not lint */ #include @@ -112,6 +112,7 @@ static TTY *ttylist; /* head of linked list */ static time_t currentout; /* current logout value */ static long maxrec; /* records to display */ static int fulltime = 0; /* Display seconds? */ +static int xflag; /* Assume file is wtmpx format */ int main(int, char *[]); @@ -131,7 +132,7 @@ static void usage(void); static void usage(void) { - (void)fprintf(stderr, "usage: %s [-#%s] [-nT] [-f file]" + (void)fprintf(stderr, "usage: %s [-#%s] [-nTx] [-f file]" " [-H hostsize] [-h host] [-L linesize]\n" "\t [-N namesize] [-t tty] [user ...]\n", getprogname(), #ifdef NOTYET_SUPPORT_UTMPX @@ -156,7 +157,7 @@ main(int argc, char *argv[]) maxrec = -1; - while ((ch = getopt(argc, argv, "0123456789f:H:h:L:nN:Tt:")) != -1) + while ((ch = getopt(argc, argv, "0123456789f:H:h:L:nN:Tt:x")) != -1) switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -199,6 +200,9 @@ main(int argc, char *argv[]) case 't': addarg(TTY_TYPE, ttyconv(optarg)); break; + case 'x': + xflag = 1; + break; case '?': default: usage(); @@ -238,7 +242,7 @@ main(int argc, char *argv[]) #endif } #if defined(SUPPORT_UTMPX) && defined(SUPPORT_UTMP) - if (file[strlen(file) - 1] == 'x') + if (file[strlen(file) - 1] == 'x' || xflag) wtmpx(file, namesize, linesize, hostsize, numeric); else wtmp(file, namesize, linesize, hostsize, numeric);