]> andersk Git - moira.git/blob - dbck/dbck.qc
Initial revision
[moira.git] / dbck / dbck.qc
1 /* $Header$
2  *
3  * Moira 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;
26 struct hash *strings, *members;
27 ##int dcmenable;
28 struct save_queue *modtables, *sq_create();
29 int interrupt();
30
31
32 main(argc, argv)
33 int argc;
34 char **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;
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);
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
91     signal(SIGHUP, interrupt);
92     signal(SIGQUIT, interrupt);
93     signal(SIGINT, interrupt);
94     modtables = sq_create();
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 {
112         count_only_setup();
113     }
114     phase4();
115
116 ##  end transaction
117     cleanup();
118     printf("Done.\n");
119     exit(0);
120 }
121
122 ingerr(num)
123 int     *num;
124 {
125     printf("An ingres error occuurred, code %d\n", *num);
126     printf("Aborting...\n");
127     if (!abort) {
128         abort++;
129 ##      abort
130     }
131     exit(1);
132 }
133
134
135 int interrupt()
136 ##{
137     printf("Signal caught\n");
138     if (prompt("Save database changes")) {
139         /* break out of a retrieve loop */
140         IIbreak();
141 ##      end transaction
142         cleanup();
143         exit(0);
144     }
145     printf("Aborting transaction\n");
146     if (!abort) {
147         abort++;
148         /* break out of a retrieve loop */
149         IIbreak();
150 ##      abort
151     }
152 ##  replace values (value = dcmenable) where values.name = "dcm_enable"
153 ##  exit
154     exit(0);
155 ##}
156
157
158 modified(table)
159 char *table;
160 {
161     sq_save_unique_string(modtables, table);
162 }
163
164 cleanup()
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 ##}
174
175
176 out_of_mem(msg)
177 char *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.045235 seconds and 5 git commands to generate.