version 1.5, 1997/07/20 09:07:17 |
version 1.6, 1997/07/25 02:23:34 |
|
|
static time_t currentout; /* current logout value */ |
static time_t currentout; /* current logout value */ |
static long maxrec; /* records to display */ |
static long maxrec; /* records to display */ |
static char *file = _PATH_WTMP; /* wtmp file */ |
static char *file = _PATH_WTMP; /* wtmp file */ |
|
static int fulltime = 0; /* Display seconds? */ |
static time_t snaptime; /* if != 0, we will only |
static time_t snaptime; /* if != 0, we will only |
* report users logged in |
* report users logged in |
* at this snapshot time |
* at this snapshot time |
|
|
|
|
maxrec = -1; |
maxrec = -1; |
snaptime = 0; |
snaptime = 0; |
while ((ch = getopt(argc, argv, "0123456789f:h:t:d:")) != -1) |
while ((ch = getopt(argc, argv, "0123456789f:h:t:d:T")) != -1) |
switch (ch) { |
switch (ch) { |
case '0': case '1': case '2': case '3': case '4': |
case '0': case '1': case '2': case '3': case '4': |
case '5': case '6': case '7': case '8': case '9': |
case '5': case '6': case '7': case '8': case '9': |
|
|
case 'd': |
case 'd': |
snaptime = dateconv(optarg); |
snaptime = dateconv(optarg); |
break; |
break; |
|
case 'T': |
|
fulltime = -1; |
|
break; |
case '?': |
case '?': |
default: |
default: |
(void)fprintf(stderr, |
(void)fprintf(stderr, |
"usage: last [-#] [-f file] [-t tty]" |
"usage: last [-#] [-f file] [-T] [-t tty]" |
" [-h host] [-d [MMDD]hhmm[.SS]]" |
" [-h host] [-d [MMDD]hhmm[.SS]]" |
" [user ...]\n"); |
" [user ...]\n"); |
exit(1); |
exit(1); |
|
|
void |
void |
wtmp() |
wtmp() |
{ |
{ |
struct utmp *bp; /* current structure */ |
struct utmp *bp; /* current structure */ |
TTY *T; /* tty list entry */ |
TTY *T; /* tty list entry */ |
struct stat stb; /* stat of file for size */ |
struct stat stb; /* stat of file for size */ |
time_t bl, delta; /* time difference */ |
time_t bl, delta; /* time difference */ |
|
int timesize; /* how long time string gonna be */ |
int bytes, wfd; |
int bytes, wfd; |
char *ct, *crmsg; |
char *ct, *crmsg; |
int snapfound = 0; /* found snapshot entry? */ |
int snapfound = 0; /* found snapshot entry? */ |
if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1) |
if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1) |
err(1, "%s", file); |
err(1, "%s", file); |
bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf); |
bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf); |
|
|
|
if (fulltime) |
|
timesize = 8; /* HH:MM:SS */ |
|
else |
|
timesize = 5; /* HH:MM */ |
|
|
(void)time(&buf[0].ut_time); |
(void)time(&buf[0].ut_time); |
(void)signal(SIGINT, onintr); |
(void)signal(SIGINT, onintr); |
(void)signal(SIGQUIT, onintr); |
(void)signal(SIGQUIT, onintr); |
|
|
*/ |
*/ |
if (want(bp, NO)) { |
if (want(bp, NO)) { |
ct = ctime(&bp->ut_time); |
ct = ctime(&bp->ut_time); |
printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", |
printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s \n", |
UT_NAMESIZE, UT_NAMESIZE, |
UT_NAMESIZE, UT_NAMESIZE, |
bp->ut_name, UT_LINESIZE, |
bp->ut_name, UT_LINESIZE, |
UT_LINESIZE, bp->ut_line, |
UT_LINESIZE, bp->ut_line, |
UT_HOSTSIZE, UT_HOSTSIZE, |
UT_HOSTSIZE, UT_HOSTSIZE, |
bp->ut_host, ct, ct + 11); |
bp->ut_host, ct, timesize, |
|
timesize, ct + 11); |
if (maxrec != -1 && !--maxrec) |
if (maxrec != -1 && !--maxrec) |
return; |
return; |
} |
} |
|
|
&& !bp->ut_line[1]) { |
&& !bp->ut_line[1]) { |
if (want(bp, NO)) { |
if (want(bp, NO)) { |
ct = ctime(&bp->ut_time); |
ct = ctime(&bp->ut_time); |
printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", |
printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s \n", |
UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, |
UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, |
UT_LINESIZE, UT_LINESIZE, bp->ut_line, |
UT_LINESIZE, UT_LINESIZE, bp->ut_line, |
UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, |
UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, |
ct, ct + 11); |
ct, timesize, timesize, ct + 11); |
if (maxrec && !--maxrec) |
if (maxrec && !--maxrec) |
return; |
return; |
} |
} |
|
|
T->logout < 0)))) { |
T->logout < 0)))) { |
snapfound = 1; |
snapfound = 1; |
ct = ctime(&bp->ut_time); |
ct = ctime(&bp->ut_time); |
printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s ", |
printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s ", |
UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, |
UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, |
UT_LINESIZE, UT_LINESIZE, bp->ut_line, |
UT_LINESIZE, UT_LINESIZE, bp->ut_line, |
UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, |
UT_HOSTSIZE, UT_HOSTSIZE, bp->ut_host, |
ct, ct + 11); |
ct, timesize, timesize, ct + 11); |
if (!T->logout) |
if (!T->logout) |
puts(" still logged in"); |
puts(" still logged in"); |
else { |
else { |
|
|
printf("- %s", crmsg); |
printf("- %s", crmsg); |
} |
} |
else |
else |
printf("- %5.5s", |
printf("- %*.*s", |
|
timesize, timesize, |
ctime(&T->logout)+11); |
ctime(&T->logout)+11); |
delta = T->logout - bp->ut_time; |
delta = T->logout - bp->ut_time; |
if (delta < SECSPERDAY) |
if (delta < SECSPERDAY) |
printf(" (%5.5s)\n", |
printf(" (%*.*s)\n", |
|
timesize, timesize, |
asctime(gmtime(&delta))+11); |
asctime(gmtime(&delta))+11); |
else |
else |
printf(" (%ld+%5.5s)\n", |
printf(" (%ld+%*.*s)\n", |
delta / SECSPERDAY, |
delta / SECSPERDAY, |
|
timesize, timesize, |
asctime(gmtime(&delta))+11); |
asctime(gmtime(&delta))+11); |
} |
} |
if (maxrec != -1 && !--maxrec) |
if (maxrec != -1 && !--maxrec) |
|
|
} |
} |
} |
} |
ct = ctime(&buf[0].ut_time); |
ct = ctime(&buf[0].ut_time); |
printf("\nwtmp begins %10.10s %5.5s \n", ct, ct + 11); |
printf("\nwtmp begins %10.10s %*.*s \n", ct, timesize, timesize, ct + 11); |
} |
} |
|
|
/* |
/* |
|
|
char *ct; |
char *ct; |
|
|
ct = ctime(&buf[0].ut_time); |
ct = ctime(&buf[0].ut_time); |
printf("\ninterrupted %10.10s %5.5s \n", ct, ct + 11); |
printf("\ninterrupted %10.10s %8.8s \n", ct, ct + 11); |
if (signo == SIGINT) |
if (signo == SIGINT) |
exit(1); |
exit(1); |
(void)fflush(stdout); /* fix required for rsh */ |
(void)fflush(stdout); /* fix required for rsh */ |