- 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);
+
+ time(&buf[0].ut_time);
+ signal(SIGINT,onintr);
+ signal(SIGQUIT,onintr);
+
+ tab[MAXTTYS].logout = -1; /* end flag value */
+ while (--bl >= 0) {
+ if (lseek(wtmp,(long)(bl * sizeof(buf)),L_SET) == -1 || (bytes = read(wtmp,(char *)buf,sizeof(buf))) == -1) {
+ perror(file);
+ exit(1);
+ }
+ for (bp = &buf[bytes / sizeof(buf[0]) - 1];bp >= buf;--bp) {
+ if (lineq(bp->ut_line,"~")) {
+ /*
+ * if the name is empty and the terminal
+ * line is '~', it's a shutdown of some
+ * sort; see utmp(5) for more info.
+ */
+ for (T = tab;T->logout != -1;++T)
+ T->logout = -bp->ut_time;
+ crmsg = nameq(bp->ut_name,"shutdown") ? "down " : "crash";
+ if (!bp->ut_name[0])
+ 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 != -1 && !--maxrec)
+ exit(0);
+ }
+ continue;