Changeset View
Changeset View
Standalone View
Standalone View
head/usr.bin/last/last.c
Show All 34 Lines | |||||
#ifndef lint | #ifndef lint | ||||
static const char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94"; | static const char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94"; | ||||
#endif /* not lint */ | #endif /* not lint */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/capsicum.h> | |||||
#include <sys/queue.h> | |||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <capsicum_helpers.h> | |||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <langinfo.h> | #include <langinfo.h> | ||||
#include <locale.h> | #include <locale.h> | ||||
#include <paths.h> | #include <paths.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <timeconv.h> | #include <timeconv.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <utmpx.h> | #include <utmpx.h> | ||||
#include <sys/queue.h> | |||||
#define NO 0 /* false/no */ | #define NO 0 /* false/no */ | ||||
#define YES 1 /* true/yes */ | #define YES 1 /* true/yes */ | ||||
#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2; | #define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2; | ||||
typedef struct arg { | typedef struct arg { | ||||
char *name; /* argument */ | char *name; /* argument */ | ||||
#define REBOOT_TYPE -1 | #define REBOOT_TYPE -1 | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | while ((ch = getopt(argc, argv, "0123456789d:f:h:n:st:wy")) != -1) | ||||
case 'y': | case 'y': | ||||
yflag++; | yflag++; | ||||
break; | break; | ||||
case '?': | case '?': | ||||
default: | default: | ||||
usage(); | usage(); | ||||
} | } | ||||
if (caph_limit_stdio() < 0) | |||||
err(1, "can't limit stdio rights"); | |||||
caph_cache_catpages(); | |||||
caph_cache_tzdata(); | |||||
/* Cache UTX database. */ | |||||
if (setutxdb(UTXDB_LOG, file) != 0) | |||||
err(1, "%s", file != NULL ? file : "(default utx db)"); | |||||
if (cap_enter() < 0 && errno != ENOSYS) | |||||
err(1, "cap_enter"); | |||||
if (sflag && width == 8) usage(); | if (sflag && width == 8) usage(); | ||||
if (argc) { | if (argc) { | ||||
setlinebuf(stdout); | setlinebuf(stdout); | ||||
for (argv += optind; *argv; ++argv) { | for (argv += optind; *argv; ++argv) { | ||||
if (strcmp(*argv, "reboot") == 0) | if (strcmp(*argv, "reboot") == 0) | ||||
addarg(REBOOT_TYPE, *argv); | addarg(REBOOT_TYPE, *argv); | ||||
#define COMPATIBILITY | #define COMPATIBILITY | ||||
Show All 21 Lines | wtmp(void) | ||||
time_t t; | time_t t; | ||||
char ct[80]; | char ct[80]; | ||||
struct tm *tm; | struct tm *tm; | ||||
SLIST_INIT(&idlist); | SLIST_INIT(&idlist); | ||||
(void)time(&t); | (void)time(&t); | ||||
/* Load the last entries from the file. */ | /* Load the last entries from the file. */ | ||||
if (setutxdb(UTXDB_LOG, file) != 0) | |||||
err(1, "%s", file); | |||||
while ((ut = getutxent()) != NULL) { | while ((ut = getutxent()) != NULL) { | ||||
if (amount % 128 == 0) { | if (amount % 128 == 0) { | ||||
buf = realloc(buf, (amount + 128) * sizeof *ut); | buf = realloc(buf, (amount + 128) * sizeof *ut); | ||||
if (buf == NULL) | if (buf == NULL) | ||||
err(1, "realloc"); | err(1, "realloc"); | ||||
} | } | ||||
memcpy(&buf[amount++], ut, sizeof *ut); | memcpy(&buf[amount++], ut, sizeof *ut); | ||||
if (t > ut->ut_tv.tv_sec) | if (t > ut->ut_tv.tv_sec) | ||||
▲ Show 20 Lines • Show All 333 Lines • Show Last 20 Lines |