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>
15 EXEC SQL INCLUDE sqlca;
16 EXEC SQL INCLUDE sqlda;
18 static char dbck_qc_rcsid[] = "$Header$";
26 struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys;
27 struct hash *strings, *members, *subnets, *string_dups;
28 EXEC SQL BEGIN DECLARE SECTION;
30 EXEC SQL END DECLARE SECTION;
31 struct save_queue *modtables, *sq_create();
35 extern SQLDA *sqlald(int, int, int);
37 int main(int argc, char **argv)
40 EXEC SQL BEGIN DECLARE SECTION;
42 EXEC SQL END DECLARE SECTION;
47 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
49 while (++arg - argv < argc)
56 debug = atoi((*arg)[2] ? *arg + 2 : *++arg);
80 printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n",
89 printf("Only doing counts\n");
91 printf("Doing fast version (skipping some checks)\n");
93 printf("Will NOT modify the database\n");
94 else if (mode == MODE_PREEN)
95 printf("Will fix simple things without asking\n");
96 else if (mode == MODE_YES)
97 printf("Will fix everything without asking\n");
99 printf("Debug level is %d\n", debug);
101 signal(SIGHUP, interrupt);
102 signal(SIGQUIT, interrupt);
103 signal(SIGINT, interrupt);
105 modtables = sq_create();
106 mr_sqlda = sqlald(1, 255, 0);
108 EXEC SQL WHENEVER SQLERROR DO dbmserr();
109 printf("Opening database %s...", database);
111 EXEC SQL CONNECT :database IDENTIFIED BY :database;
113 EXEC SQL SELECT value INTO :dcmenable FROM numvalues
114 WHERE name = 'dcm_enable';
115 dprintf("DCM disabled (was %d)\n", dcmenable);
116 EXEC SQL UPDATE numvalues SET value = 0 WHERE name = 'dcm_enable';
118 /* Begin transaction here. */
123 EXEC SQL COMMIT WORK;
125 EXEC SQL COMMIT WORK;
127 EXEC SQL COMMIT WORK;
132 EXEC SQL COMMIT WORK;
135 EXEC SQL COMMIT WORK;
144 EXEC SQL BEGIN DECLARE SECTION;
146 EXEC SQL END DECLARE SECTION;
147 int bufsize = 256, msglength = 0;
149 if (sqlca.sqlcode == 1403)
151 printf("A DBMS error occurred, code %d\n", sqlca.sqlcode);
152 sqlglm(buf, &bufsize, &msglength);
153 buf[msglength] = '\0';
155 printf("Aborting...\n");
159 EXEC SQL ROLLBACK WORK;
167 printf("Signal caught\n");
168 if (prompt("Save database changes"))
170 EXEC SQL COMMIT WORK;
174 printf("Aborting transaction\n");
178 EXEC SQL ROLLBACK WORK;
181 EXEC SQL UPDATE numvalues SET value = :dcmenable
182 WHERE name = 'dcm_enable';
188 int modified(char *table)
190 sq_save_unique_string(modtables, table);
195 EXEC SQL BEGIN DECLARE SECTION;
197 EXEC SQL END DECLARE SECTION;
199 while (sq_get_data(modtables, &tab))
201 EXEC SQL UPDATE tblstats SET modtime = SYSDATE
202 WHERE table_name = :tab;
204 EXEC SQL UPDATE numvalues SET value = :dcmenable
205 WHERE name = 'dcm_enable';
209 int out_of_mem(char *msg)
211 fprintf(stderr, "Out of memory while %s\n", msg);
212 if (prompt("Save database changes"))
214 EXEC SQL COMMIT WORK;
218 printf("Aborting transaction\n");
219 EXEC SQL ROLLBACK WORK;