Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/last Add wtmpx support.



details:   https://anonhg.NetBSD.org/src/rev/6c1fef6041c0
branches:  trunk
changeset: 543113:6c1fef6041c0
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Feb 17 15:08:57 2003 +0000

description:
Add wtmpx support.

diffstat:

 usr.bin/last/Makefile |    3 +-
 usr.bin/last/last.1   |   23 ++-
 usr.bin/last/last.c   |  363 +++++++++++++++++++------------------------------
 usr.bin/last/want.c   |  225 ++++++++++++++++++++++++++++++
 4 files changed, 389 insertions(+), 225 deletions(-)

diffs (truncated from 788 to 300 lines):

diff -r 65734d43d5db -r 6c1fef6041c0 usr.bin/last/Makefile
--- a/usr.bin/last/Makefile     Mon Feb 17 14:37:57 2003 +0000
+++ b/usr.bin/last/Makefile     Mon Feb 17 15:08:57 2003 +0000
@@ -1,6 +1,7 @@
-#      $NetBSD: Makefile,v 1.5 1997/10/19 03:44:21 lukem Exp $
+#      $NetBSD: Makefile,v 1.6 2003/02/17 15:08:57 christos Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 
 PROG=  last
+CPPFLAGS+=-DSUPPORT_UTMPX -DSUPPORT_UTMP
 
 .include <bsd.prog.mk>
diff -r 65734d43d5db -r 6c1fef6041c0 usr.bin/last/last.1
--- a/usr.bin/last/last.1       Mon Feb 17 14:37:57 2003 +0000
+++ b/usr.bin/last/last.1       Mon Feb 17 15:08:57 2003 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: last.1,v 1.9 2002/09/30 11:09:04 grant Exp $
+.\"    $NetBSD: last.1,v 1.10 2003/02/17 15:08:57 christos Exp $
 .\"
 .\" Copyright (c) 1980, 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -46,6 +46,9 @@
 .Op Fl f Ar file
 .Op Fl h Ar host
 .Op Fl t Ar tty
+.Op Fl L Ar linesize
+.Op Fl N Ar namesize
+.Op Fl H Ar hostsize
 .Op user ...
 .Sh DESCRIPTION
 .Nm
@@ -70,7 +73,14 @@
 reads the file
 .Ar file
 instead of the default,
+.Pa /var/log/wtmpx
+or
 .Pa /var/log/wtmp .
