- fstat(wtmp, &stb);
- bl = (stb.st_size + sizeof (buf)-1) / sizeof (buf);
- if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
- signal(SIGINT, onintr);
- signal(SIGQUIT, onintr);
- }
- for (bl--; bl >= 0; bl--) {
- lseek(wtmp, bl * sizeof (buf), 0);
- bp = &buf[read(wtmp, buf, sizeof (buf)) / sizeof(buf[0]) - 1];
- for ( ; bp >= buf; bp--) {
- print = want(bp);
- if (print) {
- ct = ctime(&bp->ut_time);
- printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s ",
- NMAX, NMAX, bp->ut_name,
- LMAX, LMAX, bp->ut_line,
- HMAX, HMAX, bp->ut_host,
- ct, 11+ct);
+ bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf);
+
+ (void)time(&buf[0].ut_time);
+ (void)signal(SIGINT, onintr);
+ (void)signal(SIGQUIT, onintr);
+
+ while (--bl >= 0) {
+ if (lseek(wfd, (long)(bl * sizeof(buf)), L_SET) == -1 ||
+ (bytes = read(wfd, (char *)buf, sizeof(buf))) == -1) {
+ fprintf(stderr, "last: %s: ", file);
+ perror((char *)NULL);
+ exit(1);
+ }
+ for (bp = &buf[bytes / sizeof(buf[0]) - 1]; bp >= buf; --bp) {
+ /*
+ * if the terminal line is '~', the machine stopped.
+ * see utmp(5) for more info.
+ */
+ if (!strncmp(bp->ut_line, "~", LMAX)) {
+ /* everybody just logged out */
+ for (T = ttylist; T; T = T->next)
+ T->logout = -bp->ut_time;
+ currentout = -bp->ut_time;
+ crmsg = strncmp(bp->ut_name, "shutdown", NMAX) ? "crash" : "down ";
+ if (!bp->ut_name[0])
+ (void)strcpy(bp->ut_name, "reboot");
+ if (want(bp, NO)) {
+ ct = ctime(&bp->ut_time);
+ printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", NMAX, NMAX, bp->ut_name, LMAX, LMAX, bp->ut_line, HMAX, HMAX, bp->ut_host, ct, ct + 11);
+ if (maxrec && !--maxrec)
+ return;
+ }
+ continue;