|
Packit |
6c4009 |
/* utmpdump - dump utmp-like files.
|
|
Packit |
6c4009 |
Copyright (C) 1997-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <time.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
#include <utmp.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static void
|
|
Packit |
6c4009 |
print_entry (struct utmp *up)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Mixed 32-/64-bit systems may have timeval structs of different sixe
|
|
Packit |
6c4009 |
but need struct utmp to be the same size. So in 64-bit up->ut_tv may
|
|
Packit |
6c4009 |
not be a timeval but a struct of __int32_t's. This would cause a compile
|
|
Packit |
6c4009 |
time warning and a formating error when 32-bit int is passed where
|
|
Packit |
6c4009 |
a 64-bit long is expected. So copy up->up_tv to a temporary timeval.
|
|
Packit |
6c4009 |
This is 32-/64-bit agnostic and expands the timeval fields to the
|
|
Packit |
6c4009 |
expected size as needed. */
|
|
Packit |
6c4009 |
struct timeval temp_tv;
|
|
Packit |
6c4009 |
temp_tv.tv_sec = up->ut_tv.tv_sec;
|
|
Packit |
6c4009 |
temp_tv.tv_usec = up->ut_tv.tv_usec;
|
|
Packit |
6c4009 |
|
|
Packit Service |
66ff64 |
printf ("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-16.16s] [%-15.15s]"
|
|
Packit Service |
66ff64 |
" [%ld]\n",
|
|
Packit Service |
66ff64 |
up->ut_type, up->ut_pid, up->ut_id, up->ut_user, up->ut_line,
|
|
Packit Service |
66ff64 |
up->ut_host, 4 + ctime (&temp_tv.tv_sec),
|
|
Packit Service |
66ff64 |
(long int) temp_tv.tv_usec);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
main (int argc, char *argv[])
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct utmp *up;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (argc > 1)
|
|
Packit |
6c4009 |
utmpname (argv[1]);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
setutent ();
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
while ((up = getutent ()))
|
|
Packit |
6c4009 |
print_entry (up);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
endutent ();
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return EXIT_SUCCESS;
|
|
Packit |
6c4009 |
}
|