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