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>
This commit is contained in:
parent
2d5ea05a45
commit
6628ca0a98
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=202643
@ -196,8 +196,6 @@ main(int argc, char *argv[])
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAXUTXENTRIES 1024
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* wtmp --
|
* wtmp --
|
||||||
* read through the wtmp file
|
* read through the wtmp file
|
||||||
@ -205,9 +203,9 @@ main(int argc, char *argv[])
|
|||||||
void
|
void
|
||||||
wtmp(void)
|
wtmp(void)
|
||||||
{
|
{
|
||||||
struct utmpx buf[MAXUTXENTRIES];
|
struct utmpx *buf = NULL;
|
||||||
struct utmpx *ut;
|
struct utmpx *ut;
|
||||||
static unsigned int first = 0, amount = 0;
|
static unsigned int amount = 0;
|
||||||
time_t t;
|
time_t t;
|
||||||
char ct[80];
|
char ct[80];
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
@ -219,11 +217,12 @@ wtmp(void)
|
|||||||
if (setutxdb(UTXDB_LOG, file) != 0)
|
if (setutxdb(UTXDB_LOG, file) != 0)
|
||||||
err(1, "%s", file);
|
err(1, "%s", file);
|
||||||
while ((ut = getutxent()) != NULL) {
|
while ((ut = getutxent()) != NULL) {
|
||||||
memcpy(&buf[(first + amount) % MAXUTXENTRIES], ut, sizeof *ut);
|
if (amount % 128 == 0) {
|
||||||
if (amount == MAXUTXENTRIES)
|
buf = realloc(buf, (amount + 128) * sizeof *ut);
|
||||||
first++;
|
if (buf == NULL)
|
||||||
else
|
err(1, "realloc");
|
||||||
amount++;
|
}
|
||||||
|
memcpy(&buf[amount++], ut, sizeof *ut);
|
||||||
if (t > ut->ut_tv.tv_sec)
|
if (t > ut->ut_tv.tv_sec)
|
||||||
t = ut->ut_tv.tv_sec;
|
t = ut->ut_tv.tv_sec;
|
||||||
}
|
}
|
||||||
@ -231,7 +230,7 @@ wtmp(void)
|
|||||||
|
|
||||||
/* Display them in reverse order. */
|
/* Display them in reverse order. */
|
||||||
while (amount > 0)
|
while (amount > 0)
|
||||||
doentry(&buf[(first + amount--) % MAXUTXENTRIES]);
|
doentry(&buf[--amount]);
|
||||||
|
|
||||||
tm = localtime(&t);
|
tm = localtime(&t);
|
||||||
(void) strftime(ct, sizeof(ct), "\nwtmp begins %+\n", tm);
|
(void) strftime(ct, sizeof(ct), "\nwtmp begins %+\n", tm);
|
||||||
|
Loading…
Reference in New Issue
Block a user