chiark / gitweb /
database upgrade tool. needs to be run manually.
[disorder] / server / stats.c
CommitLineData
d6dde5a3
RK
1/*
2 * This file is part of DisOrder
3 * Copyright (C) 2007 Richard Kettlewell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20
21#include <config.h>
22#include "types.h"
23
24#include <locale.h>
25#include <stdio.h>
26#include <errno.h>
27#include <pcre.h>
28#include <getopt.h>
0ca6d097 29#include <syslog.h>
95daf696 30#include <unistd.h>
d6dde5a3
RK
31
32#include "defs.h"
33#include "mem.h"
34#include "log.h"
35#include "syscalls.h"
36#include "configuration.h"
37#include "trackdb.h"
38
39static const struct option options[] = {
40 { "help", no_argument, 0, 'h' },
41 { "version", no_argument, 0, 'V' },
42 { "config", required_argument, 0, 'c' },
43 { "debug", no_argument, 0, 'd' },
44 { "no-debug", no_argument, 0, 'D' },
0ca6d097
RK
45 { "syslog", no_argument, 0, 's' },
46 { "no-syslog", no_argument, 0, 'S' },
d6dde5a3
RK
47 { 0, 0, 0, 0 }
48};
49
50/* display usage message and terminate */
51static void help(void) {
52 xprintf("Usage:\n"
53 " disorder-stats [OPTIONS]\n"
54 "Options:\n"
55 " --help, -h Display usage message\n"
56 " --version, -V Display version number\n"
57 " --config PATH, -c PATH Set configuration file\n"
58 " --[no-]debug, -d Turn on (off) debugging\n"
0ca6d097 59 " --[no-]syslog Force logging\n"
d6dde5a3
RK
60 "\n"
61 "Generate DisOrder database statistics.\n");
62 xfclose(stdout);
63 exit(0);
64}
65
66/* display version number and terminate */
67static void version(void) {
68 xprintf("disorder-stats version %s\n", disorder_version_string);
69 xfclose(stdout);
70 exit(0);
71}
72
73int main(int argc, char **argv) {
0ca6d097 74 int n, logsyslog = !isatty(2);
d6dde5a3
RK
75 char **stats;
76
77 set_progname(argv);
78 mem_init();
79 if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
0ca6d097 80 while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
d6dde5a3
RK
81 switch(n) {
82 case 'h': help();
83 case 'V': version();
84 case 'c': configfile = optarg; break;
85 case 'd': debugging = 1; break;
86 case 'D': debugging = 0; break;
0ca6d097
RK
87 case 'S': logsyslog = 0; break;
88 case 's': logsyslog = 1; break;
d6dde5a3
RK
89 default: fatal(0, "invalid option");
90 }
91 }
0ca6d097
RK
92 if(logsyslog) {
93 openlog(progname, LOG_PID, LOG_DAEMON);
94 log_default = &log_syslog;
95 }
d6dde5a3
RK
96 if(config_read(0))
97 fatal(0, "cannot read configuration");
98 trackdb_init(0);
3dc3d7db 99 trackdb_open(0);
d6dde5a3
RK
100 stats = trackdb_stats(0);
101 while(*stats)
102 xprintf("%s\n", *stats++);
103 xfclose(stdout);
104 return 0;
105}
106
107
108/*
109Local Variables:
110c-basic-offset:2
111comment-column:40
112fill-column:79
113indent-tabs-mode:nil
114End:
115*/