]> andersk Git - moira.git/blame_incremental - dbck/phase4.pc
Deal with tracking creation times for users.
[moira.git] / dbck / phase4.pc
... / ...
CommitLineData
1/* $Id$
2 *
3 * (c) Copyright 1988-1998 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>
9#include <moira.h>
10#include "dbck.h"
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15
16EXEC SQL INCLUDE sqlca;
17
18RCSID("$Header$");
19
20EXEC SQL WHENEVER SQLERROR DO dbmserr();
21
22void count_boxes(int id, void *user, void *boxes);
23void check_box_counts(int id, void *cnt, void *counts);
24void check_nfs_counts(int id, void *nfsphys, void *hint);
25
26void count_boxes(int id, void *user, void *boxes)
27{
28 struct user *u = user;
29 int i;
30
31 if (u->potype == 'P')
32 {
33 if ((i = (int) hash_lookup(boxes, u->pobox_id)))
34 {
35 if (hash_store(boxes, u->pobox_id, (void *)(i + 1)) == -1)
36 out_of_mem("storing poboxes in hash table");
37 }
38 else
39 {
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");
43 }
44 }
45}
46
47
48void check_box_counts(int id, void *cnt, void *counts)
49{
50 EXEC SQL BEGIN DECLARE SECTION;
51 int oldval, rowcount, iid = id, icnt = (int)cnt;
52 EXEC SQL END DECLARE SECTION;
53
54 oldval = (int) hash_lookup(counts, id);
55 icnt--;
56 if (oldval != icnt)
57 {
58 printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
59 ((struct machine *) hash_lookup(machines, id))->name,
60 oldval, icnt);
61 if (single_fix("Update", 1))
62 {
63 EXEC SQL UPDATE serverhosts SET value1 = :icnt
64 WHERE service = 'POP' AND mach_id = :iid;
65 rowcount = sqlca.sqlerrd[2];
66 if (rowcount > 0)
67 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
68 else
69 printf("Not fixed\n");
70 modified("serverhosts");
71 }
72 }
73}
74
75
76void check_nfs_counts(int id, void *nfsphys, void *hint)
77{
78 struct nfsphys *n = nfsphys;
79 EXEC SQL BEGIN DECLARE SECTION;
80 int iid = id, val, rowcount;
81 EXEC SQL END DECLARE SECTION;
82
83 val = n->count;
84 if (n->allocated != val)
85 {
86 printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n",
87 ((struct machine *) hash_lookup(machines, n->mach_id))->name,
88 n->dir, n->allocated, val);
89 if (single_fix("Update", 1))
90 {
91 EXEC SQL UPDATE nfsphys SET allocated = :val
92 WHERE nfsphys_id = :iid;
93 rowcount = sqlca.sqlerrd[2];
94 if (rowcount > 0)
95 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
96 else
97 printf("Not fixed\n");
98 modified("nfsphys");
99 }
100 }
101}
102
103
104void phase4(void)
105{
106 struct hash *boxes, *counts;
107 int id, cnt;
108
109 printf("Phase 4 - Checking counts\n");
110
111 dprintf("Doing POBoxes...\n");
112 boxes = create_hash(10);
113 counts = create_hash(10);
114 EXEC SQL DECLARE csr401 CURSOR FOR
115 SELECT mach_id, value1 FROM serverhosts
116 WHERE service = 'POP';
117 EXEC SQL OPEN csr401;
118 while (1)
119 {
120 EXEC SQL FETCH csr401 INTO :id, :cnt;
121 if (sqlca.sqlcode)
122 break;
123
124 if (hash_store(boxes, id, (void *)1) == -1)
125 out_of_mem("storing poboxes");
126 if (hash_store(counts, id, (void *)cnt) == -1)
127 out_of_mem("storing pobox counts in hash table");
128 }
129 EXEC SQL CLOSE csr401;
130 hash_step(users, count_boxes, boxes);
131 hash_step(boxes, check_box_counts, counts);
132
133 dprintf("Doing NFSphys...\n");
134 hash_step(nfsphys, check_nfs_counts, 0);
135}
This page took 0.031243 seconds and 5 git commands to generate.