-/* $Header$
+/* $Id$
*
* Moira database consistency checker
*
- * (c) Copyright 1988 by the Massachusetts Institute of Technology.
- * For copying and distribution information, please see the file
- * <mit-copyright.h>.
+ * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
*/
#include <mit-copyright.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
+#include <moira.h>
#include "dbck.h"
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
EXEC SQL INCLUDE sqlca;
EXEC SQL INCLUDE sqlda;
-static char dbck_qc_rcsid[] = "$Header$";
-
+RCSID("$Header$");
int debug = 0;
int mode = MODE_ASK;
int warn = 1;
int abort_p = 0;
struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys;
-struct hash *strings, *members, *subnets, *string_dups;
+struct hash *strings, *members, *subnets, *string_dups, *printservers;
+struct hash *containers;
EXEC SQL BEGIN DECLARE SECTION;
int dcmenable;
EXEC SQL END DECLARE SECTION;
-struct save_queue *modtables, *sq_create();
-void interrupt();
+struct save_queue *modtables;
SQLDA *mr_sqlda;
+void interrupt(void);
extern SQLDA *sqlald(int, int, int);
+extern void sqlglm(char *, unsigned int *, unsigned int *);
int main(int argc, char **argv)
{
EXEC SQL BEGIN DECLARE SECTION;
char *database;
EXEC SQL END DECLARE SECTION;
- int ingerr();
- int countonly = 0;
+ struct sigaction sa;
database = "moira";
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
while (++arg - argv < argc)
{
- if (**arg == '-')
+ if (**arg == '-')
{
switch ((*arg)[1])
{
case 'a':
mode = MODE_ASK;
break;
- case 'c':
- countonly++;
- break;
case 'f':
fast++;
break;
warn = 0;
break;
default:
- printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n",
+ printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-f] [-w] [database]\n",
argv[0]);
exit(1);
}
else
database = *arg;
}
- if (countonly)
- printf("Only doing counts\n");
- else if (fast)
+ if (fast)
printf("Doing fast version (skipping some checks)\n");
if (mode == MODE_NO)
printf("Will NOT modify the database\n");
if (debug)
printf("Debug level is %d\n", debug);
- signal(SIGHUP, interrupt);
- signal(SIGQUIT, interrupt);
- signal(SIGINT, interrupt);
+ sa.sa_handler = interrupt;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGHUP, &sa, NULL);
+ sigaction(SIGQUIT, &sa, NULL);
+ sigaction(SIGINT, &sa, NULL);
modtables = sq_create();
mr_sqlda = sqlald(1, 255, 0);
fflush(stdout);
EXEC SQL CONNECT :database IDENTIFIED BY :database;
printf("done\n");
- EXEC SQL SELECT value INTO :dcmenable FROM numvalues
- WHERE name = 'dcm_enable';
- dprintf("DCM disabled (was %d)\n", dcmenable);
- EXEC SQL UPDATE numvalues SET value = 0 WHERE name = 'dcm_enable';
+ if (mode != MODE_NO)
+ {
+ EXEC SQL SELECT value INTO :dcmenable FROM numvalues
+ WHERE name = 'dcm_enable';
+ dprintf("DCM disabled (was %d)\n", dcmenable);
+ EXEC SQL UPDATE numvalues SET value = 0 WHERE name = 'dcm_enable';
+ }
/* Begin transaction here. */
- if (!countonly)
- {
- phase1();
- EXEC SQL COMMIT WORK;
- phase2();
- EXEC SQL COMMIT WORK;
- phase3();
- EXEC SQL COMMIT WORK;
- }
- else
- {
- count_only_setup();
- EXEC SQL COMMIT WORK;
- }
+ phase1();
+ EXEC SQL COMMIT WORK;
+ phase2();
+ EXEC SQL COMMIT WORK;
+ phase3();
+ EXEC SQL COMMIT WORK;
phase4();
EXEC SQL COMMIT WORK;
- cleanup();
+ if (mode != MODE_NO)
+ cleanup();
printf("Done.\n");
exit(0);
}
-int dbmserr(void)
+void dbmserr(void)
{
EXEC SQL BEGIN DECLARE SECTION;
- char buf[512];
+ char buf[256];
EXEC SQL END DECLARE SECTION;
int bufsize = 256, msglength = 0;
if (sqlca.sqlcode == 1403)
return;
- printf("A DBMS error occurred, code %d\n", sqlca.sqlcode);
+ printf("A DBMS error occurred, code %ld\n", sqlca.sqlcode);
sqlglm(buf, &bufsize, &msglength);
buf[msglength] = '\0';
printf("%s\n", buf);
}
-int modified(char *table)
+void modified(char *table)
{
sq_save_unique_string(modtables, table);
}
-int cleanup(void)
+void cleanup(void)
{
EXEC SQL BEGIN DECLARE SECTION;
char *tab;
}
-int out_of_mem(char *msg)
+void out_of_mem(char *msg)
{
fprintf(stderr, "Out of memory while %s\n", msg);
if (prompt("Save database changes"))