2 * This file is part of DisOrder
3 * Copyright (C) 2005 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
30 #include <sys/types.h>
36 #include "configuration.h"
44 #include "trackdb-int.h"
46 static const struct option options
[] = {
47 { "help", no_argument
, 0, 'h' },
48 { "version", no_argument
, 0, 'V' },
49 { "config", required_argument
, 0, 'c' },
50 { "debug", no_argument
, 0, 'd' },
51 { "no-debug", no_argument
, 0, 'D' },
52 { "syslog", no_argument
, 0, 's' },
53 { "no-syslog", no_argument
, 0, 'S' },
57 /* display usage message and terminate */
58 static void help(void) {
60 " disorder-deadlock [OPTIONS]\n"
62 " --help, -h Display usage message\n"
63 " --version, -V Display version number\n"
64 " --config PATH, -c PATH Set configuration file\n"
65 " --debug, -d Turn on debugging\n"
66 " --[no-]syslog Force logging\n"
68 "Deadlock manager for DisOrder. Not intended to be run\n"
74 /* display version number and terminate */
75 static void version(void) {
76 xprintf("%s", disorder_version_string
);
81 int main(int argc
, char **argv
) {
82 int n
, err
, aborted
, logsyslog
= !isatty(2);
85 if(!setlocale(LC_CTYPE
, "")) fatal(errno
, "error calling setlocale");
86 while((n
= getopt_long(argc
, argv
, "hVc:dDSs", options
, 0)) >= 0) {
90 case 'c': configfile
= optarg
; break;
91 case 'd': debugging
= 1; break;
92 case 'D': debugging
= 0; break;
93 case 'S': logsyslog
= 0; break;
94 case 's': logsyslog
= 1; break;
95 default: fatal(0, "invalid option");
99 openlog(progname
, LOG_PID
, LOG_DAEMON
);
100 log_default
= &log_syslog
;
102 if(config_read(0)) fatal(0, "cannot read configuration");
104 trackdb_init(TRACKDB_NO_RECOVER
);
105 while(getppid() != 1) {
106 if((err
= trackdb_env
->lock_detect(trackdb_env
,
110 fatal(0, "trackdb_env->lock_detect: %s", db_strerror(err
));
112 D(("aborted %d lock requests", aborted
));
115 /* if our parent goes away, it's time to stop */
116 info("stopped (parent terminated)");