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