Commit | Line | Data |
---|---|---|
460b9539 | 1 | /* |
2 | * This file is part of DisOrder | |
5aff007d | 3 | * Copyright (C) 2005, 2007, 2008 Richard Kettlewell |
460b9539 | 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 <getopt.h> | |
25 | #include <stdio.h> | |
26 | #include <stdlib.h> | |
27 | #include <db.h> | |
28 | #include <locale.h> | |
29 | #include <errno.h> | |
30 | #include <sys/types.h> | |
31 | #include <unistd.h> | |
32 | #include <pcre.h> | |
33 | #include <string.h> | |
34 | #include <syslog.h> | |
35 | ||
36 | #include "configuration.h" | |
37 | #include "syscalls.h" | |
38 | #include "log.h" | |
39 | #include "defs.h" | |
40 | #include "mem.h" | |
41 | #include "kvp.h" | |
5df73aeb | 42 | #include "rights.h" |
460b9539 | 43 | #include "trackdb.h" |
44 | #include "trackdb-int.h" | |
3fbdc96d | 45 | #include "version.h" |
460b9539 | 46 | |
47 | static const struct option options[] = { | |
48 | { "help", no_argument, 0, 'h' }, | |
49 | { "version", no_argument, 0, 'V' }, | |
50 | { "config", required_argument, 0, 'c' }, | |
51 | { "debug", no_argument, 0, 'd' }, | |
52 | { "no-debug", no_argument, 0, 'D' }, | |
0ca6d097 RK |
53 | { "syslog", no_argument, 0, 's' }, |
54 | { "no-syslog", no_argument, 0, 'S' }, | |
460b9539 | 55 | { 0, 0, 0, 0 } |
56 | }; | |
57 | ||
58 | /* display usage message and terminate */ | |
59 | static void help(void) { | |
60 | xprintf("Usage:\n" | |
61 | " disorder-deadlock [OPTIONS]\n" | |
62 | "Options:\n" | |
63 | " --help, -h Display usage message\n" | |
64 | " --version, -V Display version number\n" | |
65 | " --config PATH, -c PATH Set configuration file\n" | |
66 | " --debug, -d Turn on debugging\n" | |
0ca6d097 | 67 | " --[no-]syslog Force logging\n" |
460b9539 | 68 | "\n" |
69 | "Deadlock manager for DisOrder. Not intended to be run\n" | |
70 | "directly.\n"); | |
71 | xfclose(stdout); | |
72 | exit(0); | |
73 | } | |
74 | ||
460b9539 | 75 | int main(int argc, char **argv) { |
0ca6d097 | 76 | int n, err, aborted, logsyslog = !isatty(2); |
460b9539 | 77 | |
78 | set_progname(argv); | |
460b9539 | 79 | if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); |
0ca6d097 | 80 | while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) { |
460b9539 | 81 | switch(n) { |
82 | case 'h': help(); | |
3fbdc96d | 83 | case 'V': version("disorder-deadlock"); |
460b9539 | 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; | |
460b9539 | 89 | default: fatal(0, "invalid option"); |
90 | } | |
91 | } | |
0ca6d097 | 92 | if(logsyslog) { |
460b9539 | 93 | openlog(progname, LOG_PID, LOG_DAEMON); |
94 | log_default = &log_syslog; | |
95 | } | |
c00fce3a | 96 | if(config_read(0)) fatal(0, "cannot read configuration"); |
460b9539 | 97 | info("started"); |
d25c4615 | 98 | trackdb_init(TRACKDB_NO_RECOVER); |
460b9539 | 99 | while(getppid() != 1) { |
100 | if((err = trackdb_env->lock_detect(trackdb_env, | |
101 | 0, | |
102 | DB_LOCK_DEFAULT, | |
103 | &aborted))) | |
104 | fatal(0, "trackdb_env->lock_detect: %s", db_strerror(err)); | |
105 | if(aborted) | |
106 | D(("aborted %d lock requests", aborted)); | |
107 | sleep(1); | |
108 | } | |
109 | /* if our parent goes away, it's time to stop */ | |
110 | info("stopped (parent terminated)"); | |
111 | return 0; | |
112 | } | |
113 | ||
114 | /* | |
115 | Local Variables: | |
116 | c-basic-offset:2 | |
117 | comment-column:40 | |
118 | fill-column:79 | |
119 | indent-tabs-mode:nil | |
120 | End: | |
121 | */ |