]> andersk Git - moira.git/blame - dbck/phase4.pc
Command line printer manipulation client, and build goo.
[moira.git] / dbck / phase4.pc
CommitLineData
7ac48069 1/* $Id$
68bbc9c3 2 *
7ac48069 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>.
68bbc9c3 6 */
7
8#include <mit-copyright.h>
9#include <moira.h>
10#include "dbck.h"
7ac48069 11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15
208a4f4a 16EXEC SQL INCLUDE sqlca;
68bbc9c3 17
7ac48069 18RCSID("$Header$");
68bbc9c3 19
4b9e5c72 20EXEC SQL WHENEVER SQLERROR DO dbmserr();
68bbc9c3 21
7ac48069 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)
68bbc9c3 27{
7ac48069 28 struct user *u = user;
5eaef520 29 int i;
68bbc9c3 30
5eaef520 31 if (u->potype == 'P')
32 {
33 if ((i = (int) hash_lookup(boxes, u->pobox_id)))
34 {
7ac48069 35 if (hash_store(boxes, u->pobox_id, (void *)(i + 1)) == -1)
ab05f33a 36 out_of_mem("storing poboxes in hash table");
5eaef520 37 }
38 else
39 {
68bbc9c3 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");
5eaef520 43 }
68bbc9c3 44 }
45}
46
47
7ac48069 48void check_box_counts(int id, void *cnt, void *counts)
208a4f4a 49{
5eaef520 50 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 51 int oldval, rowcount, iid = id, icnt = (int)cnt;
5eaef520 52 EXEC SQL END DECLARE SECTION;
53
54 oldval = (int) hash_lookup(counts, id);
7ac48069 55 icnt--;
56 if (oldval != icnt)
5eaef520 57 {
58 printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
59 ((struct machine *) hash_lookup(machines, id))->name,
7ac48069 60 oldval, icnt);
5eaef520 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");
68bbc9c3 71 }
72 }
208a4f4a 73}
68bbc9c3 74
75
7ac48069 76void check_nfs_counts(int id, void *nfsphys, void *hint)
208a4f4a 77{
7ac48069 78 struct nfsphys *n = nfsphys;
5eaef520 79 EXEC SQL BEGIN DECLARE SECTION;
05d03f93 80 int iid = id, rowcount;
81 unsigned long long val;
82 char valstr[40] = {0}, *endptr = valstr+39;
5eaef520 83 EXEC SQL END DECLARE SECTION;
84
85 val = n->count;
86 if (n->allocated != val)
87 {
05d03f93 88 printf("Count wrong on NFSphys %s:%s; is %lld in db, counted %lld\n",
5eaef520 89 ((struct machine *) hash_lookup(machines, n->mach_id))->name,
90 n->dir, n->allocated, val);
91 if (single_fix("Update", 1))
92 {
05d03f93 93 strcpy(valstr, ulltostr(val, endptr));
94 EXEC SQL UPDATE nfsphys SET allocated = TO_NUMBER(:valstr)
5eaef520 95 WHERE nfsphys_id = :iid;
96 rowcount = sqlca.sqlerrd[2];
97 if (rowcount > 0)
98 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
99 else
100 printf("Not fixed\n");
101 modified("nfsphys");
68bbc9c3 102 }
103 }
208a4f4a 104}
68bbc9c3 105
106
7ac48069 107void phase4(void)
208a4f4a 108{
5eaef520 109 struct hash *boxes, *counts;
110 int id, cnt;
111
112 printf("Phase 4 - Checking counts\n");
113
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;
121 while (1)
122 {
123 EXEC SQL FETCH csr401 INTO :id, :cnt;
124 if (sqlca.sqlcode)
125 break;
126
7ac48069 127 if (hash_store(boxes, id, (void *)1) == -1)
5eaef520 128 out_of_mem("storing poboxes");
7ac48069 129 if (hash_store(counts, id, (void *)cnt) == -1)
5eaef520 130 out_of_mem("storing pobox counts in hash table");
208a4f4a 131 }
5eaef520 132 EXEC SQL CLOSE csr401;
133 hash_step(users, count_boxes, boxes);
134 hash_step(boxes, check_box_counts, counts);
68bbc9c3 135
5eaef520 136 dprintf("Doing NFSphys...\n");
137 hash_step(nfsphys, check_nfs_counts, 0);
208a4f4a 138}
This page took 0.180629 seconds and 5 git commands to generate.