source: npl/mailserver/dspam/dspam-3.10.2/src/tools.hash_drv/cssstat.c @ c5c522c

gcc484ntopperl-5.22
Last change on this file since c5c522c was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/* $Id: cssstat.c,v 1.86 2011/06/28 00:13:48 sbajic Exp $ */
2
3/*
4 DSPAM
5 COPYRIGHT (C) 2002-2012 DSPAM PROJECT
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Affero General Public License as
9 published by the Free Software Foundation, either version 3 of the
10 License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Affero General Public License for more details.
16
17 You should have received a copy of the GNU Affero General Public License
18 along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20*/
21
22/* cssstat.c - Print hash file statistics */
23
24#define READ_ATTRIB(A)          _ds_read_attribute(agent_config, A)
25#define MATCH_ATTRIB(A, B)      _ds_match_attribute(agent_config, A, B)
26
27#ifdef HAVE_CONFIG_H
28#include <auto-config.h>
29#endif
30
31#include <string.h>
32#include <sys/types.h>
33#include <sys/mman.h>
34#include <sys/stat.h>
35#include <sys/uio.h>
36#include <dirent.h>
37#include <unistd.h>
38#include <errno.h>
39#include <stdlib.h>
40#include <stdio.h>
41#include <fcntl.h>
42#include <signal.h>
43
44#ifdef TIME_WITH_SYS_TIME
45#   include <sys/time.h>
46#   include <time.h>
47#else
48#   ifdef HAVE_SYS_TIME_H
49#       include <sys/time.h>
50#   else
51#       include <time.h>
52#   endif
53#endif
54
55int DO_DEBUG
56#ifdef DEBUG
57= 1
58#else
59= 0
60#endif
61;
62
63#include "read_config.h"
64#include "hash_drv.h"
65#include "language.h"
66#include "error.h"
67 
68#define SYNTAX "syntax: cssstat [filename]"
69
70int cssstat(const char *filename);
71
72int main(int argc, char *argv[]) {
73  char *filename;
74  int r;
75
76  if (argc<2) {
77    fprintf(stderr, "%s\n", SYNTAX);
78    exit(EXIT_FAILURE);
79  }
80   
81  agent_config = read_config(NULL);
82  if (!agent_config) {
83    LOG(LOG_ERR, ERR_AGENT_READ_CONFIG);
84    exit(EXIT_FAILURE);
85  }
86
87  filename = argv[1];
88
89  r = cssstat(filename);
90 
91  if (r) {
92    fprintf(stderr, "cssstat failed on error %d\n", r);
93    exit(EXIT_FAILURE);
94  }
95  exit(EXIT_SUCCESS);
96}
97
98int cssstat(const char *filename) {
99  struct _hash_drv_map map;
100  hash_drv_header_t header;
101  hash_drv_spam_record_t rec;
102  unsigned long filepos = sizeof(struct _hash_drv_header);
103  unsigned long nfree = 0, nused = 0;
104  unsigned long efree, eused;
105  unsigned long extents = 0;
106  unsigned long i;
107
108  unsigned long max_seek     = HASH_SEEK_MAX;
109  unsigned long max_extents  = 0;
110  unsigned long extent_size  = HASH_EXTENT_MAX;
111  int flags = 0;
112
113  if (READ_ATTRIB("HashExtentSize"))
114    extent_size = strtol(READ_ATTRIB("HashExtentSize"), NULL, 0);
115
116  if (READ_ATTRIB("HashMaxExtents"))
117    max_extents = strtol(READ_ATTRIB("HashMaxExtents"), NULL, 0);
118
119  if (MATCH_ATTRIB("HashAutoExtend", "on"))
120    flags = HMAP_AUTOEXTEND;
121
122  if (READ_ATTRIB("HashMaxSeek"))
123     max_seek = strtol(READ_ATTRIB("HashMaxSeek"), NULL, 0);
124
125  if (_hash_drv_open(filename, &map, 0, max_seek,
126                     max_extents, extent_size, 0, flags))
127  {
128    return EFAILURE;
129  }
130
131  header = map.addr;
132  printf("filename %s length %ld\n", filename, (long) map.file_len);
133
134  while(filepos < map.file_len) {
135    printf("extent %lu: record length %lu\n", extents,
136      (unsigned long) header->hash_rec_max);
137    efree = eused = 0;
138    for(i=0;i<header->hash_rec_max;i++) {
139      rec = (void *) ((unsigned long) map.addr + filepos);
140      if (rec->hashcode) {
141        eused++;
142        nused++;
143      } else {
144        efree++;
145        nfree++;
146      }
147      filepos += sizeof(struct _hash_drv_spam_record);
148    }
149    header = (void *) ((unsigned long) map.addr + filepos);
150    filepos += sizeof(struct _hash_drv_header);
151    extents++;
152
153    printf("\textent records used %lu\n", eused);
154    printf("\textent records free %lu\n", efree);
155  }
156
157  _hash_drv_close(&map);
158
159  printf("total database records used %lu\n", nused);
160  printf("total database records free %lu\n", nfree);
161  printf("total extents               %lu\n", extents);
162  return 0;
163}
164
Note: See TracBrowser for help on using the repository browser.