aboutsummaryrefslogtreecommitdiff
path: root/dutmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'dutmp.c')
-rw-r--r--dutmp.c61
1 files changed, 33 insertions, 28 deletions
diff --git a/dutmp.c b/dutmp.c
index e92b6700f..2dad7d4a5 100644
--- a/dutmp.c
+++ b/dutmp.c
@@ -9,39 +9,44 @@
9 * 9 *
10 * made against libc6 10 * made against libc6
11 */ 11 */
12 12
13#include "internal.h" 13#include "internal.h"
14#include <stdio.h> 14#include <stdio.h>
15#include <utmp.h> 15#include <utmp.h>
16 16
17const char dutmp_usage[] = "dutmp\n" 17const char dutmp_usage[] = "dutmp\n"
18"\n" 18 "\n"
19"\tDump file or stdin utmp file format to stdout, pipe delimited.\n" 19 "\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
20"\tdutmp /var/run/utmp\n"; 20 "\tdutmp /var/run/utmp\n";
21 21
22extern int 22extern int dutmp_fn (int argc, char **argv)
23dutmp_fn(const struct FileInfo * i)
24{ 23{
25 24
26FILE * f = stdin; 25 FILE *f = stdin;
27struct utmp * ut = (struct utmp *) malloc(sizeof(struct utmp) ); 26 struct utmp ut;
28 27
29 if ( i ) 28 if ((argc < 2) || (**(argv + 1) == '-')) {
30 if (! (f = fopen(i->source, "r"))) { 29 fprintf (stderr, "Usage: %s %s\n", *argv, dutmp_usage);
31 name_and_error(i->source); 30 exit (FALSE);
32 return 1; 31 }
33 } 32
34 33 if ( **(++argv) == 0 ) {
35 while (fread (ut, 1, sizeof(struct utmp), f)) { 34 f = fopen (*(++argv), "r");
36 //printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n", 35 if (f < 0 ) {
37 printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", 36 perror (*argv);
38 ut->ut_type, ut->ut_pid, ut->ut_line, 37 exit (FALSE);
39 ut->ut_id, ut->ut_user, ut->ut_host, 38 }
40 ut->ut_exit.e_termination, ut->ut_exit.e_exit, 39 }
41 ut->ut_session, 40
42 ut->ut_tv.tv_sec, ut->ut_tv.tv_usec, 41 while (fread (&ut, 1, sizeof (struct utmp), f)) {
43 ut->ut_addr); 42 // printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n",
44 } 43 printf ("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
45 44 ut.ut_type, ut.ut_pid, ut.ut_line,
46return 0; 45 ut.ut_id, ut.ut_user, ut.ut_host,
46 ut.ut_exit.e_termination, ut.ut_exit.e_exit,
47 ut.ut_session,
48 ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr);
49 }
50
51 exit (TRUE);
47} 52}