3 * Moira database consistency checker
5 * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
18 EXEC SQL INCLUDE sqlca;
19 EXEC SQL INCLUDE sqlda;
28 struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys;
29 struct hash *strings, *members, *subnets, *string_dups;
30 EXEC SQL BEGIN DECLARE SECTION;
32 EXEC SQL END DECLARE SECTION;
33 struct save_queue *modtables;
37 extern SQLDA *sqlald(int, int, int);
38 extern void sqlglm(char *, unsigned int *, unsigned int *);
40 int main(int argc, char **argv)
43 EXEC SQL BEGIN DECLARE SECTION;
45 EXEC SQL END DECLARE SECTION;
50 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
52 while (++arg - argv < argc)
59 debug = atoi((*arg)[2] ? *arg + 2 : *++arg);
83 printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n",
92 printf("Only doing counts\n");
94 printf("Doing fast version (skipping some checks)\n");
96 printf("Will NOT modify the database\n");
97 else if (mode == MODE_PREEN)
98 printf("Will fix simple things without asking\n");
99 else if (mode == MODE_YES)
100 printf("Will fix everything without asking\n");
102 printf("Debug level is %d\n", debug);
104 sa.sa_handler = interrupt;
106 sigemptyset(&sa.sa_mask);
107 sigaction(SIGHUP, &sa, NULL);
108 sigaction(SIGQUIT, &sa, NULL);
109 sigaction(SIGINT, &sa, NULL);
111 modtables = sq_create();
112 mr_sqlda = sqlald(1, 255, 0);
114 EXEC SQL WHENEVER SQLERROR DO dbmserr();
115 printf("Opening database %s...", database);
117 EXEC SQL CONNECT :database IDENTIFIED BY :database;
119 EXEC SQL SELECT value INTO :dcmenable FROM numvalues
120 WHERE name = 'dcm_enable';
121 dprintf("DCM disabled (was %d)\n", dcmenable);
122 EXEC SQL UPDATE numvalues SET value = 0 WHERE name = 'dcm_enable';
124 /* Begin transaction here. */
129 EXEC SQL COMMIT WORK;
131 EXEC SQL COMMIT WORK;
133 EXEC SQL COMMIT WORK;
138 EXEC SQL COMMIT WORK;
141 EXEC SQL COMMIT WORK;
150 EXEC SQL BEGIN DECLARE SECTION;
152 EXEC SQL END DECLARE SECTION;
153 int bufsize = 256, msglength = 0;
155 if (sqlca.sqlcode == 1403)
157 printf("A DBMS error occurred, code %ld\n", sqlca.sqlcode);
158 sqlglm(buf, &bufsize, &msglength);
159 buf[msglength] = '\0';
161 printf("Aborting...\n");
165 EXEC SQL ROLLBACK WORK;
173 printf("Signal caught\n");
174 if (prompt("Save database changes"))
176 EXEC SQL COMMIT WORK;
180 printf("Aborting transaction\n");
184 EXEC SQL ROLLBACK WORK;
187 EXEC SQL UPDATE numvalues SET value = :dcmenable
188 WHERE name = 'dcm_enable';
194 void modified(char *table)
196 sq_save_unique_string(modtables, table);
201 EXEC SQL BEGIN DECLARE SECTION;
203 EXEC SQL END DECLARE SECTION;
205 while (sq_get_data(modtables, &tab))
207 EXEC SQL UPDATE tblstats SET modtime = SYSDATE
208 WHERE table_name = :tab;
210 EXEC SQL UPDATE numvalues SET value = :dcmenable
211 WHERE name = 'dcm_enable';
215 void out_of_mem(char *msg)
217 fprintf(stderr, "Out of memory while %s\n", msg);
218 if (prompt("Save database changes"))
220 EXEC SQL COMMIT WORK;
224 printf("Aborting transaction\n");
225 EXEC SQL ROLLBACK WORK;