version 1.39, 2013/08/22 04:43:40 |
version 1.40, 2014/04/17 09:56:09 |
|
|
int want(struct utmp *, int); |
int want(struct utmp *, int); |
void wtmp(void); |
void wtmp(void); |
void checkargs(void); |
void checkargs(void); |
|
void print_entry(const struct utmp *); |
void usage(void); |
void usage(void); |
|
|
#define NAME_WIDTH 9 |
#define NAME_WIDTH 9 |
|
|
} |
} |
} |
} |
|
|
|
void |
|
print_entry(const struct utmp *bp) |
|
{ |
|
printf("%-*.*s %-*.*s %-*.*s ", |
|
NAME_WIDTH, UT_NAMESIZE, bp->ut_name, |
|
UT_LINESIZE, UT_LINESIZE, bp->ut_line, |
|
HOST_WIDTH, UT_HOSTSIZE, bp->ut_host); |
|
|
|
if (seconds) |
|
printf("%lld", (long long)bp->ut_time); |
|
else { |
|
struct tm *tm; |
|
|
|
tm = localtime(&bp->ut_time); |
|
if (tm == NULL) { |
|
/* bogus entry? format as epoch time... */ |
|
printf("%lld", (long long)bp->ut_time); |
|
} else { |
|
char tim[40]; |
|
|
|
strftime(tim, sizeof tim, |
|
fulltime ? "%a %b %d %H:%M:%S" : "%a %b %d %H:%M", |
|
tm); |
|
printf("%s", tim); |
|
} |
|
} |
|
} |
|
|
|
|
/* |
/* |
* read through the wtmp file |
* read through the wtmp file |
*/ |
*/ |
|
|
{ |
{ |
time_t delta, total = 0; |
time_t delta, total = 0; |
int timesize, wfd, snapfound = 0; |
int timesize, wfd, snapfound = 0; |
char *ct, *crmsg, tim[40]; |
char *ct, *crmsg; |
struct utmp *bp; |
struct utmp *bp; |
struct stat stb; |
struct stat stb; |
ssize_t bytes; |
ssize_t bytes; |
|
|
* unless flagged for |
* unless flagged for |
*/ |
*/ |
if (want(bp, NO)) { |
if (want(bp, NO)) { |
if (seconds) { |
print_entry(bp); |
snprintf(tim, sizeof tim, "%ld", |
printf("\n"); |
(long)bp->ut_time); |
|
} else { |
|
ct = ctime(&bp->ut_time); |
|
snprintf(tim, sizeof tim, |
|
"%10.10s %*.*s", ct, |
|
timesize, timesize, ct + 11); |
|
} |
|
printf("%-*.*s %-*.*s %-*.*s %s \n", |
|
NAME_WIDTH, UT_NAMESIZE, bp->ut_name, |
|
UT_LINESIZE, UT_LINESIZE, bp->ut_line, |
|
HOST_WIDTH, UT_HOSTSIZE, bp->ut_host, |
|
tim); |
|
|
|
if (maxrec != -1 && !--maxrec) { |
if (maxrec != -1 && !--maxrec) { |
close(wfd); |
close(wfd); |
return; |
return; |
|
|
if ((bp->ut_line[0] == '{' || bp->ut_line[0] == '|') && |
if ((bp->ut_line[0] == '{' || bp->ut_line[0] == '|') && |
!bp->ut_line[1]) { |
!bp->ut_line[1]) { |
if (want(bp, NO)) { |
if (want(bp, NO)) { |
if (seconds) { |
print_entry(bp); |
snprintf(tim, sizeof tim, "%ld", |
printf("\n"); |
(long)bp->ut_time); |
|
} else { |
|
ct = ctime(&bp->ut_time); |
|
snprintf(tim, sizeof tim, |
|
"%10.10s %*.*s", ct, |
|
timesize, timesize, ct + 11); |
|
} |
|
printf("%-*.*s %-*.*s %-*.*s %s \n", |
|
NAME_WIDTH, UT_NAMESIZE, bp->ut_name, |
|
UT_LINESIZE, UT_LINESIZE, bp->ut_line, |
|
HOST_WIDTH, UT_HOSTSIZE, bp->ut_host, |
|
tim); |
|
|
|
if (maxrec && !--maxrec) { |
if (maxrec && !--maxrec) { |
close(wfd); |
close(wfd); |
return; |
return; |
|
|
(T->logout > snaptime || !T->logout || |
(T->logout > snaptime || !T->logout || |
T->logout < 0)))) { |
T->logout < 0)))) { |
snapfound = 1; |
snapfound = 1; |
if (seconds) { |
print_entry(bp); |
snprintf(tim, sizeof tim, "%ld", |
printf(" "); |
(long)bp->ut_time); |
|
} else { |
|
ct = ctime(&bp->ut_time); |
|
snprintf(tim, sizeof tim, |
|
"%10.10s %*.*s", ct, |
|
timesize, timesize, ct + 11); |
|
} |
|
printf("%-*.*s %-*.*s %-*.*s %s ", |
|
NAME_WIDTH, UT_NAMESIZE, bp->ut_name, |
|
UT_LINESIZE, UT_LINESIZE, bp->ut_line, |
|
HOST_WIDTH, UT_HOSTSIZE, bp->ut_host, |
|
tim); |
|
|
|
if (!T->logout) |
if (!T->logout) |
puts(" still logged in"); |
puts(" still logged in"); |
|
|
printf("- %s", crmsg); |
printf("- %s", crmsg); |
} else { |
} else { |
if (seconds) |
if (seconds) |
printf("- %ld", |
printf("- %lld", |
(long)T->logout); |
(long long)T->logout); |
else |
else |
printf("- %*.*s", |
printf("- %*.*s", |
timesize, timesize, |
timesize, timesize, |
|
|
} |
} |
delta = T->logout - bp->ut_time; |
delta = T->logout - bp->ut_time; |
if (seconds) |
if (seconds) |
printf(" (%ld)\n", (long)delta); |
printf(" (%lld)\n", |
|
(long long)delta); |
else { |
else { |
if (delta < SECSPERDAY) |
if (delta < SECSPERDAY) |
printf(" (%*.*s)\n", |
printf(" (%*.*s)\n", |