44558ebc9da5af774e1164c06b06536eac7cc62a
2 * This file is part of DisOrder
3 * Copyright (C) 2007 Richard Kettlewell
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.
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.
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
36 #include "configuration.h"
40 static const struct option options
[] = {
41 { "help", no_argument
, 0, 'h' },
42 { "version", no_argument
, 0, 'V' },
43 { "config", required_argument
, 0, 'c' },
44 { "debug", no_argument
, 0, 'd' },
45 { "no-debug", no_argument
, 0, 'D' },
46 { "syslog", no_argument
, 0, 's' },
47 { "no-syslog", no_argument
, 0, 'S' },
51 /* display usage message and terminate */
52 static void help(void) {
54 " disorder-stats [OPTIONS]\n"
56 " --help, -h Display usage message\n"
57 " --version, -V Display version number\n"
58 " --config PATH, -c PATH Set configuration file\n"
59 " --[no-]debug, -d Turn on (off) debugging\n"
60 " --[no-]syslog Force logging\n"
62 "Generate DisOrder database statistics.\n");
67 /* display version number and terminate */
68 static void version(void) {
69 xprintf("%s", disorder_version_string
);
74 int main(int argc
, char **argv
) {
75 int n
, logsyslog
= !isatty(2);
80 if(!setlocale(LC_CTYPE
, "")) fatal(errno
, "error calling setlocale");
81 while((n
= getopt_long(argc
, argv
, "hVc:dDSs", options
, 0)) >= 0) {
85 case 'c': configfile
= optarg
; break;
86 case 'd': debugging
= 1; break;
87 case 'D': debugging
= 0; break;
88 case 'S': logsyslog
= 0; break;
89 case 's': logsyslog
= 1; break;
90 default: fatal(0, "invalid option");
94 openlog(progname
, LOG_PID
, LOG_DAEMON
);
95 log_default
= &log_syslog
;
98 fatal(0, "cannot read configuration");
99 trackdb_init(TRACKDB_NO_RECOVER
);
100 trackdb_open(TRACKDB_NO_UPGRADE
);
101 stats
= trackdb_stats(0);
103 xprintf("%s\n", *stats
++);