3 * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
16 EXEC SQL INCLUDE sqlca;
20 EXEC SQL WHENEVER SQLERROR DO dbmserr();
22 void count_boxes(int id, void *user, void *boxes);
23 void check_box_counts(int id, void *cnt, void *counts);
24 void check_nfs_counts(int id, void *nfsphys, void *hint);
26 void count_boxes(int id, void *user, void *boxes)
28 struct user *u = user;
33 if ((i = (int) hash_lookup(boxes, u->pobox_id)))
35 if (hash_store(boxes, u->pobox_id, (void *)(i + 1)) == -1)
36 out_of_mem("storing poboxes in hash table");
40 printf("User %s(%s) has pobox on non-POP server %d\n",
41 u->fullname, u->login, u->pobox_id);
42 printf("Not fixing this error\n");
48 void check_box_counts(int id, void *cnt, void *counts)
50 EXEC SQL BEGIN DECLARE SECTION;
51 int oldval, rowcount, iid = id, icnt = (int)cnt;
52 EXEC SQL END DECLARE SECTION;
54 oldval = (int) hash_lookup(counts, id);
58 printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
59 ((struct machine *) hash_lookup(machines, id))->name,
61 if (single_fix("Update", 1))
63 EXEC SQL UPDATE serverhosts SET value1 = :icnt
64 WHERE service = 'POP' AND mach_id = :iid;
65 rowcount = sqlca.sqlerrd[2];
67 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
69 printf("Not fixed\n");
70 modified("serverhosts");
76 void check_nfs_counts(int id, void *nfsphys, void *hint)
78 struct nfsphys *n = nfsphys;
79 EXEC SQL BEGIN DECLARE SECTION;
80 int iid = id, rowcount;
81 unsigned long long val;
82 char valstr[40] = {0}, *endptr = valstr+39;
83 EXEC SQL END DECLARE SECTION;
86 if (n->allocated != val)
88 printf("Count wrong on NFSphys %s:%s; is %lld in db, counted %lld\n",
89 ((struct machine *) hash_lookup(machines, n->mach_id))->name,
90 n->dir, n->allocated, val);
91 if (single_fix("Update", 1))
93 strcpy(valstr, ulltostr(val, endptr));
94 EXEC SQL UPDATE nfsphys SET allocated = TO_NUMBER(:valstr)
95 WHERE nfsphys_id = :iid;
96 rowcount = sqlca.sqlerrd[2];
98 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
100 printf("Not fixed\n");
109 struct hash *boxes, *counts;
112 printf("Phase 4 - Checking counts\n");
114 dprintf("Doing POBoxes...\n");
115 boxes = create_hash(10);
116 counts = create_hash(10);
117 EXEC SQL DECLARE csr401 CURSOR FOR
118 SELECT mach_id, value1 FROM serverhosts
119 WHERE service = 'POP';
120 EXEC SQL OPEN csr401;
123 EXEC SQL FETCH csr401 INTO :id, :cnt;
127 if (hash_store(boxes, id, (void *)1) == -1)
128 out_of_mem("storing poboxes");
129 if (hash_store(counts, id, (void *)cnt) == -1)
130 out_of_mem("storing pobox counts in hash table");
132 EXEC SQL CLOSE csr401;
133 hash_step(users, count_boxes, boxes);
134 hash_step(boxes, check_box_counts, counts);
136 dprintf("Doing NFSphys...\n");
137 hash_step(nfsphys, check_nfs_counts, 0);