]> andersk Git - moira.git/blame - dbck/dbck.qc
Initial revision
[moira.git] / dbck / dbck.qc
CommitLineData
d2543f8c 1/* $Header$
2 *
3 * SMS database consistency checker
4 *
5 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
8 */
9
10#include <mit-copyright.h>
11#include <stdio.h>
12#include <strings.h>
13#include <signal.h>
14#include "dbck.h"
15
16
7c4223ee 17static char dbck_qc_rcsid[] = "$Header$";
18
19
f96a9704 20int debug = 0;
d2543f8c 21int mode = MODE_ASK;
22int fast = 0;
f96a9704 23int warn = 1;
24int abort = 0;
d2543f8c 25struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys, *strings;
26##int dcmenable;
7c4223ee 27struct save_queue *modtables;
28int interrupt();
d2543f8c 29
30
31main(argc, argv)
32int argc;
33char **argv;
34{
35 char **arg = argv;
36## char *database;
37 int ingerr();
38 int countonly = 0;
39
40 database = "sms";
41
42 while (++arg - argv < argc) {
43 if (**arg == '-')
44 switch ((*arg)[1]) {
45 case 'd':
46 debug = atoi((*arg)[2] ? *arg+2 : *++arg);
47 break;
48 case 'n':
49 mode = MODE_NO;
50 break;
51 case 'y':
52 mode = MODE_YES;
53 break;
54 case 'p':
55 mode = MODE_PREEN;
56 break;
57 case 'a':
58 mode = MODE_ASK;
59 break;
60 case 'c':
61 countonly++;
62 break;
63 case 'f':
64 fast++;
65 break;
f96a9704 66 case 'w':
67 warn = 0;
68 break;
69 default:
70 printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n",
71 argv[0]);
72 exit(1);
d2543f8c 73 }
74 else
75 database = *arg;
76 }
77 if (countonly)
78 printf("Only doing counts\n");
79 else if (fast)
80 printf("Doing fast version (skipping some checks)\n");
81 if (mode == MODE_NO)
82 printf("Will NOT modify the database\n");
83 else if (mode == MODE_PREEN)
84 printf("Will fix simple things without asking\n");
85 else if (mode == MODE_YES)
86 printf("Will fix everything without asking\n");
87 if (debug)
88 printf("Debug level is %d\n", debug);
89
7c4223ee 90 signal(SIGHUP, interrupt);
91 signal(SIGQUIT, interrupt);
92 signal(SIGINT, interrupt);
93 modtables = sq_create();
d2543f8c 94
95 IIseterr(ingerr);
96 printf("Opening database %s...", database);
97 fflush(stdout);
98## ingres database
99 printf("done\n");
100## retrieve (dcmenable = values.value) where values.name = "dcm_enable"
101 dprintf("DCM disabled (was %d)\n", dcmenable);
102## replace values (value = 0) where values.name = "dcm_enable"
103
104## begin transaction
105
106 if (!countonly) {
107 phase1();
108 phase2();
109 phase3();
110 } else {
d2543f8c 111 count_only_setup();
112 }
113 phase4();
114
115## end transaction
7c4223ee 116 cleanup();
d2543f8c 117 printf("Done.\n");
d2543f8c 118 exit(0);
119}
120
121ingerr(num)
122int *num;
123{
124 printf("An ingres error occuurred, code %d\n", *num);
125 printf("Aborting...\n");
f96a9704 126 if (!abort) {
127 abort++;
128## abort
129 }
d2543f8c 130 exit(1);
131}
132
133
7c4223ee 134int interrupt()
d2543f8c 135##{
7c4223ee 136 printf("Signal caught\n");
137 if (prompt("Save database changes")) {
f96a9704 138 /* break out of a retrieve loop */
139 IIbreak();
7c4223ee 140## end transaction
141 cleanup();
142 exit(0);
143 }
144 printf("Aborting transaction\n");
f96a9704 145 if (!abort) {
146 abort++;
147 /* break out of a retrieve loop */
148 IIbreak();
149## abort
150 }
d2543f8c 151## replace values (value = dcmenable) where values.name = "dcm_enable"
152## exit
153 exit(0);
154##}
7c4223ee 155
156
157modified(table)
158char *table;
159{
160 sq_save_unique_string(modtables, table);
161}
162
163cleanup()
164##{
165## char *tab;
166
167 while (sq_get_data(modtables, &tab)) {
168## replace tblstats (modtime = "now") where tblstats.table = tab
169 }
170## replace values (value = dcmenable) where values.name = "dcm_enable"
171## exit
172##}
This page took 0.06918 seconds and 5 git commands to generate.