From owner-svn-src-all@FreeBSD.ORG Tue Jan 19 19:53:06 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 19ABF106568D; Tue, 19 Jan 2010 19:53:06 +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 08C368FC14; Tue, 19 Jan 2010 19:53:06 +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 o0JJr5YH090622; Tue, 19 Jan 2010 19:53:05 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0JJr5Ko090620; Tue, 19 Jan 2010 19:53:05 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201001191953.o0JJr5Ko090620@svn.freebsd.org> From: Ed Schouten Date: Tue, 19 Jan 2010 19:53:05 +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: r202643 - head/usr.bin/last 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: Tue, 19 Jan 2010 19:53:06 -0000 Author: ed Date: Tue Jan 19 19:53:05 2010 New Revision: 202643 URL: http://svn.freebsd.org/changeset/base/202643 Log: Make last(1) display the full log file. I must have misread when I ported the original last(1) source code. Instead of only processing the last 1024 entries, it reads them in in chucks of 1024 entries at a time. Unfortunately we cannot walk through the log file in reverse order, which means we have to allocate a piece of memory to hold all the entries. Call realloc() for each 128 entries we read. Reported by: Andrzej Tobola Modified: head/usr.bin/last/last.c Modified: head/usr.bin/last/last.c ============================================================================== --- head/usr.bin/last/last.c Tue Jan 19 19:51:54 2010 (r202642) +++ head/usr.bin/last/last.c Tue Jan 19 19:53:05 2010 (r202643) @@ -196,8 +196,6 @@ main(int argc, char *argv[]) exit(0); } -#define MAXUTXENTRIES 1024 - /* * wtmp -- * read through the wtmp file @@ -205,9 +203,9 @@ main(int argc, char *argv[]) void wtmp(void) { - struct utmpx buf[MAXUTXENTRIES]; + struct utmpx *buf = NULL; struct utmpx *ut; - static unsigned int first = 0, amount = 0; + static unsigned int amount = 0; time_t t; char ct[80]; struct tm *tm; @@ -219,11 +217,12 @@ wtmp(void) if (setutxdb(UTXDB_LOG, file) != 0) err(1, "%s", file); while ((ut = getutxent()) != NULL) { - memcpy(&buf[(first + amount) % MAXUTXENTRIES], ut, sizeof *ut); - if (amount == MAXUTXENTRIES) - first++; - else - amount++; + if (amount % 128 == 0) { + buf = realloc(buf, (amount + 128) * sizeof *ut); + if (buf == NULL) + err(1, "realloc"); + } + memcpy(&buf[amount++], ut, sizeof *ut); if (t > ut->ut_tv.tv_sec) t = ut->ut_tv.tv_sec; } @@ -231,7 +230,7 @@ wtmp(void) /* Display them in reverse order. */ while (amount > 0) - doentry(&buf[(first + amount--) % MAXUTXENTRIES]); + doentry(&buf[--amount]); tm = localtime(&t); (void) strftime(ct, sizeof(ct), "\nwtmp begins %+\n", tm);