]> andersk Git - moira.git/blame - dbck/phase4.pc
eliminate use of the `register' keyword: let the compiler decide
[moira.git] / dbck / phase4.pc
CommitLineData
68bbc9c3 1/* $Header$
2 *
3 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
5 * <mit-copyright.h>.
6 */
7
8#include <mit-copyright.h>
5eaef520 9#include <stdlib.h>
68bbc9c3 10#include <moira.h>
11#include "dbck.h"
208a4f4a 12EXEC SQL INCLUDE sqlca;
68bbc9c3 13
14static char phase4_qc_rcsid[] = "$Header$";
15
4b9e5c72 16EXEC SQL WHENEVER SQLERROR DO dbmserr();
68bbc9c3 17
5eaef520 18count_boxes(int id, struct user *u, struct hash *boxes)
68bbc9c3 19{
5eaef520 20 int i;
68bbc9c3 21
5eaef520 22 if (u->potype == 'P')
23 {
24 if ((i = (int) hash_lookup(boxes, u->pobox_id)))
25 {
26 if (hash_store(boxes, u->pobox_id, i + 1) == -1)
ab05f33a 27 out_of_mem("storing poboxes in hash table");
5eaef520 28 }
29 else
30 {
68bbc9c3 31 printf("User %s(%s) has pobox on non-POP server %d\n",
32 u->fullname, u->login, u->pobox_id);
33 printf("Not fixing this error\n");
5eaef520 34 }
68bbc9c3 35 }
36}
37
38
5eaef520 39check_box_counts(int id, int cnt, struct hash *counts)
208a4f4a 40{
5eaef520 41 EXEC SQL BEGIN DECLARE SECTION;
42 int oldval, rowcount, iid = id, icnt = cnt;
43 EXEC SQL END DECLARE SECTION;
44
45 oldval = (int) hash_lookup(counts, id);
46 cnt--;
47 if (oldval != cnt)
48 {
49 printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
50 ((struct machine *) hash_lookup(machines, id))->name,
51 oldval, cnt);
52 if (single_fix("Update", 1))
53 {
54 EXEC SQL UPDATE serverhosts SET value1 = :icnt
55 WHERE service = 'POP' AND mach_id = :iid;
56 rowcount = sqlca.sqlerrd[2];
57 if (rowcount > 0)
58 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
59 else
60 printf("Not fixed\n");
61 modified("serverhosts");
68bbc9c3 62 }
63 }
208a4f4a 64}
68bbc9c3 65
66
5eaef520 67check_nfs_counts(int id, struct nfsphys *n, int hint)
208a4f4a 68{
5eaef520 69 EXEC SQL BEGIN DECLARE SECTION;
70 int iid = id, val, rowcount;
71 EXEC SQL END DECLARE SECTION;
72
73 val = n->count;
74 if (n->allocated != val)
75 {
76 printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n",
77 ((struct machine *) hash_lookup(machines, n->mach_id))->name,
78 n->dir, n->allocated, val);
79 if (single_fix("Update", 1))
80 {
81 EXEC SQL UPDATE nfsphys SET allocated = :val
82 WHERE nfsphys_id = :iid;
83 rowcount = sqlca.sqlerrd[2];
84 if (rowcount > 0)
85 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
86 else
87 printf("Not fixed\n");
88 modified("nfsphys");
68bbc9c3 89 }
90 }
208a4f4a 91}
68bbc9c3 92
93
5eaef520 94phase4(void)
208a4f4a 95{
5eaef520 96 struct hash *boxes, *counts;
97 int id, cnt;
98
99 printf("Phase 4 - Checking counts\n");
100
101 dprintf("Doing POBoxes...\n");
102 boxes = create_hash(10);
103 counts = create_hash(10);
104 EXEC SQL DECLARE csr401 CURSOR FOR
105 SELECT mach_id, value1 FROM serverhosts
106 WHERE service = 'POP';
107 EXEC SQL OPEN csr401;
108 while (1)
109 {
110 EXEC SQL FETCH csr401 INTO :id, :cnt;
111 if (sqlca.sqlcode)
112 break;
113
114 if (hash_store(boxes, id, 1) == -1)
115 out_of_mem("storing poboxes");
116 if (hash_store(counts, id, cnt) == -1)
117 out_of_mem("storing pobox counts in hash table");
208a4f4a 118 }
5eaef520 119 EXEC SQL CLOSE csr401;
120 hash_step(users, count_boxes, boxes);
121 hash_step(boxes, check_box_counts, counts);
68bbc9c3 122
5eaef520 123 dprintf("Doing NFSphys...\n");
124 hash_step(nfsphys, check_nfs_counts, 0);
208a4f4a 125}
68bbc9c3 126
127
5eaef520 128count_only_setup(void)
208a4f4a 129{
5eaef520 130 EXEC SQL BEGIN DECLARE SECTION;
131 int id, status, id2, id3;
132 char name[33], last[17], first[17], buf[257];
133 EXEC SQL END DECLARE SECTION;
134 struct save_queue *sq;
135 struct user *u;
136 struct nfsphys *n;
137 struct machine *m;
138
139 dprintf("Loading users...\n");
140 users = create_hash(30000);
141 EXEC SQL DECLARE csr402 CURSOR FOR
142 SELECT users_id, login, last, first, status,
143 potype, pop_id, box_id FROM users
144 WHERE potype = 'POP';
145 EXEC SQL OPEN csr402;
146 while (1)
147 {
148 EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status,
149 :buf, :id2, :id3;
150 if (sqlca.sqlcode)
151 break;
152
153 u = malloc(sizeof(struct user));
154 if (!u)
155 out_of_mem("storing users");
156 strcpy(u->login, strtrim(name));
157 u->potype = buf[0];
158 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
159 u->fullname = strsave(buf);
160 u->status = status;
161 u->users_id = id;
162 switch (u->potype)
163 {
68bbc9c3 164 case 'P':
5eaef520 165 u->pobox_id = id2;
166 break;
68bbc9c3 167 case 'S':
5eaef520 168 u->pobox_id = id3;
169 break;
68bbc9c3 170 default:
5eaef520 171 u->pobox_id = 0;
208a4f4a 172 }
5eaef520 173 if (hash_store(users, id, u) == -1)
174 out_of_mem("storing users in hash table");
ab05f33a 175 }
5eaef520 176 EXEC SQL CLOSE csr402;
177
178 dprintf("Loading machines...\n");
179 machines = create_hash(20000);
180 EXEC SQL DECLARE csr403 CURSOR FOR
181 SELECT mach_id, name FROM machine;
182 EXEC SQL OPEN csr403;
183 while (1)
184 {
185 EXEC SQL FETCH csr403 INTO :id, :name;
186 if (sqlca.sqlcode)
187 break;
188
189 m = malloc(sizeof(struct machine));
190 if (!m)
68bbc9c3 191 out_of_mem("storing machines");
192 strcpy(m->name, strtrim(name));
193 m->mach_id = id;
5eaef520 194 if (hash_store(machines, id, m) == -1)
ab05f33a 195 out_of_mem("storing users in hash table");
208a4f4a 196 }
5eaef520 197 EXEC SQL CLOSE csr403;
198
199 dprintf("Loading nfsphys...\n");
200 nfsphys = create_hash(500);
201 EXEC SQL DECLARE csr404 CURSOR FOR
202 SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys;
203 EXEC SQL OPEN csr404;
204 while (1)
205 {
206 EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3;
207 if (sqlca.sqlcode)
208 break;
209
210 n = malloc(sizeof(struct nfsphys));
211 if (!n)
212 out_of_mem("storing nfsphys");
213 strcpy(n->dir, strtrim(name));
214 n->mach_id = id2;
215 n->nfsphys_id = id;
216 n->allocated = id3;
217 n->count = 0;
218 if (hash_store(nfsphys, id, n) == -1)
219 out_of_mem("storing nfsphys in hash table");
220 }
221 EXEC SQL CLOSE csr404;
222
223 dprintf("Counting quotas...\n");
224 EXEC SQL DECLARE csr405 CURSOR FOR
225 SELECT phys_id, quota FROM quota;
226 EXEC SQL OPEN csr405;
227 while (1)
228 {
229 EXEC SQL FETCH csr405 INTO :id, :id2;
230 if (sqlca.sqlcode)
231 break;
232
233 if (n = (struct nfsphys *) hash_lookup(nfsphys, id))
234 n->count += id2;
208a4f4a 235 }
5eaef520 236 EXEC SQL CLOSE csr405;
208a4f4a 237}
This page took 0.089654 seconds and 5 git commands to generate.