From owner-svn-src-user@FreeBSD.ORG Sun Jan 10 17:45:47 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 793AD106568D; Sun, 10 Jan 2010 17:45:47 +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 6A7EB8FC24; Sun, 10 Jan 2010 17:45:47 +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 o0AHjlD8095651; Sun, 10 Jan 2010 17:45:47 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0AHjlqC095649; Sun, 10 Jan 2010 17:45:47 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201001101745.o0AHjlqC095649@svn.freebsd.org> From: Ed Schouten Date: Sun, 10 Jan 2010 17:45:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202020 - user/ed/utmpx/usr.bin/last X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jan 2010 17:45:47 -0000 Author: ed Date: Sun Jan 10 17:45:47 2010 New Revision: 202020 URL: http://svn.freebsd.org/changeset/base/202020 Log: Somewhat make last(1) work. Right now it's still quite broken. It doesn't properly detect logouts, because it doesn't honour ut_id and ut_type yet. Modified: user/ed/utmpx/usr.bin/last/last.c Modified: user/ed/utmpx/usr.bin/last/last.c ============================================================================== --- user/ed/utmpx/usr.bin/last/last.c Sun Jan 10 17:44:22 2010 (r202019) +++ user/ed/utmpx/usr.bin/last/last.c Sun Jan 10 17:45:47 2010 (r202020) @@ -66,8 +66,6 @@ __FBSDID("$FreeBSD$"); #define YES 1 /* true/yes */ #define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2; -static struct utmpx buf[1024]; /* utmp read buffer */ - typedef struct arg { char *name; /* argument */ #define HOST_TYPE -2 @@ -104,7 +102,6 @@ void addarg(int, char *); time_t dateconv(char *); void doentry(struct utmpx *); void hostconv(char *); -void onintr(int); void printentry(struct utmpx *, struct ttytab *); char *ttyconv(char *); int want(struct utmpx *); @@ -199,6 +196,8 @@ main(int argc, char *argv[]) exit(0); } +#define MAXUTXENTRIES 1024 + /* * wtmp -- * read through the wtmp file @@ -206,36 +205,37 @@ main(int argc, char *argv[]) void wtmp(void) { -#if 0 - struct utmpx *bp; /* current structure */ - int bytes, wfd; + struct utmpx buf[MAXUTXENTRIES]; + struct utmpx *ut; + static unsigned int first = 0, amount = 0; + time_t t; char ct[80]; struct tm *tm; - time_t t; LIST_INIT(&ttylist); + (void)time(&t); + /* Load the last entries from the file. */ if (setutxdb(UTXDB_LOG, file) != 0) err(1, "%s", file); - bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf); + while ((ut = getutxent()) != NULL) { + memcpy(&buf[(first + amount) % MAXUTXENTRIES], ut, sizeof *ut); + if (amount == MAXUTXENTRIES) + first++; + else + amount++; + if (t > ut->ut_tv.tv_sec) + t = ut->ut_tv.tv_sec; + } + endutxent(); + + /* Display them in reverse order. */ + while (amount > 0) + doentry(&buf[(first + amount--) % MAXUTXENTRIES]); - (void)time(&t); - buf[0].ut_tv.tv_sec = t; - (void)signal(SIGINT, onintr); - (void)signal(SIGQUIT, onintr); - - while (--bl >= 0) { - if (lseek(wfd, (off_t)(bl * sizeof(buf)), L_SET) == -1 || - (bytes = read(wfd, buf, sizeof(buf))) == -1) - err(1, "%s", file); - for (bp = &buf[bytes / sizeof(buf[0]) - 1]; bp >= buf; --bp) - doentry(bp); - } - t = buf[0].ut_tv.tv_sec; tm = localtime(&t); (void) strftime(ct, sizeof(ct), "\nwtmp begins %+\n", tm); printf("%s", ct); -#endif } /* @@ -550,25 +550,3 @@ terr: errx(1, "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]"); return timet; } - - -/* - * onintr -- - * on interrupt, we inform the user how far we've gotten - */ -void -onintr(int signo) -{ - char ct[80]; - struct tm *tm; - time_t t = buf[0].ut_tv.tv_sec; - - tm = localtime(&t); - (void) strftime(ct, sizeof(ct), - d_first ? "%a %e %b %R" : "%a %b %e %R", - tm); - printf("\ninterrupted %s\n", ct); - if (signo == SIGINT) - exit(1); - (void)fflush(stdout); /* fix required for rsh */ -}