Commit | Line | Data |
---|---|---|
460b9539 | 1 | /* |
2 | * This file is part of DisOrder | |
5aff007d | 3 | * Copyright (C) 2005, 2007, 2008 Richard Kettlewell |
460b9539 | 4 | * |
e7eb3a27 | 5 | * This program is free software: you can redistribute it and/or modify |
460b9539 | 6 | * it under the terms of the GNU General Public License as published by |
e7eb3a27 | 7 | * the Free Software Foundation, either version 3 of the License, or |
460b9539 | 8 | * (at your option) any later version. |
9 | * | |
e7eb3a27 RK |
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 | * | |
460b9539 | 15 | * You should have received a copy of the GNU General Public License |
e7eb3a27 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
460b9539 | 17 | */ |
18 | ||
05b75f8d | 19 | #include "disorder-server.h" |
460b9539 | 20 | |
21 | static const struct option options[] = { | |
22 | { "help", no_argument, 0, 'h' }, | |
23 | { "version", no_argument, 0, 'V' }, | |
24 | { "config", required_argument, 0, 'c' }, | |
25 | { "debug", no_argument, 0, 'd' }, | |
26 | { "no-debug", no_argument, 0, 'D' }, | |
0ca6d097 RK |
27 | { "syslog", no_argument, 0, 's' }, |
28 | { "no-syslog", no_argument, 0, 'S' }, | |
460b9539 | 29 | { 0, 0, 0, 0 } |
30 | }; | |
31 | ||
32 | /* display usage message and terminate */ | |
33 | static void help(void) { | |
34 | xprintf("Usage:\n" | |
35 | " disorder-deadlock [OPTIONS]\n" | |
36 | "Options:\n" | |
37 | " --help, -h Display usage message\n" | |
38 | " --version, -V Display version number\n" | |
39 | " --config PATH, -c PATH Set configuration file\n" | |
40 | " --debug, -d Turn on debugging\n" | |
0ca6d097 | 41 | " --[no-]syslog Force logging\n" |
460b9539 | 42 | "\n" |
43 | "Deadlock manager for DisOrder. Not intended to be run\n" | |
44 | "directly.\n"); | |
45 | xfclose(stdout); | |
46 | exit(0); | |
47 | } | |
48 | ||
460b9539 | 49 | int main(int argc, char **argv) { |
0ca6d097 | 50 | int n, err, aborted, logsyslog = !isatty(2); |
460b9539 | 51 | |
52 | set_progname(argv); | |
460b9539 | 53 | if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); |
0ca6d097 | 54 | while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) { |
460b9539 | 55 | switch(n) { |
56 | case 'h': help(); | |
3fbdc96d | 57 | case 'V': version("disorder-deadlock"); |
460b9539 | 58 | case 'c': configfile = optarg; break; |
59 | case 'd': debugging = 1; break; | |
60 | case 'D': debugging = 0; break; | |
0ca6d097 RK |
61 | case 'S': logsyslog = 0; break; |
62 | case 's': logsyslog = 1; break; | |
460b9539 | 63 | default: fatal(0, "invalid option"); |
64 | } | |
65 | } | |
0ca6d097 | 66 | if(logsyslog) { |
460b9539 | 67 | openlog(progname, LOG_PID, LOG_DAEMON); |
68 | log_default = &log_syslog; | |
69 | } | |
c00fce3a | 70 | if(config_read(0)) fatal(0, "cannot read configuration"); |
460b9539 | 71 | info("started"); |
d25c4615 | 72 | trackdb_init(TRACKDB_NO_RECOVER); |
460b9539 | 73 | while(getppid() != 1) { |
74 | if((err = trackdb_env->lock_detect(trackdb_env, | |
75 | 0, | |
76 | DB_LOCK_DEFAULT, | |
77 | &aborted))) | |
78 | fatal(0, "trackdb_env->lock_detect: %s", db_strerror(err)); | |
79 | if(aborted) | |
80 | D(("aborted %d lock requests", aborted)); | |
81 | sleep(1); | |
82 | } | |
83 | /* if our parent goes away, it's time to stop */ | |
84 | info("stopped (parent terminated)"); | |
85 | return 0; | |
86 | } | |
87 | ||
88 | /* | |
89 | Local Variables: | |
90 | c-basic-offset:2 | |
91 | comment-column:40 | |
92 | fill-column:79 | |
93 | indent-tabs-mode:nil | |
94 | End: | |
95 | */ |