]> andersk Git - moira.git/blame - server/increment.qc
add hesiod library to link line; rebuild dependancies
[moira.git] / server / increment.qc
CommitLineData
7593ae52 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
6 * Copyright (C) 1989 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
9 *
10 */
11
12#ifndef lint
13static char *rcsid_qrtn_qc = "$Header$";
14#endif lint
15
16#include <mit-copyright.h>
17#include <sms.h>
18#include "query.h"
19#include "sms_server.h"
20
21extern char *whoami;
77de3714 22char *malloc();
23
24int inc_pid = 0;
25int inc_running = 0;
26time_t inc_started;
7593ae52 27
28#define MAXARGC 15
29
30/* structures to save before args */
31static char beforeb[MAXARGC][ARGLEN];
32static char *before[MAXARGC];
33##char *barg0, *barg1, *barg2, *barg3, *barg4;
34##char *barg5, *barg6, *barg7, *barg8, *barg9;
35##char *barg10, *barg11, *barg12, *barg13, *barg14;
36static int beforec;
37static char *beforetable;
38
39/* structures to save after args */
40static char afterb[MAXARGC][ARGLEN];
41static char *after[MAXARGC];
42##char *aarg0, *aarg1, *aarg2, *aarg3, *aarg4;
43##char *aarg5, *aarg6, *aarg7, *aarg8, *aarg9;
44##char *aarg10, *aarg11, *aarg12, *aarg13, *aarg14;
45static int afterc;
46
47/* structures to save entire sets of incremental changes */
0ce1f730 48struct save_queue *incremental_sq = NULL;
77de3714 49struct save_queue *incremental_exec = NULL;
7593ae52 50struct iupdate {
51 char *table;
52 int beforec;
53 char **before;
54 int afterc;
55 char **after;
77de3714 56 char *service;
7593ae52 57};
58
59
60incremental_init()
61{
62 int i;
63
64 for (i = 0; i < MAXARGC; i++) {
65 before[i] = &beforeb[i][0];
66 after[i] = &afterb[i][0];
67 }
68 barg0 = before[0];
69 barg1 = before[1];
70 barg2 = before[2];
71 barg3 = before[3];
72 barg4 = before[4];
73 barg5 = before[5];
74 barg6 = before[6];
75 barg7 = before[7];
76 barg8 = before[8];
77 barg9 = before[9];
78 barg10 = before[10];
79 barg11 = before[11];
80 barg12 = before[12];
81 barg13 = before[13];
82 barg14 = before[14];
83 aarg0 = after[0];
84 aarg1 = after[1];
85 aarg2 = after[2];
86 aarg3 = after[3];
87 aarg4 = after[4];
88 aarg5 = after[5];
89 aarg6 = after[6];
90 aarg7 = after[7];
91 aarg8 = after[8];
92 aarg9 = after[9];
93 aarg10 = after[10];
94 aarg11 = after[11];
95 aarg12 = after[12];
96 aarg13 = after[13];
97 aarg14 = after[14];
0ce1f730 98 if (incremental_sq == NULL)
99 incremental_sq = sq_create();
77de3714 100 if (incremental_exec == NULL)
101 incremental_exec = sq_create();
7593ae52 102}
103
104
105##incremental_before(table, qual, argv)
106##char *table;
107##char *qual;
108char **argv;
109##{
110## int id;
77de3714 111 char buffer[512], *name;
7593ae52 112
113 beforetable = table;
114
115 if (!strcmp(table, "users")) {
116## retrieve (barg0 = u.login, barg1 = text(u.uid),
117## barg2 = u.shell, barg3 = u.last, barg4 = u.first,
118## barg5 = u.middle, barg6 = text(u.status),
119## barg7 = u.mit_id, barg8 = u.mit_year)
120## where qual
121 beforec = 9;
122 } else if (!strcmp(table, "machine")) {
123## retrieve (barg0 = m.name, barg1 = m.type) where qual
124 beforec = 2;
125 } else if (!strcmp(table, "cluster")) {
126## retrieve (barg0 = c.name, barg1 = c.desc, barg2 = c.location)
127## where qual
128 beforec = 3;
129 } else if (!strcmp(table, "mcmap")) {
130 strcpy(barg0, argv[0]);
131 strcpy(barg1, argv[1]);
132 beforec = 2;
133 } else if (!strcmp(table, "svc")) {
134 strcpy(barg0, argv[0]);
135 strcpy(barg1, argv[1]);
136 strcpy(barg2, argv[2]);
137 beforec = 3;
138 } else if (!strcmp(table, "filesys")) {
139## range of fs is filesys
140## retrieve (barg0 = fs.label, barg1 = fs.type, barg2 = text(fs.mach_id),
141## barg3 = fs.name, barg4 = fs.mount, barg5 = fs.access,
142## barg6 = fs.comments, barg7 = text(fs.owner),
143## barg8 = text(fs.owners), barg9 = text(fs.createflg),
144## barg10 = fs.lockertype)
145## where qual
146 beforec = 11;
147 } else if (!strcmp(table, "nfsquota")) {
148 strcpy(barg0, argv[0]);
149 strcpy(barg1, argv[1]);
150 sprintf(buffer, "%s and filesys.filsys_id = nq.filsys_id", qual);
151 qual = buffer;
152## range of nq is nfsquota
153## retrieve (barg2 = text(nq.quota), barg3 = filesys.name) where qual
154 beforec = 4;
155 } else if (!strcmp(table, "list")) {
156## retrieve (barg0 = l.name, barg1 = text(l.active),
157## barg2 = text(l.public), barg3 = text(l.hidden),
158## barg4 = text(l.maillist), barg5 = text(l.group),
159## barg6 = text(l.gid), barg7 = l.acl_type,
160## barg8 = text(l.acl_id), barg9 = l.desc)
161## where qual
162 beforec = 10;
163 } else if (!strcmp(table, "members")) {
164 id = (int) argv[0];
77de3714 165 name = malloc(0);
166 id_to_name(id, "LIST", &name);
167 strcpy(barg0, name);
7593ae52 168 strcpy(barg1, argv[1]);
169 id = (int) argv[2];
170 if (!strcmp(barg1, "USER")) {
77de3714 171 id_to_name(id, barg1, &name);
7593ae52 172 } else if (!strcmp(barg1, "LIST")) {
77de3714 173 id_to_name(id, barg1, &name);
7593ae52 174 } else if (!strcmp(barg1, "STRING")) {
77de3714 175 id_to_name(id, barg1, &name);
7593ae52 176 } else if (!strcmp(barg1, "KERBEROS")) {
77de3714 177 id_to_name(id, "STRING", &name);
7593ae52 178 }
77de3714 179 strcpy(barg2, name);
180 free(name);
7593ae52 181 beforec = 3;
182 } /* else
183 com_err(whoami, 0, "unknown table in incremental_before"); */
184##}
185
186
187incremental_clear_before()
188{
189 beforec = 0;
190}
191
192incremental_clear_after()
193{
194 incremental_after("clear", 0);
195}
196
197
198
199##incremental_after(table, qual, argv)
200##char *table;
201##char *qual;
202char **argv;
203##{
77de3714 204 char buffer[2048], *name;
7593ae52 205## int id, i;
206 struct iupdate *iu;
207 char **copy_argv();
208
209 if (!strcmp(table, "users")) {
210## retrieve (aarg0 = u.login, aarg1 = text(u.uid),
211## aarg2 = u.shell, aarg3 = u.last, aarg4 = u.first,
212## aarg5 = u.middle, aarg6 = text(u.status),
213## aarg7 = u.mit_id, aarg8 = u.mit_year)
214## where qual
215 afterc = 9;
216 } else if (!strcmp(table, "machine")) {
217## retrieve (aarg0 = m.name, aarg1 = m.type) where qual
218 afterc = 2;
219 } else if (!strcmp(table, "cluster")) {
220## retrieve (aarg0 = c.name, aarg1 = c.desc, aarg2 = c.location)
221## where qual
222 afterc = 3;
223 } else if (!strcmp(table, "mcmap")) {
224 strcpy(aarg0, argv[0]);
225 strcpy(aarg1, argv[1]);
226 afterc = 2;
227 } else if (!strcmp(table, "svc")) {
228 strcpy(aarg0, argv[0]);
229 strcpy(aarg1, argv[1]);
230 strcpy(aarg2, argv[2]);
231 afterc = 3;
232 } else if (!strcmp(table, "filesys")) {
233## range of fs is filesys
234## retrieve (aarg0 = fs.label, aarg1 = fs.type,
235## aarg2 = text(fs.mach_id),
236## aarg3 = fs.name, aarg4 = fs.mount, aarg5 = fs.access,
237## aarg6 = fs.comments, aarg7 = text(fs.owner),
238## aarg8 = text(fs.owners), aarg9 = text(fs.createflg),
239## aarg10 = fs.lockertype)
240## where qual
241 afterc = 11;
242 } else if (!strcmp(table, "nfsquota")) {
243 strcpy(aarg0, argv[0]);
244 strcpy(aarg1, argv[1]);
245 sprintf(buffer, "%s and filesys.filsys_id = nq.filsys_id", qual);
246 qual = buffer;
247## range of nq is nfsquota
248## retrieve (aarg2 = text(nq.quota), aarg3 = filesys.name) where qual
249 afterc = 4;
250 } else if (!strcmp(table, "list")) {
251## retrieve (aarg0 = l.name, aarg1 = text(l.active),
252## aarg2 = text(l.public), aarg3 = text(l.hidden),
253## aarg4 = text(l.maillist), aarg5 = text(l.group),
254## aarg6 = text(l.gid), aarg7 = l.acl_type,
255## aarg8 = text(l.acl_id), aarg9 = l.desc)
256## where qual
257 afterc = 10;
258 } else if (!strcmp(table, "members")) {
259 id = (int) argv[0];
77de3714 260 name = malloc(0);
261 id_to_name(id, "LIST", &name);
262 strcpy(aarg0, name);
7593ae52 263 strcpy(aarg1, argv[1]);
264 id = (int) argv[2];
265 if (!strcmp(aarg1, "USER")) {
77de3714 266 id_to_name(id, aarg1, &name);
7593ae52 267 } else if (!strcmp(aarg1, "LIST")) {
77de3714 268 id_to_name(id, aarg1, &name);
7593ae52 269 } else if (!strcmp(aarg1, "STRING")) {
77de3714 270 id_to_name(id, aarg1, &name);
7593ae52 271 } else if (!strcmp(aarg1, "KERBEROS")) {
77de3714 272 id_to_name(id, "STRING", &name);
7593ae52 273 }
77de3714 274 strcpy(aarg2, name);
275 free(name);
7593ae52 276 afterc = 3;
277 } else if (!strcmp(table, "clear")) {
278 afterc = 0;
279 table = beforetable;
280 } /* else
281 com_err(whoami, 0, "unknown table in incremental_after"); */
282
283 iu = (struct iupdate *) malloc(sizeof(struct iupdate));
77de3714 284 iu->table = strsave(table);
7593ae52 285 iu->beforec = beforec;
286 iu->before = copy_argv(before, beforec);
287 iu->afterc = afterc;
288 iu->after = copy_argv(after, afterc);
289 sq_save_data(incremental_sq, iu);
290
291#ifdef DEBUG
292 sprintf(buffer, "INCREMENTAL(%s, [", table);
293 for (i = 0; i < beforec; i++) {
294 if (i == 0)
295 strcat(buffer, strtrim(before[0]));
296 else {
297 strcat(buffer, ", ");
298 strcat(buffer, strtrim(before[i]));
299 }
300 }
301 strcat(buffer, "], [");
302 for (i = 0; i < afterc; i++) {
303 if (i == 0)
304 strcat(buffer, strtrim(after[0]));
305 else {
306 strcat(buffer, ", ");
307 strcat(buffer, strtrim(after[i]));
308 }
309 }
310 strcat(buffer, "])");
311 com_err(whoami, 0, buffer);
312#endif DEBUG
313##}
314
315
316/* Called when the current transaction is committed to start any queued
77de3714 317 * incremental updates. This caches the update table the first time it
318 * is called.
7593ae52 319 */
320
0ce1f730 321struct inc_cache {
322 struct inc_cache *next;
323 char *table;
324 char *service;
325};
326
327
77de3714 328incremental_update()
329{
0ce1f730 330 static int inited = 0;
331 static struct inc_cache *cache;
332 struct inc_cache *c;
333## char tab[17], serv[17];
77de3714 334 struct iupdate *iu;
0ce1f730 335
336 if (!inited) {
337 inited++;
338
339## retrieve (tab = incremental.table, serv = incremental.service) {
340 c = (struct inc_cache *)malloc(sizeof(struct inc_cache));
341 c->next = cache;
4ccf9fd5 342 c->table = strsave(strtrim(tab));
343 c->service = strsave(strtrim(serv));
0ce1f730 344 cache = c;
345## }
7593ae52 346 }
0ce1f730 347
77de3714 348 while (sq_remove_data(incremental_sq, &iu)) {
349 for (c = cache; c; c = c->next) {
350 if (!strcmp(c->table, iu->table)) {
351 iu->service = c->service;
352 sq_save_data(incremental_exec, iu);
0ce1f730 353 }
354 }
355 }
77de3714 356 if (inc_running == 0)
357 next_incremental();
358}
359
360
361next_incremental()
362{
363 struct iupdate *iu;
364 char *argv[MAXARGC * 2 + 4], cafter[3], cbefore[3], prog[BUFSIZ];
365 int i;
366
367 if (sq_empty(incremental_exec) ||
368 (inc_running && now - inc_started < INC_TIMEOUT))
369 return;
370
371 if (inc_running)
372 com_err(whoami, 0, "incremental timeout on pid %d", inc_pid);
373
374 sq_remove_data(incremental_exec, &iu);
375 argv[1] = iu->table;
376 sprintf(cbefore, "%d", iu->beforec);
377 argv[2] = cbefore;
378 sprintf(cafter, "%d", iu->afterc);
379 argv[3] = cafter;
380 for (i = 0; i < iu->beforec; i++)
381 argv[4 + i] = iu->before[i];
382 for (i = 0; i < iu->afterc; i++)
383 argv[4 + iu->beforec + i] = iu->after[i];
384
385 sprintf(prog, "%s/%s.incr", BIN_DIR, iu->service);
386#ifdef DEBUG
387 com_err(whoami, 0, "forking %s", prog);
388#endif
389 argv[0] = prog;
390 argv[4 + iu->beforec + iu->afterc] = 0;
391 inc_pid = vfork();
392 switch (inc_pid) {
393 case 0:
394 execv(prog, argv);
395 exit(1);
396 case -1:
397 com_err(whoami, 0, "Failed to start incremental update");
398 break;
399 default:
400 inc_running = 1;
401 inc_started = now;
402 }
403
404 free_argv(iu->before, iu->beforec);
405 free_argv(iu->after, iu->afterc);
406 free(iu->table);
407 free(iu);
408
409}
7593ae52 410
411
412/* Called when the current transaction is aborted to throw away any queued
413 * incremental updates
414 */
415
416incremental_flush()
417{
418 struct iupdate *iu;
419
420 while (sq_get_data(incremental_sq, &iu)) {
421 free_argv(iu->before, iu->beforec);
422 free_argv(iu->after, iu->afterc);
77de3714 423 free(iu->table);
7593ae52 424 free(iu);
425 }
426 sq_destroy(incremental_sq);
427 incremental_sq = sq_create();
428}
429
430
431char **copy_argv(argv, argc)
432char **argv;
433int argc;
434{
435 char **ret = (char **)malloc(sizeof(char *) * argc);
436 while (--argc >= 0)
437 ret[argc] = strsave(strtrim(argv[argc]));
438 return(ret);
439}
440
441free_argv(argv, argc)
442char **argv;
443int argc;
444{
445 while (--argc >= 0)
446 free(argv[argc]);
447 free(argv);
448}
This page took 0.11086 seconds and 5 git commands to generate.