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 char **altv
; /* Alternate wtmp files */
94 unsigned int altc
; /* Number of alternative files */
95 unsigned int alti
; /* Index number of the alternative file */
97 struct timeval boot_time
; /* system boot time */
98 time_t since
; /* at what time to start displaying the file */
99 time_t until
; /* at what time to stop displaying the file */
100 time_t present
; /* who where present at time_t */
101 unsigned int time_fmt
; /* time format */
104 /* Double linked list of struct utmp's */
107 struct utmplist
*next
;
108 struct utmplist
*prev
;
111 /* Types of listing */
113 R_CRASH
= 1, /* No logout record, system boot in between */
114 R_DOWN
, /* System brought down in decent way */
115 R_NORMAL
, /* Normal */
116 R_NOW
, /* Still logged in */
117 R_REBOOT
, /* Reboot record. */
118 R_PHANTOM
, /* No logout record but session is stale. */
119 R_TIMECHANGE
/* NEW_TIME or OLD_TIME */
123 LAST_TIMEFTM_NONE
= 0,
124 LAST_TIMEFTM_SHORT_CTIME
,
125 LAST_TIMEFTM_FULL_CTIME
,
129 struct last_timefmt
{
135 static struct last_timefmt timefmts
[] = {
136 [LAST_TIMEFTM_NONE
] = { "notime", 0, 0 },
137 [LAST_TIMEFTM_SHORT_CTIME
] = { "short", 16, 7},
138 [LAST_TIMEFTM_FULL_CTIME
] = { "full", 24, 26},
139 [LAST_TIMEFTM_ISO8601
] = { "iso", 24, 26}
142 /* Global variables */
143 static unsigned int recsdone
; /* Number of records listed */
144 static time_t lastdate
; /* Last date we've seen */
146 /* --time-format=option parser */
147 static int which_time_format(const char *optarg
)
151 for (i
= 0; i
< ARRAY_SIZE(timefmts
); i
++) {
152 if (strcmp(timefmts
[i
].name
, optarg
) == 0)
155 errx(EXIT_FAILURE
, _("unknown time format: %s"), optarg
);
159 * Read one utmp entry, return in new format.
160 * Automatically reposition file pointer.
162 static int uread(const struct last_control
*ctl
, FILE *fp
, struct utmp
*u
,
166 static char buf
[UCHUNKSIZE
];
172 if (quit
== NULL
&& u
!= NULL
) {
176 return fread(u
, sizeof(struct utmp
), 1, fp
);
181 * Initialize and position.
183 utsize
= sizeof(struct utmp
);
184 fseeko(fp
, 0, SEEK_END
);
188 o
= ((fpos
- 1) / UCHUNKSIZE
) * UCHUNKSIZE
;
189 if (fseeko(fp
, o
, SEEK_SET
) < 0) {
190 warn(_("seek on %s failed"), ctl
->altv
[ctl
->alti
]);
193 bpos
= (int)(fpos
- o
);
194 if (fread(buf
, bpos
, 1, fp
) != 1) {
195 warn(_("cannot read %s"), ctl
->altv
[ctl
->alti
]);
203 * Read one struct. From the buffer if possible.
207 memcpy(u
, buf
+ bpos
, sizeof(struct utmp
));
212 * Oops we went "below" the buffer. We should be able to
213 * seek back UCHUNKSIZE bytes.
220 * Copy whatever is left in the buffer.
222 memcpy(tmp
+ (-bpos
), buf
, utsize
+ bpos
);
223 if (fseeko(fp
, fpos
, SEEK_SET
) < 0) {
224 warn(_("seek on %s failed"), ctl
->altv
[ctl
->alti
]);
229 * Read another UCHUNKSIZE bytes.
231 if (fread(buf
, UCHUNKSIZE
, 1, fp
) != 1) {
232 warn(_("cannot read %s"), ctl
->altv
[ctl
->alti
]);
237 * The end of the UCHUNKSIZE byte buffer should be the first
238 * few bytes of the current struct utmp.
240 memcpy(tmp
, buf
+ UCHUNKSIZE
+ bpos
, -bpos
);
243 memcpy(u
, tmp
, sizeof(struct utmp
));
249 * Print a short date.
251 static char *showdate(void)
253 char *s
= ctime(&lastdate
);
261 static void int_handler(int sig
__attribute__((unused
)))
263 errx(EXIT_FAILURE
, _("Interrupted %s"), showdate());
269 static void quit_handler(int sig
__attribute__((unused
)))
271 warnx(_("Interrupted %s"), showdate());
272 signal(SIGQUIT
, quit_handler
);
276 * Lookup a host with DNS.
278 static int dns_lookup(char *result
, int size
, int useip
, int32_t *a
)
280 struct sockaddr_in sin
;
281 struct sockaddr_in6 sin6
;
286 flags
= useip
? NI_NUMERICHOST
: 0;
290 * 1. If last 3 4bytes are 0, must be IPv4
291 * 2. If IPv6 in IPv4, handle as IPv4
292 * 3. Anything else is IPv6
296 if (a
[0] == 0 && a
[1] == 0 && a
[2] == (int32_t)htonl (0xffff))
299 if (mapped
|| (a
[1] == 0 && a
[2] == 0 && a
[3] == 0)) {
301 sin
.sin_family
= AF_INET
;
303 sin
.sin_addr
.s_addr
= mapped
? a
[3] : a
[0];
304 sa
= (struct sockaddr
*)&sin
;
308 memset(&sin6
, 0, sizeof(sin6
));
309 sin6
.sin6_family
= AF_INET6
;
311 memcpy(sin6
.sin6_addr
.s6_addr
, a
, 16);
312 sa
= (struct sockaddr
*)&sin6
;
313 salen
= sizeof(sin6
);
316 return getnameinfo(sa
, salen
, result
, size
, NULL
, 0, flags
);
319 static int time_formatter(const struct last_control
*ctl
, char *dst
,
320 size_t dlen
, time_t *when
, int pos
)
325 switch (ctl
->time_fmt
) {
326 case LAST_TIMEFTM_NONE
:
329 case LAST_TIMEFTM_SHORT_CTIME
:
331 ret
= sprintf(dst
, "%s", ctime(when
));
333 tm
= localtime(when
);
334 if (!strftime(dst
, dlen
, "- %H:%M", tm
))
338 case LAST_TIMEFTM_FULL_CTIME
:
340 ret
= sprintf(dst
, "%s", ctime(when
));
342 ret
= sprintf(dst
, "- %s", ctime(when
));
344 case LAST_TIMEFTM_ISO8601
:
345 tm
= localtime(when
);
347 if (!strftime(dst
, dlen
, "%Y-%m-%dT%H:%M:%S%z", tm
))
349 } else if (!strftime(dst
, dlen
, "- %Y-%m-%dT%H:%M:%S%z", tm
))
359 * Remove trailing spaces from a string.
361 static void trim_trailing_spaces(char *s
)
367 while (p
> s
&& isspace(*--p
))
376 * Show one line of information on screen
378 static int list(const struct last_control
*ctl
, struct utmp
*p
, time_t logout_time
, int what
)
380 time_t secs
, utmp_time
, now
;
381 char logintime
[LAST_TIMESTAMP_LEN
];
382 char logouttime
[LAST_TIMESTAMP_LEN
];
383 char length
[LAST_TIMESTAMP_LEN
];
385 char utline
[UT_LINESIZE
+1];
388 int mins
, hours
, days
;
390 struct last_timefmt
*fmt
;
393 * uucp and ftp have special-type entries
396 strncat(utline
, p
->ut_line
, UT_LINESIZE
);
397 if (strncmp(utline
, "ftp", 3) == 0 && isdigit(utline
[3]))
399 if (strncmp(utline
, "uucp", 4) == 0 && isdigit(utline
[4]))
403 * Is this something we want to show?
407 for (walk
= ctl
->show
; *walk
; walk
++) {
408 if (strncmp(p
->ut_user
, *walk
, UT_NAMESIZE
) == 0 ||
409 strcmp(utline
, *walk
) == 0 ||
410 (strncmp(utline
, "tty", 3) == 0 &&
411 strcmp(utline
+ 3, *walk
) == 0)) break;
413 if (*walk
== NULL
) return 0;
419 utmp_time
= p
->UL_UT_TIME
;
422 if (ctl
->present
< utmp_time
)
424 if (0 < logout_time
&& logout_time
< ctl
->present
)
427 if (time_formatter(ctl
, &logintime
[0], sizeof(logintime
), &utmp_time
, 0) < 0 ||
428 time_formatter(ctl
, &logouttime
[0], sizeof(logouttime
), &logout_time
, 1) < 0)
429 errx(EXIT_FAILURE
, _("preallocation size exceeded"));
431 secs
= logout_time
- utmp_time
;
432 mins
= (secs
/ 60) % 60;
433 hours
= (secs
/ 3600) % 24;
437 if (logout_time
== now
) {
438 if (ctl
->time_fmt
> LAST_TIMEFTM_SHORT_CTIME
) {
439 sprintf(logouttime
, " still running");
442 sprintf(logouttime
, " still");
443 sprintf(length
, "running");
446 sprintf(length
, "(%d+%02d:%02d)", days
, hours
, mins
);
448 sprintf(length
, " (%02d:%02d)", hours
, mins
);
452 sprintf(logouttime
, "- crash");
455 sprintf(logouttime
, "- down ");
458 if (ctl
->time_fmt
> LAST_TIMEFTM_SHORT_CTIME
) {
459 sprintf(logouttime
, " still logged in");
462 sprintf(logouttime
, " still");
463 sprintf(length
, "logged in");
467 if (ctl
->time_fmt
> LAST_TIMEFTM_SHORT_CTIME
) {
468 sprintf(logouttime
, " gone - no logout");
470 } else if (ctl
->time_fmt
== LAST_TIMEFTM_SHORT_CTIME
) {
471 sprintf(logouttime
, " gone");
472 sprintf(length
, "- no logout");
475 sprintf(length
, "no logout");
491 * Look up host with DNS if needed.
494 if (ctl
->usedns
|| ctl
->useip
)
495 r
= dns_lookup(domain
, sizeof(domain
), ctl
->useip
, p
->ut_addr_v6
);
498 if (len
>= (int)sizeof(domain
)) len
= sizeof(domain
) - 1;
500 strncat(domain
, p
->ut_host
, len
);
503 fmt
= &timefmts
[ctl
->time_fmt
];
507 len
= snprintf(final
, sizeof(final
),
508 "%-8.*s %-12.12s %-16.*s %-*.*s %-*.*s %s\n",
509 ctl
->name_len
, p
->ut_user
, utline
,
510 ctl
->domain_len
, domain
,
511 fmt
->in
, fmt
->in
, logintime
, fmt
->out
, fmt
->out
,
514 len
= snprintf(final
, sizeof(final
),
515 "%-8.*s %-12.12s %-*.*s %-*.*s %-12.12s %s\n",
516 ctl
->name_len
, p
->ut_user
, utline
,
517 fmt
->in
, fmt
->in
, logintime
, fmt
->out
, fmt
->out
,
518 logouttime
, length
, domain
);
521 len
= snprintf(final
, sizeof(final
),
522 "%-8.*s %-12.12s %-*.*s %-*.*s %s\n",
523 ctl
->name_len
, p
->ut_user
, utline
,
524 fmt
->in
, fmt
->in
, logintime
, fmt
->out
, fmt
->out
,
527 #if defined(__GLIBC__)
528 # if (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
529 final
[sizeof(final
)-1] = '\0';
533 trim_trailing_spaces(final
);
535 * Print out "final" string safely.
537 for (s
= final
; *s
; s
++)
538 fputc_careful(*s
, stdout
, '*');
540 if (len
< 0 || (size_t)len
>= sizeof(final
))
544 if (ctl
->maxrecs
&& ctl
->maxrecs
<= recsdone
)
551 static void __attribute__((__noreturn__
)) usage(FILE *out
)
553 fputs(USAGE_HEADER
, out
);
555 " %s [options] [<username>...] [<tty>...]\n"), program_invocation_short_name
);
557 fputs(USAGE_SEPARATOR
, out
);
558 fputs(_("Show a listing of last logged in users.\n"), out
);
560 fputs(USAGE_OPTIONS
, out
);
561 fputs(_(" -<number> how many lines to show\n"), out
);
562 fputs(_(" -a, --hostlast display hostnames in the last column\n"), out
);
563 fputs(_(" -d, --dns translate the IP number back into a hostname\n"), out
);
565 _(" -f, --file <file> use a specific file instead of %s\n"), _PATH_WTMP
);
566 fputs(_(" -F, --fulltimes print full login and logout times and dates\n"), out
);
567 fputs(_(" -i, --ip display IP numbers in numbers-and-dots notation\n"), out
);
568 fputs(_(" -n, --limit <number> how many lines to show\n"), out
);
569 fputs(_(" -R, --nohostname don't display the hostname field\n"), out
);
570 fputs(_(" -s, --since <time> display the lines since the specified time\n"), out
);
571 fputs(_(" -t, --until <time> display the lines until the specified time\n"), out
);
572 fputs(_(" -p, --present <time> display who were present at the specified time\n"), out
);
573 fputs(_(" -w, --fullnames display full user and domain names\n"), out
);
574 fputs(_(" -x, --system display system shutdown entries and run level changes\n"), out
);
575 fputs(_(" --time-format <format> show timestamps in the specified <format>:\n"
576 " notime|short|full|iso\n"), out
);
578 fputs(USAGE_SEPARATOR
, out
);
579 fputs(USAGE_HELP
, out
);
580 fputs(USAGE_VERSION
, out
);
581 fprintf(out
, USAGE_MAN_TAIL("last(1)"));
583 exit(out
== stderr
? EXIT_FAILURE
: EXIT_SUCCESS
);
586 static int is_phantom(const struct last_control
*ctl
, struct utmp
*ut
)
592 if (ut
->UL_UT_TIME
< ctl
->boot_time
.tv_sec
)
594 pw
= getpwnam(ut
->ut_name
);
597 sprintf(path
, "/proc/%u/loginuid", ut
->ut_pid
);
598 if (access(path
, R_OK
) == 0) {
599 unsigned int loginuid
;
602 if (!(f
= fopen(path
, "r")))
604 if (fscanf(f
, "%u", &loginuid
) != 1)
607 if (!ret
&& pw
->pw_uid
!= loginuid
)
612 sprintf(path
, "/dev/%s", ut
->ut_line
);
615 if (pw
->pw_uid
!= st
.st_uid
)
621 static void process_wtmp_file(const struct last_control
*ctl
)
623 FILE *fp
; /* Filepointer of wtmp file */
626 struct utmp ut
; /* Current utmp entry */
627 struct utmplist
*ulist
= NULL
; /* All entries */
628 struct utmplist
*p
; /* Pointer into utmplist */
629 struct utmplist
*next
; /* Pointer into utmplist */
631 time_t lastboot
= 0; /* Last boottime */
632 time_t lastrch
= 0; /* Last run level change */
633 time_t lastdown
; /* Last downtime */
634 time_t begintime
; /* When wtmp begins */
635 int whydown
= 0; /* Why we went down: crash or shutdown */
637 int c
, x
; /* Scratch */
638 struct stat st
; /* To stat the [uw]tmp file */
639 int quit
= 0; /* Flag */
640 int down
= 0; /* Down flag */
644 filename
= ctl
->altv
[ctl
->alti
];
652 * Install signal handlers
654 signal(SIGINT
, int_handler
);
655 signal(SIGQUIT
, quit_handler
);
660 if ((fp
= fopen(filename
, "r")) == NULL
)
661 err(EXIT_FAILURE
, _("cannot open %s"), filename
);
664 * Optimize the buffer size.
666 setvbuf(fp
, NULL
, _IOFBF
, UCHUNKSIZE
);
669 * Read first structure to capture the time field
671 if (uread(ctl
, fp
, &ut
, NULL
) == 1)
672 begintime
= ut
.UL_UT_TIME
;
674 if (fstat(fileno(fp
), &st
) != 0)
675 err(EXIT_FAILURE
, _("stat of %s failed"), filename
);
676 begintime
= st
.st_ctime
;
681 * Go to end of file minus one structure
682 * and/or initialize utmp reading code.
684 uread(ctl
, fp
, NULL
, NULL
);
687 * Read struct after struct backwards from the file.
691 if (uread(ctl
, fp
, &ut
, &quit
) != 1)
694 if (ctl
->since
&& ut
.UL_UT_TIME
< ctl
->since
)
697 if (ctl
->until
&& ctl
->until
< ut
.UL_UT_TIME
)
700 lastdate
= ut
.UL_UT_TIME
;
703 quit
= list(ctl
, &ut
, ut
.UL_UT_TIME
, R_NORMAL
);
708 * Set ut_type to the correct type.
710 if (strncmp(ut
.ut_line
, "~", 1) == 0) {
711 if (strncmp(ut
.ut_user
, "shutdown", 8) == 0)
712 ut
.ut_type
= SHUTDOWN_TIME
;
713 else if (strncmp(ut
.ut_user
, "reboot", 6) == 0)
714 ut
.ut_type
= BOOT_TIME
;
715 else if (strncmp(ut
.ut_user
, "runlevel", 8) == 0)
716 ut
.ut_type
= RUN_LVL
;
720 * For stupid old applications that don't fill in
724 if (ut
.ut_type
!= DEAD_PROCESS
&&
725 ut
.ut_user
[0] && ut
.ut_line
[0] &&
726 strcmp(ut
.ut_user
, "LOGIN") != 0)
727 ut
.ut_type
= USER_PROCESS
;
729 * Even worse, applications that write ghost
730 * entries: ut_type set to USER_PROCESS but
733 if (ut
.ut_user
[0] == 0)
734 ut
.ut_type
= DEAD_PROCESS
;
739 if (strcmp(ut
.ut_user
, "date") == 0) {
740 if (ut
.ut_line
[0] == '|')
741 ut
.ut_type
= OLD_TIME
;
742 if (ut
.ut_line
[0] == '{')
743 ut
.ut_type
= NEW_TIME
;
747 switch (ut
.ut_type
) {
750 strcpy(ut
.ut_line
, "system down");
751 quit
= list(ctl
, &ut
, lastboot
, R_NORMAL
);
753 lastdown
= lastrch
= ut
.UL_UT_TIME
;
760 ut
.ut_type
== NEW_TIME
? "new time" :
762 quit
= list(ctl
, &ut
, lastdown
, R_TIMECHANGE
);
766 strcpy(ut
.ut_line
, "system boot");
767 quit
= list(ctl
, &ut
, lastdown
, R_REBOOT
);
768 lastboot
= ut
.UL_UT_TIME
;
774 sprintf(ut
.ut_line
, "(to lvl %c)", x
);
775 quit
= list(ctl
, &ut
, lastrch
, R_NORMAL
);
777 if (x
== '0' || x
== '6') {
778 lastdown
= ut
.UL_UT_TIME
;
780 ut
.ut_type
= SHUTDOWN_TIME
;
782 lastrch
= ut
.UL_UT_TIME
;
787 * This was a login - show the first matching
788 * logout record and delete all records with
792 for (p
= ulist
; p
; p
= next
) {
794 if (strncmp(p
->ut
.ut_line
, ut
.ut_line
,
798 quit
= list(ctl
, &ut
, p
->ut
.UL_UT_TIME
, R_NORMAL
);
802 p
->next
->prev
= p
->prev
;
804 p
->prev
->next
= p
->next
;
811 * Not found? Then crashed, down, still
812 * logged in, or missing logout record.
817 /* Is process still alive? */
818 if (is_phantom(ctl
, &ut
))
822 quit
= list(ctl
, &ut
, lastboot
, c
);
828 * Just store the data if it is
829 * interesting enough.
831 if (ut
.ut_line
[0] == 0)
833 p
= xmalloc(sizeof(struct utmplist
));
834 memcpy(&p
->ut
, &ut
, sizeof(struct utmp
));
846 /* ignored ut_types */
850 warnx("unrecogized ut_type: %d", ut
.ut_type
);
854 * If we saw a shutdown/reboot record we can remove
855 * the entire current ulist.
858 lastboot
= ut
.UL_UT_TIME
;
859 whydown
= (ut
.ut_type
== SHUTDOWN_TIME
) ? R_DOWN
: R_CRASH
;
860 for (p
= ulist
; p
; p
= next
) {
869 printf(_("\n%s begins %s"), basename(filename
), ctime(&begintime
));
872 for (p
= ulist
; p
; p
= next
) {
878 int main(int argc
, char **argv
)
880 struct last_control ctl
= {
882 .name_len
= LAST_LOGIN_LEN
,
883 .time_fmt
= LAST_TIMEFTM_SHORT_CTIME
,
884 .domain_len
= LAST_DOMAIN_LEN
890 OPT_TIME_FORMAT
= CHAR_MAX
+ 1
892 static const struct option long_opts
[] = {
893 { "limit", required_argument
, NULL
, 'n' },
894 { "help", no_argument
, NULL
, 'h' },
895 { "file", required_argument
, NULL
, 'f' },
896 { "nohostname", no_argument
, NULL
, 'R' },
897 { "version", no_argument
, NULL
, 'V' },
898 { "hostlast", no_argument
, NULL
, 'a' },
899 { "since", required_argument
, NULL
, 's' },
900 { "until", required_argument
, NULL
, 't' },
901 { "present", required_argument
, NULL
, 'p' },
902 { "system", no_argument
, NULL
, 'x' },
903 { "dns", no_argument
, NULL
, 'd' },
904 { "ip", no_argument
, NULL
, 'i' },
905 { "fulltimes", no_argument
, NULL
, 'F' },
906 { "fullnames", no_argument
, NULL
, 'w' },
907 { "time-format", required_argument
, NULL
, OPT_TIME_FORMAT
},
910 static const ul_excl_t excl
[] = { /* rows and cols in in ASCII order */
911 { 'F', OPT_TIME_FORMAT
}, /* fulltime, time-format */
914 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
916 setlocale(LC_ALL
, "");
917 bindtextdomain(PACKAGE
, LOCALEDIR
);
919 atexit(close_stdout
);
921 while ((c
= getopt_long(argc
, argv
,
922 "hVf:n:RxadFit:p:s:0123456789w", long_opts
, NULL
)) != -1) {
924 err_exclusive_options(c
, long_opts
, excl
, excl_st
);
931 printf(UTIL_LINUX_VERSION
);
940 ctl
.maxrecs
= strtos32_or_err(optarg
, _("failed to parse number"));
944 ctl
.altv
= xmalloc(sizeof(char *) * argc
);
945 ctl
.altv
[ctl
.altc
++] = xstrdup(optarg
);
957 ctl
.time_fmt
= LAST_TIMEFTM_FULL_CTIME
;
960 if (parse_timestamp(optarg
, &p
) < 0)
961 errx(EXIT_FAILURE
, _("invalid time value \"%s\""), optarg
);
962 ctl
.present
= (time_t) (p
/ 1000000);
965 if (parse_timestamp(optarg
, &p
) < 0)
966 errx(EXIT_FAILURE
, _("invalid time value \"%s\""), optarg
);
967 ctl
.since
= (time_t) (p
/ 1000000);
970 if (parse_timestamp(optarg
, &p
) < 0)
971 errx(EXIT_FAILURE
, _("invalid time value \"%s\""), optarg
);
972 ctl
.until
= (time_t) (p
/ 1000000);
975 if (ctl
.name_len
< UT_NAMESIZE
)
976 ctl
.name_len
= UT_NAMESIZE
;
977 if (ctl
.domain_len
< UT_HOSTSIZE
)
978 ctl
.domain_len
= UT_HOSTSIZE
;
980 case '0': case '1': case '2': case '3': case '4':
981 case '5': case '6': case '7': case '8': case '9':
982 ctl
.maxrecs
= 10 * ctl
.maxrecs
+ c
- '0';
984 case OPT_TIME_FORMAT
:
985 ctl
.time_fmt
= which_time_format(optarg
);
994 ctl
.show
= argv
+ optind
;
997 * Which file do we want to read?
999 ctl
.lastb
= strcmp(program_invocation_short_name
, "lastb") == 0 ? 1 : 0;
1001 ctl
.altv
= xmalloc(sizeof(char *));
1003 ctl
.altv
[0] = xstrdup(_PATH_BTMP
);
1005 ctl
.altv
[0] = xstrdup(_PATH_WTMP
);
1009 for (ctl
.alti
= 0; ctl
.alti
< ctl
.altc
; ctl
.alti
++) {
1010 get_boot_time(&ctl
.boot_time
);
1011 process_wtmp_file(&ctl
);
1012 free(ctl
.altv
[ctl
.alti
]);
1015 return EXIT_SUCCESS
;