aboutsummaryrefslogtreecommitdiff
path: root/dutmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'dutmp.c')
-rw-r--r--dutmp.c62
1 files changed, 32 insertions, 30 deletions
diff --git a/dutmp.c b/dutmp.c
index a9e879daf..45eab8ae7 100644
--- a/dutmp.c
+++ b/dutmp.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> 3 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
3 * 4 *
@@ -15,37 +16,38 @@
15#include <utmp.h> 16#include <utmp.h>
16 17
17static const char dutmp_usage[] = "dutmp\n" 18static const char dutmp_usage[] = "dutmp\n"
18 "\n" 19 "\n"
19 "\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
20 "\tdutmp /var/run/utmp\n";
21 20
22extern int dutmp_main (int argc, char **argv) 21 "\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
22 "\tdutmp /var/run/utmp\n";
23
24extern int dutmp_main(int argc, char **argv)
23{ 25{
24 26
25 FILE *f = stdin; 27 FILE *f = stdin;
26 struct utmp ut; 28 struct utmp ut;
27 29
28 if ((argc < 2) || (**(argv + 1) == '-')) { 30 if ((argc < 2) || (**(argv + 1) == '-')) {
29 usage( dutmp_usage); 31 usage(dutmp_usage);
30 } 32 }
31 33
32 if ( **(++argv) == 0 ) { 34 if (**(++argv) == 0) {
33 f = fopen (*(++argv), "r"); 35 f = fopen(*(++argv), "r");
34 if (f < 0 ) { 36 if (f < 0) {
35 perror (*argv); 37 perror(*argv);
36 exit (FALSE); 38 exit(FALSE);
37 } 39 }
38 } 40 }
39 41
40 while (fread (&ut, 1, sizeof (struct utmp), f)) { 42 while (fread(&ut, 1, sizeof(struct utmp), f)) {
41 // printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n", 43 // printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n",
42 printf ("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", 44 printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
43 ut.ut_type, ut.ut_pid, ut.ut_line, 45 ut.ut_type, ut.ut_pid, ut.ut_line,
44 ut.ut_id, ut.ut_user, ut.ut_host, 46 ut.ut_id, ut.ut_user, ut.ut_host,
45 ut.ut_exit.e_termination, ut.ut_exit.e_exit, 47 ut.ut_exit.e_termination, ut.ut_exit.e_exit,
46 ut.ut_session, 48 ut.ut_session,
47 ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr); 49 ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr);
48 } 50 }
49 51
50 exit (TRUE); 52 exit(TRUE);
51} 53}