2 * last(1) from sysvinit project, merged into util-linux in Aug 2013.
4 * Copyright (C) 1991-2004 Miquel van Smoorenburg.
5 * Copyright (C) 2013 Ondrej Oprala <ooprala@redhat.com>
6 * Karel Zak <kzak@redhat.com>
8 * Re-implementation of the 'last' command, this time for Linux. Yes I know
9 * there is BSD last, but I just felt like writing this. No thanks :-). Also,
10 * this version gives lots more info (especially with -x)
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <sys/types.h>
29 #include <sys/fcntl.h>
40 #include <netinet/in.h>
42 #include <arpa/inet.h>
47 #include "pathnames.h"
49 #include "closestream.h"
50 #include "carefulputc.h"
52 #include "timeutils.h"
53 #include "monotonic.h"
55 #if defined(_HAVE_UT_TV)
56 # define UL_UT_TIME ut_tv.tv_sec
58 # define UL_UT_TIME ut_time
62 # define SHUTDOWN_TIME 254
65 #ifndef LAST_LOGIN_LEN
66 # define LAST_LOGIN_LEN 8
69 #ifndef LAST_DOMAIN_LEN
70 # define LAST_DOMAIN_LEN 16
73 #ifndef LAST_TIMESTAMP_LEN
74 # define LAST_TIMESTAMP_LEN 32
77 #define UCHUNKSIZE 16384 /* How much we read at once. */
80 unsigned int lastb
:1, /* Is this command 'lastb' */
81 extended
:1, /* Lots of info */
82 showhost
:1, /* Show hostname */
83 altlist
:1, /* Hostname at the end */
84 usedns
:1, /* Use DNS to lookup the hostname */
85 useip
:1; /* Print IP address in number format */
87 unsigned int name_len
; /* Number of login name characters to print */
88 unsigned int domain_len
; /* Number of domain name characters to print */
89 unsigned int maxrecs
; /* Maximum number of records to list */
91 char **show
; /* Match search list */
93 struct timeval boot_time
; /* system boot time */
94 time_t since
; /* at what time to start displaying the file */
95 time_t until
; /* at what time to stop displaying the file */
96 time_t present
; /* who where present at time_t */
97 unsigned int time_fmt
; /* time format */
100 /* Double linked list of struct utmp's */
103 struct utmplist
*next
;
104 struct utmplist
*prev
;
107 /* Types of listing */
109 R_CRASH
= 1, /* No logout record, system boot in between */
110 R_DOWN
, /* System brought down in decent way */
111 R_NORMAL
, /* Normal */
112 R_NOW
, /* Still logged in */
113 R_REBOOT
, /* Reboot record. */
114 R_PHANTOM
, /* No logout record but session is stale. */
115 R_TIMECHANGE
/* NEW_TIME or OLD_TIME */
119 LAST_TIMEFTM_NONE
= 0,
120 LAST_TIMEFTM_SHORT_CTIME
,
121 LAST_TIMEFTM_FULL_CTIME
,
125 struct last_timefmt
{
131 static struct last_timefmt timefmts
[] = {
132 [LAST_TIMEFTM_NONE
] = { "notime", 0, 0 },
133 [LAST_TIMEFTM_SHORT_CTIME
] = { "short", 16, 7},
134 [LAST_TIMEFTM_FULL_CTIME
] = { "full", 24, 26},
135 [LAST_TIMEFTM_ISO8601
] = { "iso", 24, 26}
138 /* Global variables */
139 static unsigned int recsdone
; /* Number of records listed */
140 static time_t lastdate
; /* Last date we've seen */
141 static time_t currentdate
; /* date when we started processing the file */
143 /* --time-format=option parser */
144 static int which_time_format(const char *optarg
)
148 for (i
= 0; i
< ARRAY_SIZE(timefmts
); i
++) {
149 if (strcmp(timefmts
[i
].name
, optarg
) == 0)
152 errx(EXIT_FAILURE
, _("unknown time format: %s"), optarg
);
156 * Read one utmp entry, return in new format.
157 * Automatically reposition file pointer.
159 static int uread(FILE *fp
, struct utmp
*u
, int *quit
, const char *filename
)
162 static char buf
[UCHUNKSIZE
];
168 if (quit
== NULL
&& u
!= NULL
) {
172 return fread(u
, sizeof(struct utmp
), 1, fp
);
177 * Initialize and position.
179 utsize
= sizeof(struct utmp
);
180 fseeko(fp
, 0, SEEK_END
);
184 o
= ((fpos
- 1) / UCHUNKSIZE
) * UCHUNKSIZE
;
185 if (fseeko(fp
, o
, SEEK_SET
) < 0) {
186 warn(_("seek on %s failed"), filename
);
189 bpos
= (int)(fpos
- o
);
190 if (fread(buf
, bpos
, 1, fp
) != 1) {
191 warn(_("cannot read %s"), filename
);
199 * Read one struct. From the buffer if possible.
203 memcpy(u
, buf
+ bpos
, sizeof(struct utmp
));
208 * Oops we went "below" the buffer. We should be able to
209 * seek back UCHUNKSIZE bytes.
216 * Copy whatever is left in the buffer.
218 memcpy(tmp
+ (-bpos
), buf
, utsize
+ bpos
);
219 if (fseeko(fp
, fpos
, SEEK_SET
) < 0) {
220 warn(_("seek on %s failed"), filename
);
225 * Read another UCHUNKSIZE bytes.
227 if (fread(buf
, UCHUNKSIZE
, 1, fp
) != 1) {
228 warn(_("cannot read %s"), filename
);
233 * The end of the UCHUNKSIZE byte buffer should be the first
234 * few bytes of the current struct utmp.
236 memcpy(tmp
, buf
+ UCHUNKSIZE
+ bpos
, -bpos
);
239 memcpy(u
, tmp
, sizeof(struct utmp
));
245 * Print a short date.
247 static char *showdate(void)
249 char *s
= ctime(&lastdate
);
257 static void int_handler(int sig
__attribute__((unused
)))
259 errx(EXIT_FAILURE
, _("Interrupted %s"), showdate());
265 static void quit_handler(int sig
__attribute__((unused
)))
267 warnx(_("Interrupted %s"), showdate());
268 signal(SIGQUIT
, quit_handler
);
272 * Lookup a host with DNS.
274 static int dns_lookup(char *result
, int size
, int useip
, int32_t *a
)
276 struct sockaddr_in sin
;
277 struct sockaddr_in6 sin6
;
282 flags
= useip
? NI_NUMERICHOST
: 0;
286 * 1. If last 3 4bytes are 0, must be IPv4
287 * 2. If IPv6 in IPv4, handle as IPv4
288 * 3. Anything else is IPv6
292 if (a
[0] == 0 && a
[1] == 0 && a
[2] == (int32_t)htonl (0xffff))
295 if (mapped
|| (a
[1] == 0 && a
[2] == 0 && a
[3] == 0)) {
297 sin
.sin_family
= AF_INET
;
299 sin
.sin_addr
.s_addr
= mapped
? a
[3] : a
[0];
300 sa
= (struct sockaddr
*)&sin
;
304 memset(&sin6
, 0, sizeof(sin6
));
305 sin6
.sin6_family
= AF_INET6
;
307 memcpy(sin6
.sin6_addr
.s6_addr
, a
, 16);
308 sa
= (struct sockaddr
*)&sin6
;
309 salen
= sizeof(sin6
);
312 return getnameinfo(sa
, salen
, result
, size
, NULL
, 0, flags
);
315 static int time_formatter(const struct last_control
*ctl
, char *dst
,
316 size_t dlen
, time_t *when
, int pos
)
321 switch (ctl
->time_fmt
) {
322 case LAST_TIMEFTM_NONE
:
325 case LAST_TIMEFTM_SHORT_CTIME
:
327 ret
= sprintf(dst
, "%s", ctime(when
));
329 tm
= localtime(when
);
330 if (!strftime(dst
, dlen
, "- %H:%M", tm
))
334 case LAST_TIMEFTM_FULL_CTIME
:
336 ret
= sprintf(dst
, "%s", ctime(when
));
338 ret
= sprintf(dst
, "- %s", ctime(when
));
340 case LAST_TIMEFTM_ISO8601
:
341 tm
= localtime(when
);
343 if (!strftime(dst
, dlen
, "%Y-%m-%dT%H:%M:%S%z", tm
))
345 } else if (!strftime(dst
, dlen
, "- %Y-%m-%dT%H:%M:%S%z", tm
))
355 * Remove trailing spaces from a string.
357 static void trim_trailing_spaces(char *s
)
363 while (p
> s
&& isspace(*--p
))
372 * Show one line of information on screen
374 static int list(const struct last_control
*ctl
, struct utmp
*p
, time_t logout_time
, int what
)
376 time_t secs
, utmp_time
;
377 char logintime
[LAST_TIMESTAMP_LEN
];
378 char logouttime
[LAST_TIMESTAMP_LEN
];
379 char length
[LAST_TIMESTAMP_LEN
];
381 char utline
[UT_LINESIZE
+1];
384 int mins
, hours
, days
;
386 struct last_timefmt
*fmt
;
389 * uucp and ftp have special-type entries
392 strncat(utline
, p
->ut_line
, UT_LINESIZE
);
393 if (strncmp(utline
, "ftp", 3) == 0 && isdigit(utline
[3]))
395 if (strncmp(utline
, "uucp", 4) == 0 && isdigit(utline
[4]))
399 * Is this something we want to show?
403 for (walk
= ctl
->show
; *walk
; walk
++) {
404 if (strncmp(p
->ut_user
, *walk
, UT_NAMESIZE
) == 0 ||
405 strcmp(utline
, *walk
) == 0 ||
406 (strncmp(utline
, "tty", 3) == 0 &&
407 strcmp(utline
+ 3, *walk
) == 0)) break;
409 if (*walk
== NULL
) return 0;
415 utmp_time
= p
->UL_UT_TIME
;
418 if (ctl
->present
< utmp_time
)
420 if (0 < logout_time
&& logout_time
< ctl
->present
)
423 if (time_formatter(ctl
, &logintime
[0], sizeof(logintime
), &utmp_time
, 0) < 0 ||
424 time_formatter(ctl
, &logouttime
[0], sizeof(logouttime
), &logout_time
, 1) < 0)
425 errx(EXIT_FAILURE
, _("preallocation size exceeded"));
427 secs
= logout_time
- utmp_time
;
428 mins
= (secs
/ 60) % 60;
429 hours
= (secs
/ 3600) % 24;
432 if (logout_time
== currentdate
) {
433 if (ctl
->time_fmt
> LAST_TIMEFTM_SHORT_CTIME
) {
434 sprintf(logouttime
, " still running");
437 sprintf(logouttime
, " still");
438 sprintf(length
, "running");
441 sprintf(length
, "(%d+%02d:%02d)", days
, hours
, mins
);
443 sprintf(length
, " (%02d:%02d)", hours
, mins
);
447 sprintf(logouttime
, "- crash");
450 sprintf(logouttime
, "- down ");
453 if (ctl
->time_fmt
> LAST_TIMEFTM_SHORT_CTIME
) {
454 sprintf(logouttime
, " still logged in");
457 sprintf(logouttime
, " still");
458 sprintf(length
, "logged in");
462 if (ctl
->time_fmt
> LAST_TIMEFTM_SHORT_CTIME
) {
463 sprintf(logouttime
, " gone - no logout");
465 } else if (ctl
->time_fmt
== LAST_TIMEFTM_SHORT_CTIME
) {
466 sprintf(logouttime
, " gone");
467 sprintf(length
, "- no logout");
470 sprintf(length
, "no logout");
486 * Look up host with DNS if needed.
489 if (ctl
->usedns
|| ctl
->useip
)
490 r
= dns_lookup(domain
, sizeof(domain
), ctl
->useip
, p
->ut_addr_v6
);
493 if (len
>= (int)sizeof(domain
)) len
= sizeof(domain
) - 1;
495 strncat(domain
, p
->ut_host
, len
);
498 fmt
= &timefmts
[ctl
->time_fmt
];
502 len
= snprintf(final
, sizeof(final
),
503 "%-8.*s %-12.12s %-16.*s %-*.*s %-*.*s %s\n",
504 ctl
->name_len
, p
->ut_user
, utline
,
505 ctl
->domain_len
, domain
,
506 fmt
->in
, fmt
->in
, logintime
, fmt
->out
, fmt
->out
,
509 len
= snprintf(final
, sizeof(final
),
510 "%-8.*s %-12.12s %-*.*s %-*.*s %-12.12s %s\n",
511 ctl
->name_len
, p
->ut_user
, utline
,
512 fmt
->in
, fmt
->in
, logintime
, fmt
->out
, fmt
->out
,
513 logouttime
, length
, domain
);
516 len
= snprintf(final
, sizeof(final
),
517 "%-8.*s %-12.12s %-*.*s %-*.*s %s\n",
518 ctl
->name_len
, p
->ut_user
, utline
,
519 fmt
->in
, fmt
->in
, logintime
, fmt
->out
, fmt
->out
,
522 #if defined(__GLIBC__)
523 # if (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
524 final
[sizeof(final
)-1] = '\0';
528 trim_trailing_spaces(final
);
530 * Print out "final" string safely.
532 for (s
= final
; *s
; s
++)
533 fputc_careful(*s
, stdout
, '*');
535 if (len
< 0 || (size_t)len
>= sizeof(final
))
539 if (ctl
->maxrecs
&& ctl
->maxrecs
<= recsdone
)
546 static void __attribute__((__noreturn__
)) usage(const struct last_control
*ctl
, FILE *out
)
548 fputs(USAGE_HEADER
, out
);
550 " %s [options] [<username>...] [<tty>...]\n"), program_invocation_short_name
);
552 fputs(USAGE_SEPARATOR
, out
);
553 fputs(_("Show a listing of last logged in users.\n"), out
);
555 fputs(USAGE_OPTIONS
, out
);
556 fputs(_(" -<number> how many lines to show\n"), out
);
557 fputs(_(" -a, --hostlast display hostnames in the last column\n"), out
);
558 fputs(_(" -d, --dns translate the IP number back into a hostname\n"), out
);
560 _(" -f, --file <file> use a specific file instead of %s\n"), ctl
->lastb
? _PATH_BTMP
: _PATH_WTMP
);
561 fputs(_(" -F, --fulltimes print full login and logout times and dates\n"), out
);
562 fputs(_(" -i, --ip display IP numbers in numbers-and-dots notation\n"), out
);
563 fputs(_(" -n, --limit <number> how many lines to show\n"), out
);
564 fputs(_(" -R, --nohostname don't display the hostname field\n"), out
);
565 fputs(_(" -s, --since <time> display the lines since the specified time\n"), out
);
566 fputs(_(" -t, --until <time> display the lines until the specified time\n"), out
);
567 fputs(_(" -p, --present <time> display who were present at the specified time\n"), out
);
568 fputs(_(" -w, --fullnames display full user and domain names\n"), out
);
569 fputs(_(" -x, --system display system shutdown entries and run level changes\n"), out
);
570 fputs(_(" --time-format <format> show timestamps in the specified <format>:\n"
571 " notime|short|full|iso\n"), out
);
573 fputs(USAGE_SEPARATOR
, out
);
574 fputs(USAGE_HELP
, out
);
575 fputs(USAGE_VERSION
, out
);
576 fprintf(out
, USAGE_MAN_TAIL("last(1)"));
578 exit(out
== stderr
? EXIT_FAILURE
: EXIT_SUCCESS
);
581 static int is_phantom(const struct last_control
*ctl
, struct utmp
*ut
)
587 if (ut
->UL_UT_TIME
< ctl
->boot_time
.tv_sec
)
589 pw
= getpwnam(ut
->ut_user
);
592 sprintf(path
, "/proc/%u/loginuid", ut
->ut_pid
);
593 if (access(path
, R_OK
) == 0) {
594 unsigned int loginuid
;
597 if (!(f
= fopen(path
, "r")))
599 if (fscanf(f
, "%u", &loginuid
) != 1)
602 if (!ret
&& pw
->pw_uid
!= loginuid
)
607 sprintf(path
, "/dev/%s", ut
->ut_line
);
610 if (pw
->pw_uid
!= st
.st_uid
)
616 static void process_wtmp_file(const struct last_control
*ctl
,
617 const char *filename
)
619 FILE *fp
; /* Filepointer of wtmp file */
621 struct utmp ut
; /* Current utmp entry */
622 struct utmplist
*ulist
= NULL
; /* All entries */
623 struct utmplist
*p
; /* Pointer into utmplist */
624 struct utmplist
*next
; /* Pointer into utmplist */
626 time_t lastboot
= 0; /* Last boottime */
627 time_t lastrch
= 0; /* Last run level change */
628 time_t lastdown
; /* Last downtime */
629 time_t begintime
; /* When wtmp begins */
630 int whydown
= 0; /* Why we went down: crash or shutdown */
632 int c
, x
; /* Scratch */
633 struct stat st
; /* To stat the [uw]tmp file */
634 int quit
= 0; /* Flag */
635 int down
= 0; /* Down flag */
641 lastdate
= currentdate
= lastrch
= lastdown
;
644 * Install signal handlers
646 signal(SIGINT
, int_handler
);
647 signal(SIGQUIT
, quit_handler
);
652 if ((fp
= fopen(filename
, "r")) == NULL
)
653 err(EXIT_FAILURE
, _("cannot open %s"), filename
);
656 * Optimize the buffer size.
658 setvbuf(fp
, NULL
, _IOFBF
, UCHUNKSIZE
);
661 * Read first structure to capture the time field
663 if (uread(fp
, &ut
, NULL
, filename
) == 1)
664 begintime
= ut
.UL_UT_TIME
;
666 if (fstat(fileno(fp
), &st
) != 0)
667 err(EXIT_FAILURE
, _("stat of %s failed"), filename
);
668 begintime
= st
.st_ctime
;
673 * Go to end of file minus one structure
674 * and/or initialize utmp reading code.
676 uread(fp
, NULL
, NULL
, filename
);
679 * Read struct after struct backwards from the file.
683 if (uread(fp
, &ut
, &quit
, filename
) != 1)
686 if (ctl
->since
&& ut
.UL_UT_TIME
< ctl
->since
)
689 if (ctl
->until
&& ctl
->until
< ut
.UL_UT_TIME
)
692 lastdate
= ut
.UL_UT_TIME
;
695 quit
= list(ctl
, &ut
, ut
.UL_UT_TIME
, R_NORMAL
);
700 * Set ut_type to the correct type.
702 if (strncmp(ut
.ut_line
, "~", 1) == 0) {
703 if (strncmp(ut
.ut_user
, "shutdown", 8) == 0)
704 ut
.ut_type
= SHUTDOWN_TIME
;
705 else if (strncmp(ut
.ut_user
, "reboot", 6) == 0)
706 ut
.ut_type
= BOOT_TIME
;
707 else if (strncmp(ut
.ut_user
, "runlevel", 8) == 0)
708 ut
.ut_type
= RUN_LVL
;
712 * For stupid old applications that don't fill in
716 if (ut
.ut_type
!= DEAD_PROCESS
&&
717 ut
.ut_user
[0] && ut
.ut_line
[0] &&
718 strcmp(ut
.ut_user
, "LOGIN") != 0)
719 ut
.ut_type
= USER_PROCESS
;
721 * Even worse, applications that write ghost
722 * entries: ut_type set to USER_PROCESS but
725 if (ut
.ut_user
[0] == 0)
726 ut
.ut_type
= DEAD_PROCESS
;
731 if (strcmp(ut
.ut_user
, "date") == 0) {
732 if (ut
.ut_line
[0] == '|')
733 ut
.ut_type
= OLD_TIME
;
734 if (ut
.ut_line
[0] == '{')
735 ut
.ut_type
= NEW_TIME
;
739 switch (ut
.ut_type
) {
742 strcpy(ut
.ut_line
, "system down");
743 quit
= list(ctl
, &ut
, lastboot
, R_NORMAL
);
745 lastdown
= lastrch
= ut
.UL_UT_TIME
;
752 ut
.ut_type
== NEW_TIME
? "new time" :
754 quit
= list(ctl
, &ut
, lastdown
, R_TIMECHANGE
);
758 strcpy(ut
.ut_line
, "system boot");
759 quit
= list(ctl
, &ut
, lastdown
, R_REBOOT
);
760 lastboot
= ut
.UL_UT_TIME
;
766 sprintf(ut
.ut_line
, "(to lvl %c)", x
);
767 quit
= list(ctl
, &ut
, lastrch
, R_NORMAL
);
769 if (x
== '0' || x
== '6') {
770 lastdown
= ut
.UL_UT_TIME
;
772 ut
.ut_type
= SHUTDOWN_TIME
;
774 lastrch
= ut
.UL_UT_TIME
;
779 * This was a login - show the first matching
780 * logout record and delete all records with
784 for (p
= ulist
; p
; p
= next
) {
786 if (strncmp(p
->ut
.ut_line
, ut
.ut_line
,
790 quit
= list(ctl
, &ut
, p
->ut
.UL_UT_TIME
, R_NORMAL
);
794 p
->next
->prev
= p
->prev
;
796 p
->prev
->next
= p
->next
;
803 * Not found? Then crashed, down, still
804 * logged in, or missing logout record.
809 /* Is process still alive? */
810 if (is_phantom(ctl
, &ut
))
814 quit
= list(ctl
, &ut
, lastboot
, c
);
820 * Just store the data if it is
821 * interesting enough.
823 if (ut
.ut_line
[0] == 0)
825 p
= xmalloc(sizeof(struct utmplist
));
826 memcpy(&p
->ut
, &ut
, sizeof(struct utmp
));
838 /* ignored ut_types */
842 warnx("unrecogized ut_type: %d", ut
.ut_type
);
846 * If we saw a shutdown/reboot record we can remove
847 * the entire current ulist.
850 lastboot
= ut
.UL_UT_TIME
;
851 whydown
= (ut
.ut_type
== SHUTDOWN_TIME
) ? R_DOWN
: R_CRASH
;
852 for (p
= ulist
; p
; p
= next
) {
861 printf(_("\n%s begins %s"), basename(filename
), ctime(&begintime
));
864 for (p
= ulist
; p
; p
= next
) {
870 int main(int argc
, char **argv
)
872 struct last_control ctl
= {
874 .name_len
= LAST_LOGIN_LEN
,
875 .time_fmt
= LAST_TIMEFTM_SHORT_CTIME
,
876 .domain_len
= LAST_DOMAIN_LEN
879 size_t i
, nfiles
= 0;
884 OPT_TIME_FORMAT
= CHAR_MAX
+ 1
886 static const struct option long_opts
[] = {
887 { "limit", required_argument
, NULL
, 'n' },
888 { "help", no_argument
, NULL
, 'h' },
889 { "file", required_argument
, NULL
, 'f' },
890 { "nohostname", no_argument
, NULL
, 'R' },
891 { "version", no_argument
, NULL
, 'V' },
892 { "hostlast", no_argument
, NULL
, 'a' },
893 { "since", required_argument
, NULL
, 's' },
894 { "until", required_argument
, NULL
, 't' },
895 { "present", required_argument
, NULL
, 'p' },
896 { "system", no_argument
, NULL
, 'x' },
897 { "dns", no_argument
, NULL
, 'd' },
898 { "ip", no_argument
, NULL
, 'i' },
899 { "fulltimes", no_argument
, NULL
, 'F' },
900 { "fullnames", no_argument
, NULL
, 'w' },
901 { "time-format", required_argument
, NULL
, OPT_TIME_FORMAT
},
904 static const ul_excl_t excl
[] = { /* rows and cols in in ASCII order */
905 { 'F', OPT_TIME_FORMAT
}, /* fulltime, time-format */
908 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
910 setlocale(LC_ALL
, "");
911 bindtextdomain(PACKAGE
, LOCALEDIR
);
913 atexit(close_stdout
);
915 * Which file do we want to read?
917 ctl
.lastb
= strcmp(program_invocation_short_name
, "lastb") == 0 ? 1 : 0;
918 while ((c
= getopt_long(argc
, argv
,
919 "hVf:n:RxadFit:p:s:0123456789w", long_opts
, NULL
)) != -1) {
921 err_exclusive_options(c
, long_opts
, excl
, excl_st
);
928 printf(UTIL_LINUX_VERSION
);
937 ctl
.maxrecs
= strtos32_or_err(optarg
, _("failed to parse number"));
941 files
= xmalloc(sizeof(char *) * argc
);
942 files
[nfiles
++] = xstrdup(optarg
);
954 ctl
.time_fmt
= LAST_TIMEFTM_FULL_CTIME
;
957 if (parse_timestamp(optarg
, &p
) < 0)
958 errx(EXIT_FAILURE
, _("invalid time value \"%s\""), optarg
);
959 ctl
.present
= (time_t) (p
/ 1000000);
962 if (parse_timestamp(optarg
, &p
) < 0)
963 errx(EXIT_FAILURE
, _("invalid time value \"%s\""), optarg
);
964 ctl
.since
= (time_t) (p
/ 1000000);
967 if (parse_timestamp(optarg
, &p
) < 0)
968 errx(EXIT_FAILURE
, _("invalid time value \"%s\""), optarg
);
969 ctl
.until
= (time_t) (p
/ 1000000);
972 if (ctl
.name_len
< UT_NAMESIZE
)
973 ctl
.name_len
= UT_NAMESIZE
;
974 if (ctl
.domain_len
< UT_HOSTSIZE
)
975 ctl
.domain_len
= UT_HOSTSIZE
;
977 case '0': case '1': case '2': case '3': case '4':
978 case '5': case '6': case '7': case '8': case '9':
979 ctl
.maxrecs
= 10 * ctl
.maxrecs
+ c
- '0';
981 case OPT_TIME_FORMAT
:
982 ctl
.time_fmt
= which_time_format(optarg
);
991 ctl
.show
= argv
+ optind
;
994 files
= xmalloc(sizeof(char *));
995 files
[nfiles
++] = xstrdup(ctl
.lastb
? _PATH_BTMP
: _PATH_WTMP
);
998 for (i
= 0; i
< nfiles
; i
++) {
999 get_boot_time(&ctl
.boot_time
);
1000 process_wtmp_file(&ctl
, files
[i
]);
1004 return EXIT_SUCCESS
;