]> andersk Git - moira.git/blame - dbck/dbck.dc
Added support for handling Kerberos ".root" instances.
[moira.git] / dbck / dbck.dc
CommitLineData
68bbc9c3 1/* $Header$
2 *
3 * Moira 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
17static char dbck_qc_rcsid[] = "$Header$";
18
19
20int debug = 0;
21int mode = MODE_ASK;
22int fast = 0;
23int warn = 1;
208a4f4a 24int abort_p = 0;
68bbc9c3 25struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys;
26struct hash *strings, *members;
208a4f4a 27EXEC SQL BEGIN DECLARE SECTION;
28int dcmenable;
29EXEC SQL END DECLARE SECTION;
68bbc9c3 30struct save_queue *modtables, *sq_create();
31int interrupt();
32
33
34main(argc, argv)
35int argc;
36char **argv;
37{
38 char **arg = argv;
208a4f4a 39EXEC SQL BEGIN DECLARE SECTION;
40 char *database;
41EXEC SQL END DECLARE SECTION;
68bbc9c3 42 int ingerr();
43 int countonly = 0;
44
208a4f4a 45 database = "moira";
68bbc9c3 46
47 while (++arg - argv < argc) {
48 if (**arg == '-')
49 switch ((*arg)[1]) {
50 case 'd':
51 debug = atoi((*arg)[2] ? *arg+2 : *++arg);
52 break;
53 case 'n':
54 mode = MODE_NO;
55 break;
56 case 'y':
57 mode = MODE_YES;
58 break;
59 case 'p':
60 mode = MODE_PREEN;
61 break;
62 case 'a':
63 mode = MODE_ASK;
64 break;
65 case 'c':
66 countonly++;
67 break;
68 case 'f':
69 fast++;
70 break;
71 case 'w':
72 warn = 0;
73 break;
74 default:
75 printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n",
76 argv[0]);
77 exit(1);
78 }
79 else
80 database = *arg;
81 }
82 if (countonly)
83 printf("Only doing counts\n");
84 else if (fast)
85 printf("Doing fast version (skipping some checks)\n");
86 if (mode == MODE_NO)
87 printf("Will NOT modify the database\n");
88 else if (mode == MODE_PREEN)
89 printf("Will fix simple things without asking\n");
90 else if (mode == MODE_YES)
91 printf("Will fix everything without asking\n");
92 if (debug)
93 printf("Debug level is %d\n", debug);
94
95 setlinebuf(stdout);
96
97 signal(SIGHUP, interrupt);
98 signal(SIGQUIT, interrupt);
99 signal(SIGINT, interrupt);
100 modtables = sq_create();
101
102 IIseterr(ingerr);
103 printf("Opening database %s...", database);
104 fflush(stdout);
208a4f4a 105/* ingres database */
106 EXEC SQL CONNECT :database;
68bbc9c3 107 printf("done\n");
208a4f4a 108/* retrieve (dcmenable = values.value) where values.name = "dcm_enable" */
109 EXEC SQL SELECT value INTO :dcmenable FROM numvalues
110 WHERE name='dcm_enable';
68bbc9c3 111 dprintf("DCM disabled (was %d)\n", dcmenable);
208a4f4a 112/* replace values (value = 0) where values.name = "dcm_enable" */
113 EXEC SQL UPDATE numvalues SET value=0 WHERE name='dcm_enable';
68bbc9c3 114
208a4f4a 115 /* Begin transaction here. */
68bbc9c3 116
117 if (!countonly) {
118 phase1();
119 phase2();
120 phase3();
121 } else {
122 count_only_setup();
123 }
124 phase4();
125
208a4f4a 126 EXEC SQL COMMIT WORK;
127
68bbc9c3 128 cleanup();
129 printf("Done.\n");
130 exit(0);
131}
132
133ingerr(num)
134int *num;
135{
136 printf("An ingres error occuurred, code %d\n", *num);
137 printf("Aborting...\n");
208a4f4a 138 if (!abort_p) {
139 abort_p++;
140 EXEC SQL ROLLBACK WORK;
68bbc9c3 141 }
142 exit(1);
143}
144
145
146int interrupt()
208a4f4a 147{
68bbc9c3 148 printf("Signal caught\n");
149 if (prompt("Save database changes")) {
150 /* break out of a retrieve loop */
151 IIbreak();
208a4f4a 152
153 EXEC SQL COMMIT WORK;
68bbc9c3 154 cleanup();
155 exit(0);
156 }
157 printf("Aborting transaction\n");
208a4f4a 158 if (!abort_p) {
159 abort_p++;
68bbc9c3 160 /* break out of a retrieve loop */
161 IIbreak();
208a4f4a 162 EXEC SQL ROLLBACK WORK;
68bbc9c3 163 }
208a4f4a 164
165/* replace values (value = dcmenable) where values.name = "dcm_enable" */
166 EXEC SQL UPDATE numvalues SET value=:dcmenable
167 WHERE name='dcm_enable';
168
169/* exit */
170 /* No equivalent (?) */
68bbc9c3 171 exit(0);
208a4f4a 172}
68bbc9c3 173
174
175modified(table)
176char *table;
177{
178 sq_save_unique_string(modtables, table);
179}
180
181cleanup()
208a4f4a 182{
183 EXEC SQL BEGIN DECLARE SECTION;
184 char *tab;
185 EXEC SQL END DECLARE SECTION;
68bbc9c3 186
187 while (sq_get_data(modtables, &tab)) {
208a4f4a 188/* replace tblstats (modtime = "now") where tblstats.table = tab */
189 EXEC SQL REPEATED UPDATE tblstats SET modtime='now'
190 WHERE table_name = :tab;
68bbc9c3 191 }
208a4f4a 192/* replace values (value = dcmenable) where values.name = "dcm_enable" */
193 EXEC SQL UPDATE numvalues SET value = :dcmenable
194 WHERE name='dcm_enable';
195/* exit */
196 /* No equivalent (?) */
197}
68bbc9c3 198
199
200out_of_mem(msg)
201char *msg;
202{
203 fprintf(stderr, "Out of memory while %s\n", msg);
208a4f4a 204/* end transaction */
205 EXEC SQL COMMIT WORK;
68bbc9c3 206 cleanup();
207 exit(1);
208}
This page took 0.107595 seconds and 5 git commands to generate.