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