summaryrefslogtreecommitdiffstats
path: root/usr.bin/last/last.c
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2010-01-19 19:53:05 +0000
committered <ed@FreeBSD.org>2010-01-19 19:53:05 +0000
commit7848a5349f855e84d678e5dce37385b1e3ca92e8 (patch)
tree75629d8be62fdd6acf821d349d5568478e784ee1 /usr.bin/last/last.c
parent6852acc871c80b0a9a030cfc09767707a9bc2bb3 (diff)
downloadFreeBSD-src-7848a5349f855e84d678e5dce37385b1e3ca92e8.zip
FreeBSD-src-7848a5349f855e84d678e5dce37385b1e3ca92e8.tar.gz
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 <ato iem pw edu pl>
Diffstat (limited to 'usr.bin/last/last.c')
-rw-r--r--usr.bin/last/last.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/usr.bin/last/last.c b/usr.bin/last/last.c
index a202b31..eb38b64 100644
--- a/usr.bin/last/last.c
+++ b/usr.bin/last/last.c
@@ -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);
OpenPOWER on IntegriCloud