struct utmplist *next;
struct utmplist *prev;
};
-struct utmplist *utmplist = NULL;
/* Types of listing */
enum {
static void process_wtmp_file(const struct last_control *ctl)
{
FILE *fp; /* Filepointer of wtmp file */
+ char *filename;
struct utmp ut; /* Current utmp entry */
+ struct utmplist *ulist = NULL; /* All entries */
struct utmplist *p; /* Pointer into utmplist */
struct utmplist *next; /* Pointer into utmplist */
time(&lastdown);
lastrch = lastdown;
+ filename = ctl->altv[ctl->alti];
/*
* Fill in 'lastdate'
/*
* Open the utmp file
*/
- if ((fp = fopen(ctl->altv[ctl->alti], "r")) == NULL)
- err(EXIT_FAILURE, _("cannot open %s"), ctl->altv[ctl->alti]);
+ if ((fp = fopen(filename, "r")) == NULL)
+ err(EXIT_FAILURE, _("cannot open %s"), filename);
/*
* Optimize the buffer size.
begintime = ut.UL_UT_TIME;
else {
if (fstat(fileno(fp), &st) != 0)
- err(EXIT_FAILURE, _("stat of %s failed"), ctl->altv[ctl->alti]);
+ err(EXIT_FAILURE, _("stat of %s failed"), filename);
begintime = st.st_ctime;
quit = 1;
}
* the same ut_line.
*/
c = 0;
- for (p = utmplist; p; p = next) {
+ for (p = ulist; p; p = next) {
next = p->next;
if (strncmp(p->ut.ut_line, ut.ut_line,
UT_LINESIZE) == 0) {
quit = list(ctl, &ut, p->ut.UL_UT_TIME, R_NORMAL);
c = 1;
}
- if (p->next) p->next->prev = p->prev;
+ if (p->next)
+ p->next->prev = p->prev;
if (p->prev)
p->prev->next = p->next;
else
- utmplist = p->next;
+ ulist = p->next;
free(p);
}
}
break;
p = xmalloc(sizeof(struct utmplist));
memcpy(&p->ut, &ut, sizeof(struct utmp));
- p->next = utmplist;
+ p->next = ulist;
p->prev = NULL;
- if (utmplist) utmplist->prev = p;
- utmplist = p;
+ if (ulist)
+ ulist->prev = p;
+ ulist = p;
break;
case EMPTY:
/*
* If we saw a shutdown/reboot record we can remove
- * the entire current utmplist.
+ * the entire current ulist.
*/
if (down) {
lastboot = ut.UL_UT_TIME;
whydown = (ut.ut_type == SHUTDOWN_TIME) ? R_DOWN : R_CRASH;
- for (p = utmplist; p; p = next) {
+ for (p = ulist; p; p = next) {
next = p->next;
free(p);
}
- utmplist = NULL;
+ ulist = NULL;
down = 0;
}
}
- printf(_("\n%s begins %s"), basename(ctl->altv[ctl->alti]), ctime(&begintime));
+ printf(_("\n%s begins %s"), basename(filename), ctime(&begintime));
fclose(fp);
- for (p = utmplist; p; p = next) {
+
+ for (p = ulist; p; p = next) {
next = p->next;
free(p);
}
ctl.altc++;
}
- for (; ctl.alti < ctl.altc; ctl.alti++) {
+ for (ctl.alti = 0; ctl.alti < ctl.altc; ctl.alti++) {
get_boot_time(&ctl.boot_time);
process_wtmp_file(&ctl);
free(ctl.altv[ctl.alti]);