]> andersk Git - moira.git/blob - dbck/dbck.qc
Used /bin/sh format instead of /bin/csh format, by accident.
[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     setlinebuf(stdout);
92
93     signal(SIGHUP, interrupt);
94     signal(SIGQUIT, interrupt);
95     signal(SIGINT, interrupt);
96     modtables = sq_create();
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 {
114         count_only_setup();
115     }
116     phase4();
117
118 ##  end transaction
119     cleanup();
120     printf("Done.\n");
121     exit(0);
122 }
123
124 ingerr(num)
125 int     *num;
126 {
127     printf("An ingres error occuurred, code %d\n", *num);
128     printf("Aborting...\n");
129     if (!abort) {
130         abort++;
131 ##      abort
132     }
133     exit(1);
134 }
135
136
137 int interrupt()
138 ##{
139     printf("Signal caught\n");
140     if (prompt("Save database changes")) {
141         /* break out of a retrieve loop */
142         IIbreak();
143 ##      end transaction
144         cleanup();
145         exit(0);
146     }
147     printf("Aborting transaction\n");
148     if (!abort) {
149         abort++;
150         /* break out of a retrieve loop */
151         IIbreak();
152 ##      abort
153     }
154 ##  replace values (value = dcmenable) where values.name = "dcm_enable"
155 ##  exit
156     exit(0);
157 ##}
158
159
160 modified(table)
161 char *table;
162 {
163     sq_save_unique_string(modtables, table);
164 }
165
166 cleanup()
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 ##}
176
177
178 out_of_mem(msg)
179 char *msg;
180 {
181     fprintf(stderr, "Out of memory while %s\n", msg);
182 ##  end transaction    
183     cleanup();
184     exit(1);
185 }
This page took 0.099532 seconds and 5 git commands to generate.