Add 'make dist' target to get a tarball to test in addition to the upload target.
[sysvinit.git] / obsolete / utmpdump.c.OLD
CommitLineData
a74aeac6
PR
1/*
2 * utmpdump Simple program to dump UTMP and WTMP files in
3 * raw format, so they can be examined.
4 *
5 * Version: @(#)utmpdump.c 13-Aug-1996 1.00 miquels@cistron.nl
6 *
7 * This file is part of the sysvinit suite,
8 * Copyright (C) 1991-1996 Miquel van Smoorenburg.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#include <stdio.h>
26#include <utmp.h>
27#include <time.h>
28
29void dump(fp)
30FILE *fp;
31{
32 struct utmp ut;
33 int f;
34 time_t tm;
35
36 while (fread(&ut, sizeof(struct utmp), 1, fp) == 1) {
37 for(f = 0; f < 12; f++) if (ut.ut_line[f] == ' ') ut.ut_line[f] = '_';
38 for(f = 0; f < 8; f++) if (ut.ut_name[f] == ' ') ut.ut_name[f] = '_';
39 tm = ut.ut_time;
40 printf("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-15.15s]\n",
41 ut.ut_type, ut.ut_pid, ut.ut_id, ut.ut_user,
42 ut.ut_line, 4 + ctime(&tm));
43 }
44}
45
46int main(argc, argv)
47int argc;
48char **argv;
49{
50 int f;
51 FILE *fp;
52
53 if (argc < 2) {
54 argc = 2;
55 argv[1] = UTMP_FILE;
56 }
57
58 for(f = 1; f < argc; f++) {
59 if (strcmp(argv[f], "-") == 0) {
60 printf("Utmp dump of stdin\n");
61 dump(stdin);
62 } else if ((fp = fopen(argv[f], "r")) != NULL) {
63 printf("Utmp dump of %s\n", argv[f]);
64 dump(fp);
65 fclose(fp);
66 } else
67 perror(argv[f]);
68 }
69 return(0);
70}