3 * Moira database consistency checker
5 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
17 static char dbck_qc_rcsid[] = "$Header$";
25 struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys;
26 struct hash *strings, *members;
27 EXEC SQL BEGIN DECLARE SECTION;
29 EXEC SQL END DECLARE SECTION;
30 struct save_queue *modtables, *sq_create();
39 EXEC SQL BEGIN DECLARE SECTION;
41 EXEC SQL END DECLARE SECTION;
47 while (++arg - argv < argc) {
51 debug = atoi((*arg)[2] ? *arg+2 : *++arg);
75 printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n",
83 printf("Only doing counts\n");
85 printf("Doing fast version (skipping some checks)\n");
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");
93 printf("Debug level is %d\n", debug);
97 signal(SIGHUP, interrupt);
98 signal(SIGQUIT, interrupt);
99 signal(SIGINT, interrupt);
100 modtables = sq_create();
103 printf("Opening database %s...", database);
105 EXEC SQL CONNECT :database;
107 EXEC SQL SELECT value INTO :dcmenable FROM numvalues
108 WHERE name='dcm_enable';
109 dprintf("DCM disabled (was %d)\n", dcmenable);
110 EXEC SQL UPDATE numvalues SET value=0 WHERE name='dcm_enable';
112 /* Begin transaction here. */
123 EXEC SQL COMMIT WORK;
133 if (*num == 100) return;
134 printf("An ingres error occuurred, code %d\n", *num);
135 printf("Aborting...\n");
138 EXEC SQL ROLLBACK WORK;
146 printf("Signal caught\n");
147 if (prompt("Save database changes")) {
148 /* break out of a retrieve loop */
151 EXEC SQL COMMIT WORK;
155 printf("Aborting transaction\n");
158 /* break out of a retrieve loop */
160 EXEC SQL ROLLBACK WORK;
163 EXEC SQL UPDATE numvalues SET value=:dcmenable
164 WHERE name='dcm_enable';
173 sq_save_unique_string(modtables, table);
178 EXEC SQL BEGIN DECLARE SECTION;
180 EXEC SQL END DECLARE SECTION;
182 while (sq_get_data(modtables, &tab)) {
183 EXEC SQL REPEATED UPDATE tblstats SET modtime='now'
184 WHERE table_name = :tab;
186 EXEC SQL UPDATE numvalues SET value = :dcmenable
187 WHERE name='dcm_enable';
194 fprintf(stderr, "Out of memory while %s\n", msg);
195 if (prompt("Save database changes")) {
196 /* break out of a retrieve loop */
199 EXEC SQL COMMIT WORK;
203 printf("Aborting transaction\n");
205 EXEC SQL ROLLBACK WORK;