+If the file ends with `x', it is treated as a
+.Xr utmpx 5
+format file, else it is treated as a
+.Xr utmp 5
+format file.
 .It Fl Ar n
 Limits the report to
 .Ar n
@@ -88,6 +98,12 @@
 names may be names or internet numbers.
 .It Fl T
 Display better time information, including the year and seconds.
+.It Fl L Ar linesize
+Use the provided linesize as the width to format the tty field.
+.It Fl N Ar namesize
+Use the provided namesize as the width to format the login name field.
+.It Fl H Ar hostsize
+Use the provided hostsize as the width to format the host name field.
 .El
 .Pp
 If
@@ -117,12 +133,15 @@
 indicates how
 far the search has progressed and then continues.
 .Sh FILES
-.Bl -tag -width /var/log/wtmp -compact
+.Bl -tag -width /var/log/wtmpx -compact
+.It Pa /var/log/wtmpx
+login data base
 .It Pa /var/log/wtmp
 login data base
 .El
 .Sh SEE ALSO
 .Xr lastcomm 1 ,
+.Xr utmpx 5 ,
 .Xr utmp 5 ,
 .Xr ac 8
 .Sh HISTORY
diff -r 65734d43d5db -r 6c1fef6041c0 usr.bin/last/last.c
--- a/usr.bin/last/last.c       Mon Feb 17 14:37:57 2003 +0000
+++ b/usr.bin/last/last.c       Mon Feb 17 15:08:57 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: last.c,v 1.15 2000/06/30 06:19:58 simonb Exp $ */
+/*     $NetBSD: last.c,v 1.16 2003/02/17 15:08:57 christos Exp $       */
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -44,7 +44,7 @@
 #if 0
 static char sccsid[] = "@(#)last.c     8.2 (Berkeley) 4/2/94";
 #endif
-__RCSID("$NetBSD: last.c,v 1.15 2000/06/30 06:19:58 simonb Exp $");
+__RCSID("$NetBSD: last.c,v 1.16 2003/02/17 15:08:57 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -60,7 +60,23 @@
 #include <time.h>
 #include <tzfile.h>
 #include <unistd.h>
+#ifdef SUPPORT_UTMPX
+#include <utmpx.h>
+#endif
+#ifdef SUPPORT_UTMP
 #include <utmp.h>
+#endif
+
+#ifndef UT_NAMESIZE
+#define UT_NAMESIZE 8
+#define UT_LINESIZE 8
+#define UT_HOSTSIZE 16
+#endif
+#ifndef SIGNATURE
+#define SIGNATURE -1
+#endif
+
+
 
 #define        NO      0                       /* false/no */
 #define        YES     1                       /* true/yes */
@@ -76,7 +92,7 @@
 #define        TIMEONLY        0x2             /* show time only, not date */
 #define        GMT             0x4             /* show time at GMT, for offsets only */
 
-static struct utmp     buf[1024];      /* utmp read buffer */
+#define MAXUTMP                1024;
 
 typedef struct arg {
        char    *name;                  /* argument */
@@ -86,40 +102,61 @@
        int     type;                   /* type of arg */
        struct arg      *next;          /* linked list pointer */
 } ARG;
-ARG    *arglist;                       /* head of linked list */
+static ARG     *arglist;               /* head of linked list */
 
 typedef struct ttytab {
        time_t  logout;                 /* log out time */
-       char    tty[UT_LINESIZE + 1];   /* terminal name */
+       char    tty[128];               /* terminal name */
        struct ttytab   *next;          /* linked list pointer */
 } TTY;
-TTY    *ttylist;                       /* head of linked list */
+static TTY     *ttylist;               /* head of linked list */
 
 static time_t  currentout;             /* current logout value */
 static long    maxrec;                 /* records to display */
-static char    *file = _PATH_WTMP;     /* wtmp file */
 static int     fulltime = 0;           /* Display seconds? */
 
-int     main __P((int, char *[]));
-void    addarg __P((int, char *));
-TTY    *addtty __P((char *));
-void    hostconv __P((char *));
-void    onintr __P((int));
-char   *ttyconv __P((char *));
-int     want __P((struct utmp *, int));
-void    wtmp __P((void));
-char   *fmttime __P((time_t, int));
+int     main(int, char *[]);
+
+static void     addarg(int, char *);
+static TTY     *addtty(const char *);
+static void     hostconv(char *);
+static char    *ttyconv(char *);
+#ifdef SUPPORT_UTMPX
+static void     wtmpx(const char *, int, int, int);
+#endif
+#ifdef SUPPORT_UTMP
+static void     wtmp(const char *, int, int, int);
+#endif
+static char    *fmttime(time_t, int);
+static void     usage(void);
+
+static
+void usage(void)
+{
+       (void)fprintf(stderr, "Usage: %s [-#%s] [-f file] [-t tty]"
+           " [-h hostname] [-T] [user ...]\n", getprogname(),
+#ifdef SUPPORT_UTMPX
+           "w"
+#else
+           ""
+#endif
+       );
+       exit(1);
+}
 
 int
-main(argc, argv)
-       int argc;
-       char *argv[];
+main(int argc, char *argv[])
 {
        int ch;
        char *p;
+       char    *file = NULL;
+       int namesize = UT_NAMESIZE;
+       int linesize = UT_LINESIZE;
+       int hostsize = UT_HOSTSIZE;
 
        maxrec = -1;
-       while ((ch = getopt(argc, argv, "0123456789f:h:t:T")) != -1)
+
+       while ((ch = getopt(argc, argv, "0123456789f:h:H:L:N:t:T")) != -1)
                switch (ch) {
                case '0': case '1': case '2': case '3': case '4':
                case '5': case '6': case '7': case '8': case '9':
@@ -147,14 +184,21 @@
                case 't':
                        addarg(TTY_TYPE, ttyconv(optarg));
                        break;
+               case 'U':
+                       namesize = atoi(optarg);
+                       break;
+               case 'L':
+                       linesize = atoi(optarg);
+                       break;
+               case 'H':
+                       hostsize = atoi(optarg);
+                       break;
                case 'T':
                        fulltime = 1;
                        break;
                case '?':
                default:
-                       (void)fprintf(stderr,
-       "usage: last [-#] [-f file] [-t tty] [-h hostname] [-T] [user ...]\n");
-                       exit(1);
+                       usage();
                }
 
        if (argc) {
@@ -168,186 +212,50 @@
                        addarg(USER_TYPE, *argv);
                }
        }
-       wtmp();
+       if (file == NULL) {
+#ifdef SUPPORT_UTMPX
+               if (access(_PATH_WTMPX, R_OK) == 0)
+                       file = _PATH_WTMPX;
+               else
+#endif
+#ifdef SUPPORT_UTMP
+               if (access(_PATH_WTMP, R_OK) == 0)
+                       file = _PATH_WTMP;
+#endif
+               if (file == NULL)
+#if defined(SUPPORT_UTMPX) && defined(SUPPORT_UTMP)
+                       errx(1, "Cannot access `%s' or `%s'", _PATH_WTMPX,
+                           _PATH_WTMP);
+#elif defined(SUPPORT_UTMPX)
+                       errx(1, "Cannot access `%s'", _PATH_WTMPX);
+#elif defined(SUPPORT_UTMP)
+                       errx(1, "Cannot access `%s'", _PATH_WTMP);
+#else
+                       errx(1, "No utmp or utmpx support compiled in.");
+#endif
+       }
+#if defined(SUPPORT_UTMPX) && defined(SUPPORT_UTMP)
+       if (file[strlen(file) - 1] == 'x')
+               wtmpx(file, namesize, linesize, hostsize);
+       else
+               wtmp(file, namesize, linesize, hostsize);
+#elif defined(SUPPORT_UTMPX)
+       wtmpx(file, namesize, linesize, hostsize);
+#elif defined(SUPPORT_UTMP)
+       wtmp(file, namesize, linesize, hostsize);
+#else
+       errx(1, "Nu utmp or utmpx support compiled in.");
+#endif
        exit(0);
 }
 
-/*
- * wtmp --
- *     read through the wtmp file
- */
-void
-wtmp()
-{
-       struct utmp     *bp;            /* current structure */
-       TTY     *T;                     /* tty list entry */
-       struct stat     stb;            /* stat of file for size */
-       time_t  delta;                  /* time difference */
-       off_t   bl;
-       int     bytes, wfd;
-       char    *ct, *crmsg;
-
-       crmsg = NULL;
-
-       if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1)
-               err(1, "%s", file);
-       bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf);
-
-       (void)time(&buf[0].ut_time);
-       (void)signal(SIGINT, onintr);
-       (void)signal(SIGQUIT, onintr);
-
-       while (--bl >= 0) {
-               if (lseek(wfd, bl * sizeof(buf), SEEK_SET) == -1 ||



Home | Main Index | Thread Index | Old Index