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