Commit | Line | Data |
---|---|---|
460b9539 | 1 | /* |
2 | * This file is part of DisOrder | |
8a886602 | 3 | * Copyright (C) 2005, 2007-2009 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 | */ |
132a5a4a RK |
18 | /** @file server/deadlock.c |
19 | * @brief Deadlock monitor | |
20 | * | |
21 | * Spawned by the server. | |
22 | */ | |
05b75f8d | 23 | #include "disorder-server.h" |
460b9539 | 24 | |
25 | static const struct option options[] = { | |
26 | { "help", no_argument, 0, 'h' }, | |
27 | { "version", no_argument, 0, 'V' }, | |
28 | { "config", required_argument, 0, 'c' }, | |
29 | { "debug", no_argument, 0, 'd' }, | |
30 | { "no-debug", no_argument, 0, 'D' }, | |
0ca6d097 RK |
31 | { "syslog", no_argument, 0, 's' }, |
32 | { "no-syslog", no_argument, 0, 'S' }, | |
460b9539 | 33 | { 0, 0, 0, 0 } |
34 | }; | |
35 | ||
36 | /* display usage message and terminate */ | |
16bf32dc | 37 | static void attribute((noreturn)) help(void) { |
460b9539 | 38 | xprintf("Usage:\n" |
39 | " disorder-deadlock [OPTIONS]\n" | |
40 | "Options:\n" | |
41 | " --help, -h Display usage message\n" | |
42 | " --version, -V Display version number\n" | |
43 | " --config PATH, -c PATH Set configuration file\n" | |
44 | " --debug, -d Turn on debugging\n" | |
0ca6d097 | 45 | " --[no-]syslog Force logging\n" |
460b9539 | 46 | "\n" |
47 | "Deadlock manager for DisOrder. Not intended to be run\n" | |
48 | "directly.\n"); | |
49 | xfclose(stdout); | |
50 | exit(0); | |
51 | } | |
52 | ||
460b9539 | 53 | int main(int argc, char **argv) { |
0ca6d097 | 54 | int n, err, aborted, logsyslog = !isatty(2); |
460b9539 | 55 | |
56 | set_progname(argv); | |
2e9ba080 | 57 | if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); |
0ca6d097 | 58 | while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) { |
460b9539 | 59 | switch(n) { |
60 | case 'h': help(); | |
3fbdc96d | 61 | case 'V': version("disorder-deadlock"); |
460b9539 | 62 | case 'c': configfile = optarg; break; |
63 | case 'd': debugging = 1; break; | |
64 | case 'D': debugging = 0; break; | |
0ca6d097 RK |
65 | case 'S': logsyslog = 0; break; |
66 | case 's': logsyslog = 1; break; | |
2e9ba080 | 67 | default: disorder_fatal(0, "invalid option"); |
460b9539 | 68 | } |
69 | } | |
0ca6d097 | 70 | if(logsyslog) { |
460b9539 | 71 | openlog(progname, LOG_PID, LOG_DAEMON); |
72 | log_default = &log_syslog; | |
73 | } | |
477b12ff | 74 | config_per_user = 0; |
2e9ba080 RK |
75 | if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration"); |
76 | disorder_info("started"); | |
d25c4615 | 77 | trackdb_init(TRACKDB_NO_RECOVER); |
460b9539 | 78 | while(getppid() != 1) { |
79 | if((err = trackdb_env->lock_detect(trackdb_env, | |
80 | 0, | |
81 | DB_LOCK_DEFAULT, | |
82 | &aborted))) | |
2e9ba080 | 83 | disorder_fatal(0, "trackdb_env->lock_detect: %s", db_strerror(err)); |
460b9539 | 84 | if(aborted) |
85 | D(("aborted %d lock requests", aborted)); | |
86 | sleep(1); | |
87 | } | |
88 | /* if our parent goes away, it's time to stop */ | |
2e9ba080 | 89 | disorder_info("stopped (parent terminated)"); |
460b9539 | 90 | return 0; |
91 | } | |
92 | ||
93 | /* | |
94 | Local Variables: | |
95 | c-basic-offset:2 | |
96 | comment-column:40 | |
97 | fill-column:79 | |
98 | indent-tabs-mode:nil | |
99 | End: | |
100 | */ |