6 * Copyright (C) 1989 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
13 static char *rcsid_qrtn_qc = "$Header$";
16 #include <mit-copyright.h>
19 #include "mr_server.h"
30 /* structures to save before args */
31 static char beforeb[MAXARGC][ARGLEN];
32 static char *before[MAXARGC];
33 ##char *barg0, *barg1, *barg2, *barg3, *barg4;
34 ##char *barg5, *barg6, *barg7, *barg8, *barg9;
35 ##char *barg10, *barg11, *barg12, *barg13, *barg14;
37 static char *beforetable;
39 /* structures to save after args */
40 static char afterb[MAXARGC][ARGLEN];
41 static char *after[MAXARGC];
42 ##char *aarg0, *aarg1, *aarg2, *aarg3, *aarg4;
43 ##char *aarg5, *aarg6, *aarg7, *aarg8, *aarg9;
44 ##char *aarg10, *aarg11, *aarg12, *aarg13, *aarg14;
47 /* structures to save entire sets of incremental changes */
48 struct save_queue *incremental_sq = NULL;
49 struct save_queue *incremental_exec = NULL;
64 for (i = 0; i < MAXARGC; i++) {
65 before[i] = &beforeb[i][0];
66 after[i] = &afterb[i][0];
98 if (incremental_sq == NULL)
99 incremental_sq = sq_create();
100 if (incremental_exec == NULL)
101 incremental_exec = sq_create();
105 ##incremental_before(table, qual, argv)
111 char buffer[512], *name;
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)
122 } else if (!strcmp(table, "machine")) {
123 ## retrieve (barg0 = m.name, barg1 = m.type) where qual
125 } else if (!strcmp(table, "cluster")) {
126 ## retrieve (barg0 = c.name, barg1 = c.desc, barg2 = c.location)
129 } else if (!strcmp(table, "mcmap")) {
130 strcpy(barg0, argv[0]);
131 strcpy(barg1, argv[1]);
133 } else if (!strcmp(table, "svc")) {
134 strcpy(barg0, argv[0]);
135 strcpy(barg1, argv[1]);
136 strcpy(barg2, argv[2]);
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)
147 } else if (!strcmp(table, "quota")) {
149 strcpy(barg1, argv[1]);
151 sprintf(buffer, "%s and filesys.filsys_id = q.filsys_id", qual);
153 ## range of q is quota
154 ## retrieve (barg3 = text(q.quota), barg4 = filesys.name) where qual
156 } else if (!strcmp(table, "list")) {
157 ## retrieve (barg0 = l.name, barg1 = text(l.active),
158 ## barg2 = text(l.public), barg3 = text(l.hidden),
159 ## barg4 = text(l.maillist), barg5 = text(l.group),
160 ## barg6 = text(l.gid), barg7 = l.acl_type,
161 ## barg8 = text(l.acl_id), barg9 = l.desc)
164 } else if (!strcmp(table, "members")) {
166 ## retrieve (barg3 = text(list.group)) where list.list_id = id
168 id_to_name(id, "LIST", &name);
170 strcpy(barg1, argv[1]);
172 if (!strcmp(barg1, "USER")) {
173 id_to_name(id, barg1, &name);
174 } else if (!strcmp(barg1, "LIST")) {
175 id_to_name(id, barg1, &name);
176 } else if (!strcmp(barg1, "STRING")) {
177 id_to_name(id, barg1, &name);
178 } else if (!strcmp(barg1, "KERBEROS")) {
179 id_to_name(id, "STRING", &name);
185 com_err(whoami, 0, "unknown table in incremental_before"); */
189 incremental_clear_before()
194 incremental_clear_after()
196 incremental_after("clear", 0);
201 ##incremental_after(table, qual, argv)
206 char buffer[2048], *name;
211 if (!strcmp(table, "users")) {
212 ## retrieve (aarg0 = u.login, aarg1 = text(u.uid),
213 ## aarg2 = u.shell, aarg3 = u.last, aarg4 = u.first,
214 ## aarg5 = u.middle, aarg6 = text(u.status),
215 ## aarg7 = u.mit_id, aarg8 = u.mit_year)
218 } else if (!strcmp(table, "machine")) {
219 ## retrieve (aarg0 = m.name, aarg1 = m.type) where qual
221 } else if (!strcmp(table, "cluster")) {
222 ## retrieve (aarg0 = c.name, aarg1 = c.desc, aarg2 = c.location)
225 } else if (!strcmp(table, "mcmap")) {
226 strcpy(aarg0, argv[0]);
227 strcpy(aarg1, argv[1]);
229 } else if (!strcmp(table, "svc")) {
230 strcpy(aarg0, argv[0]);
231 strcpy(aarg1, argv[1]);
232 strcpy(aarg2, argv[2]);
234 } else if (!strcmp(table, "filesys")) {
235 ## range of fs is filesys
236 ## retrieve (aarg0 = fs.label, aarg1 = fs.type,
237 ## aarg2 = text(fs.mach_id),
238 ## aarg3 = fs.name, aarg4 = fs.mount, aarg5 = fs.access,
239 ## aarg6 = fs.comments, aarg7 = text(fs.owner),
240 ## aarg8 = text(fs.owners), aarg9 = text(fs.createflg),
241 ## aarg10 = fs.lockertype)
244 } else if (!strcmp(table, "quota")) {
246 strcpy(aarg1, argv[1]);
248 sprintf(buffer, "%s and filesys.filsys_id = q.filsys_id", qual);
250 ## range of q is quota
251 ## retrieve (aarg3 = text(q.quota), aarg4 = filesys.name) where qual
253 } else if (!strcmp(table, "list")) {
254 ## retrieve (aarg0 = l.name, aarg1 = text(l.active),
255 ## aarg2 = text(l.public), aarg3 = text(l.hidden),
256 ## aarg4 = text(l.maillist), aarg5 = text(l.group),
257 ## aarg6 = text(l.gid), aarg7 = l.acl_type,
258 ## aarg8 = text(l.acl_id), aarg9 = l.desc)
261 } else if (!strcmp(table, "members")) {
263 ## retrieve (aarg3 = text(list.group)) where list.list_id = id
265 id_to_name(id, "LIST", &name);
267 strcpy(aarg1, argv[1]);
269 if (!strcmp(aarg1, "USER")) {
270 id_to_name(id, aarg1, &name);
271 } else if (!strcmp(aarg1, "LIST")) {
272 id_to_name(id, aarg1, &name);
273 } else if (!strcmp(aarg1, "STRING")) {
274 id_to_name(id, aarg1, &name);
275 } else if (!strcmp(aarg1, "KERBEROS")) {
276 id_to_name(id, "STRING", &name);
281 } else if (!strcmp(table, "clear")) {
285 com_err(whoami, 0, "unknown table in incremental_after"); */
287 iu = (struct iupdate *) malloc(sizeof(struct iupdate));
288 iu->table = strsave(table);
289 iu->beforec = beforec;
290 iu->before = copy_argv(before, beforec);
292 iu->after = copy_argv(after, afterc);
293 sq_save_data(incremental_sq, iu);
296 sprintf(buffer, "INCREMENTAL(%s, [", table);
297 for (i = 0; i < beforec; i++) {
299 strcat(buffer, strtrim(before[0]));
301 strcat(buffer, ", ");
302 strcat(buffer, strtrim(before[i]));
305 strcat(buffer, "], [");
306 for (i = 0; i < afterc; i++) {
308 strcat(buffer, strtrim(after[0]));
310 strcat(buffer, ", ");
311 strcat(buffer, strtrim(after[i]));
314 strcat(buffer, "])");
315 com_err(whoami, 0, buffer);
320 /* Called when the current transaction is committed to start any queued
321 * incremental updates. This caches the update table the first time it
326 struct inc_cache *next;
334 static int inited = 0;
335 static struct inc_cache *cache;
337 ## char tab[17], serv[17];
343 ## retrieve (tab = incremental.table, serv = incremental.service) {
344 c = (struct inc_cache *)malloc(sizeof(struct inc_cache));
346 c->table = strsave(strtrim(tab));
347 c->service = strsave(strtrim(serv));
352 while (sq_remove_data(incremental_sq, &iu)) {
353 for (c = cache; c; c = c->next) {
354 if (!strcmp(c->table, iu->table)) {
355 iu->service = c->service;
356 sq_save_data(incremental_exec, iu);
360 if (inc_running == 0)
368 char *argv[MAXARGC * 2 + 4], cafter[3], cbefore[3], prog[BUFSIZ];
371 if (incremental_exec == NULL)
374 if (sq_empty(incremental_exec) ||
375 (inc_running && now - inc_started < INC_TIMEOUT))
379 com_err(whoami, 0, "incremental timeout on pid %d", inc_pid);
381 sq_remove_data(incremental_exec, &iu);
383 sprintf(cbefore, "%d", iu->beforec);
385 sprintf(cafter, "%d", iu->afterc);
387 for (i = 0; i < iu->beforec; i++)
388 argv[4 + i] = iu->before[i];
389 for (i = 0; i < iu->afterc; i++)
390 argv[4 + iu->beforec + i] = iu->after[i];
392 sprintf(prog, "%s/%s.incr", BIN_DIR, iu->service);
394 com_err(whoami, 0, "forking %s", prog);
397 argv[4 + iu->beforec + iu->afterc] = 0;
404 com_err(whoami, 0, "Failed to start incremental update");
411 free_argv(iu->before, iu->beforec);
412 free_argv(iu->after, iu->afterc);
419 /* Called when the current transaction is aborted to throw away any queued
420 * incremental updates
427 while (sq_get_data(incremental_sq, &iu)) {
428 free_argv(iu->before, iu->beforec);
429 free_argv(iu->after, iu->afterc);
433 sq_destroy(incremental_sq);
434 incremental_sq = sq_create();
438 char **copy_argv(argv, argc)
442 char **ret = (char **)malloc(sizeof(char *) * argc);
444 ret[argc] = strsave(strtrim(argv[argc]));
448 free_argv(argv, argc)