]> andersk Git - moira.git/blame - dbck/dbck.qc
Used /bin/sh format instead of /bin/csh format, by accident.
[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
374156f5 91 setlinebuf(stdout);
92
7c4223ee 93 signal(SIGHUP, interrupt);
94 signal(SIGQUIT, interrupt);
95 signal(SIGINT, interrupt);
96 modtables = sq_create();
d2543f8c 97
98 IIseterr(ingerr);
99 printf("Opening database %s...", database);
100 fflush(stdout);
101## ingres database
102 printf("done\n");
103## retrieve (dcmenable = values.value) where values.name = "dcm_enable"
104 dprintf("DCM disabled (was %d)\n", dcmenable);
105## replace values (value = 0) where values.name = "dcm_enable"
106
107## begin transaction
108
109 if (!countonly) {
110 phase1();
111 phase2();
112 phase3();
113 } else {
d2543f8c 114 count_only_setup();
115 }
116 phase4();
117
118## end transaction
7c4223ee 119 cleanup();
d2543f8c 120 printf("Done.\n");
d2543f8c 121 exit(0);
122}
123
124ingerr(num)
125int *num;
126{
127 printf("An ingres error occuurred, code %d\n", *num);
128 printf("Aborting...\n");
f96a9704 129 if (!abort) {
130 abort++;
131## abort
132 }
d2543f8c 133 exit(1);
134}
135
136
7c4223ee 137int interrupt()
d2543f8c 138##{
7c4223ee 139 printf("Signal caught\n");
140 if (prompt("Save database changes")) {
f96a9704 141 /* break out of a retrieve loop */
142 IIbreak();
7c4223ee 143## end transaction
144 cleanup();
145 exit(0);
146 }
147 printf("Aborting transaction\n");
f96a9704 148 if (!abort) {
149 abort++;
150 /* break out of a retrieve loop */
151 IIbreak();
152## abort
153 }
d2543f8c 154## replace values (value = dcmenable) where values.name = "dcm_enable"
155## exit
156 exit(0);
157##}
7c4223ee 158
159
160modified(table)
161char *table;
162{
163 sq_save_unique_string(modtables, table);
164}
165
166cleanup()
167##{
168## char *tab;
169
170 while (sq_get_data(modtables, &tab)) {
171## replace tblstats (modtime = "now") where tblstats.table = tab
172 }
173## replace values (value = dcmenable) where values.name = "dcm_enable"
174## exit
175##}
cc3d4d55 176
177
178out_of_mem(msg)
179char *msg;
180{
181 fprintf(stderr, "Out of memory while %s\n", msg);
182## end transaction
183 cleanup();
184 exit(1);
185}
This page took 1.013253 seconds and 5 git commands to generate.