File: dump_log.c

package info (click to toggle)
lcgdm 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 14,044 kB
  • sloc: ansic: 149,126; sh: 13,441; perl: 11,498; python: 5,778; cpp: 5,113; sql: 1,805; makefile: 1,388; fortran: 113
file content (236 lines) | stat: -rw-r--r-- 5,603 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * $Id: dump_log.c,v 1.1 2005/03/31 13:13:00 baud Exp $
 */

/*
 * Copyright (C) 1993-1999 by CERN/IT/PDP/DM
 * All rights reserved
 */
#ifndef lint
static char sccsid[] = "@(#)$RCSfile: dump_log.c,v $ $Revision: 1.1 $ $Date: 2005/03/31 13:13:00 $ CERN/IT/PDP/DM Fabien Collin" ;
#endif /* not lint */

/* dump_log.c : A command to dump a client log */

#include <stdio.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <unistd.h>
#if ( defined(__osf__) && defined(__alpha) )
#include <stdlib.h>
#endif
#include "logging.h"

#define ERR_RECORD_FULL 1

#define MAX_LSEEK 7000
#define MAX_READ 7000
#define MAX_WRITE 7000
#define MAX_OP MAX_LSEEK+MAX_READ+MAX_WRITE

static OPEN_BUFFER rec_open;
static ERROR_BUFFER rec_error;
static RECORD_BUFFER rec_record;
static OPERATION rec_op[MAX_OP];
static int cur_op;
static int record_table[MAX_RECORD_TABLE];
static int length_record_table;
static int lf;

void rec_read(buffer,size)
     char *buffer;
     int size;
{
  int n;

  if ((n = read(lf,buffer,size)) == -1)
    {
      fprintf(stderr,"Error reading logging file\n");
      exit(1);
    }

  /* It's possible for size to be equal to 0 if the client has made an open
     with a TRUNC flag : The record table is then empty, but the dump log
     is not terminated */
  if ((n == 0) && (size != 0))
    {
      fprintf(stderr,"Dump terminated\n");
      exit(0);
    }
}

void main(argc,argv)
     int argc;
     char *argv[];
{
  static char *log_filename;
  char *getconfent();
  char date[26];
  int i;
  int j;
  char buf[10];
  WRITE_BUFFER wb;
  READ_BUFFER rb;
  LSEEK_BUFFER lb;
  char *name;
  short name_length;

  if (argc != 2)
    {
	log_filename= (char *) getconfent("RFIO", "CLIENTLOG", 0);
	if (log_filename == NULL ) {
		fprintf(stderr,"No file specified\n") ;
		exit(1) ;
	}
    }
  else
  /*
    Open the logging file
    See RFIO/CLIENT_LOG variable in shift.conf
    */

  	log_filename = argv[1];

  if ((lf = open(log_filename,O_RDONLY)) == -1)
    {
      fprintf(stderr,"Cannot open %s\n",log_filename);
      exit(1);
    }

  while (1)
    {
      rec_read((char *)&rec_open,sizeof(rec_open));

      if (rec_open.command != LOG_OPEN)
	{
	  fprintf(stderr,"Panic : OPEN record not found\n");
	  exit(1);
	}
      strcpy(date,ctime(&rec_open.date));
      date[24] = '\0';

      rec_read((char *)&name_length,sizeof(name_length));

      if ((name = malloc(name_length)) == NULL)
	{
	  fprintf(stderr,"Not enough memory\n");
	  exit(1);
	}

      rec_read(name,name_length);

      printf("%08X %04X %s OPEN : Uid=%05u Local=%1d Flags=%08X Size=%08X File = %s Machine=%s Rtime=%08X Utime=%08X Stime=%08X\n",
	     rec_open.incarnation_date,
	     rec_open.incarnation_pid,
	     date,
	     rec_open.uid,
	     rec_open.local,
	     rec_open.flags,
	     rec_open.size,
	     name,
	     rec_open.machine,
	     rec_open.session_real_time,rec_open.session_user_time,rec_open.session_sys_time);

      rec_read((char *)&rec_error,sizeof(rec_error));

      if (rec_error.command != LOG_ERRORS)
	{
	  fprintf(stderr,"Panic : ERROR record not found\n");
	  exit(1);
	}

      if (rec_error.num)
	printf("%08X %04X %s ERROR : Num=%05u\n",
	       rec_open.incarnation_date,
	       rec_open.incarnation_pid,
	       date,
	       rec_error.num);
      
      rec_read((char *)&rec_record,sizeof(rec_record));

      if (rec_record.command != LOG_RECORD)
	{
	  fprintf(stderr,"Panic : RECORD TABLE record not found\n");
	  exit(1);
	}

      length_record_table = rec_record.length;
      
      rec_read((char *)record_table,rec_record.length * sizeof(long));

      rec_read((char *)&cur_op,sizeof(int));

      rec_read((char *)rec_op,cur_op * sizeof(LSEEK_BUFFER));

      for (i=0;i<cur_op;i++)
	{
	  switch(rec_op[i].lseek.command)
	    {
	    case LOG_LSEEK_SET:
	      /* Here we use a temporary variable lb because the HP-UX 9.01
		 C compiler is broken */
	      lb = rec_op[i].lseek;

	      printf("%08X %04X %s LSEEK_SET : Offset=%08X\n",
		     rec_open.incarnation_date,
		     rec_open.incarnation_pid,
		     date,
		     lb.offset);
	      break;
	    case LOG_LSEEK_CUR:
	      /* Here we use a temporary variable lb because the HP-UX 9.01
		 C compiler is broken */
	      lb = rec_op[i].lseek;

	      printf("%08X %04X %s LSEEK_CUR : Offset=%08X\n",
		     rec_open.incarnation_date,
		     rec_open.incarnation_pid,
		     date,
		     lb.offset);
	      break;
	    case LOG_LSEEK_END:
	      /* Here we use a temporary variable lb because the HP-UX 9.01
		 C compiler is broken */
	      lb = rec_op[i].lseek;

	      printf("%08X %04X %s LSEEK_END : Offset=%08X\n",
		     rec_open.incarnation_date,
		     rec_open.incarnation_pid,
		     date,
		     lb.offset);
	      break;
	    case LOG_READ:
	      /* Here we use a temporary variable rb because the HP-UX 9.01
		 C compiler is broken */
	      rb = rec_op[i].read;

	      printf("%08X %04X %s READ : Count=%08X Record=%08X\n",
		     rec_open.incarnation_date,
		     rec_open.incarnation_pid,
		     date,
		     rb.count,
		     record_table[rb.record]);
	      break;
	    case LOG_WRITE:
	      /* Here we use a temporary variable wb because the HP-UX 9.01
		 C compiler is broken */
	      wb = rec_op[i].write;

	      printf("%08X %04X %s WRITE : Count=%08X Record=%08X\n",
		     rec_open.incarnation_date,
		     rec_open.incarnation_pid,
		     date,
		     wb.count,
		     record_table[wb.record]);

	      break;
	    default:
	      printf("Error : Unknown operation\n");
	    }
	}
    }
}