| 1 | /* |
| 2 | * This file is part of DisOrder |
| 3 | * Copyright (C) 2007, 2008 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 3 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, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU 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, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | /** @file server/stats.c |
| 19 | * @brief Generate server statistics |
| 20 | * |
| 21 | * This is done in a subprogram because it can be quite slow and we don't want |
| 22 | * to wedge the rest of the server for the duration. |
| 23 | */ |
| 24 | |
| 25 | #include "disorder-server.h" |
| 26 | |
| 27 | static const struct option options[] = { |
| 28 | { "help", no_argument, 0, 'h' }, |
| 29 | { "version", no_argument, 0, 'V' }, |
| 30 | { "config", required_argument, 0, 'c' }, |
| 31 | { "debug", no_argument, 0, 'd' }, |
| 32 | { "no-debug", no_argument, 0, 'D' }, |
| 33 | { "syslog", no_argument, 0, 's' }, |
| 34 | { "no-syslog", no_argument, 0, 'S' }, |
| 35 | { 0, 0, 0, 0 } |
| 36 | }; |
| 37 | |
| 38 | /* display usage message and terminate */ |
| 39 | static void help(void) { |
| 40 | xprintf("Usage:\n" |
| 41 | " disorder-stats [OPTIONS]\n" |
| 42 | "Options:\n" |
| 43 | " --help, -h Display usage message\n" |
| 44 | " --version, -V Display version number\n" |
| 45 | " --config PATH, -c PATH Set configuration file\n" |
| 46 | " --[no-]debug, -d Turn on (off) debugging\n" |
| 47 | " --[no-]syslog Force logging\n" |
| 48 | "\n" |
| 49 | "Generate DisOrder database statistics.\n"); |
| 50 | xfclose(stdout); |
| 51 | exit(0); |
| 52 | } |
| 53 | |
| 54 | int main(int argc, char **argv) { |
| 55 | int n, logsyslog = !isatty(2); |
| 56 | char **stats; |
| 57 | |
| 58 | set_progname(argv); |
| 59 | mem_init(); |
| 60 | if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); |
| 61 | while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) { |
| 62 | switch(n) { |
| 63 | case 'h': help(); |
| 64 | case 'V': version("disorder-stats"); |
| 65 | case 'c': configfile = optarg; break; |
| 66 | case 'd': debugging = 1; break; |
| 67 | case 'D': debugging = 0; break; |
| 68 | case 'S': logsyslog = 0; break; |
| 69 | case 's': logsyslog = 1; break; |
| 70 | default: fatal(0, "invalid option"); |
| 71 | } |
| 72 | } |
| 73 | if(logsyslog) { |
| 74 | openlog(progname, LOG_PID, LOG_DAEMON); |
| 75 | log_default = &log_syslog; |
| 76 | } |
| 77 | if(config_read(0)) |
| 78 | fatal(0, "cannot read configuration"); |
| 79 | trackdb_init(TRACKDB_NO_RECOVER); |
| 80 | trackdb_open(TRACKDB_NO_UPGRADE); |
| 81 | stats = trackdb_stats(0); |
| 82 | while(*stats) |
| 83 | xprintf("%s\n", *stats++); |
| 84 | xfclose(stdout); |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | /* |
| 90 | Local Variables: |
| 91 | c-basic-offset:2 |
| 92 | comment-column:40 |
| 93 | fill-column:79 |
| 94 | indent-tabs-mode:nil |
| 95 | End: |
| 96 | */ |