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")) {
148 strcpy(barg0, argv[0]);
149 if (!strcmp(argv[1], "USER") || !strcmp(argv[1], "GROUP") ||
150 !strcmp(argv[1], "LIST") || !strcmp(argv[1], "ANY")) {
151 strcpy(barg1, argv[1]);
152 strcpy(barg2, argv[2]);
154 strcpy(barg1, "USER");
155 strcpy(barg2, argv[1]);
157 sprintf(buffer, "%s and filesys.filsys_id = q.filsys_id", qual);
159 ## range of q is quota
160 ## retrieve (barg3 = text(q.quota), barg4 = filesys.name) where qual
162 } else if (!strcmp(table, "list")) {
163 ## retrieve (barg0 = l.name, barg1 = text(l.active),
164 ## barg2 = text(l.public), barg3 = text(l.hidden),
165 ## barg4 = text(l.maillist), barg5 = text(l.group),
166 ## barg6 = text(l.gid), barg7 = l.acl_type,
167 ## barg8 = text(l.acl_id), barg9 = l.desc)
170 } else if (!strcmp(table, "members")) {
173 id_to_name(id, "LIST", &name);
175 strcpy(barg1, argv[1]);
177 if (!strcmp(barg1, "USER")) {
178 id_to_name(id, barg1, &name);
179 } else if (!strcmp(barg1, "LIST")) {
180 id_to_name(id, barg1, &name);
181 } else if (!strcmp(barg1, "STRING")) {
182 id_to_name(id, barg1, &name);
183 } else if (!strcmp(barg1, "KERBEROS")) {
184 id_to_name(id, "STRING", &name);
190 com_err(whoami, 0, "unknown table in incremental_before"); */
194 incremental_clear_before()
199 incremental_clear_after()
201 incremental_after("clear", 0);
206 ##incremental_after(table, qual, argv)
211 char buffer[2048], *name;
216 if (!strcmp(table, "users")) {
217 ## retrieve (aarg0 = u.login, aarg1 = text(u.uid),
218 ## aarg2 = u.shell, aarg3 = u.last, aarg4 = u.first,
219 ## aarg5 = u.middle, aarg6 = text(u.status),
220 ## aarg7 = u.mit_id, aarg8 = u.mit_year)
223 } else if (!strcmp(table, "machine")) {
224 ## retrieve (aarg0 = m.name, aarg1 = m.type) where qual
226 } else if (!strcmp(table, "cluster")) {
227 ## retrieve (aarg0 = c.name, aarg1 = c.desc, aarg2 = c.location)
230 } else if (!strcmp(table, "mcmap")) {
231 strcpy(aarg0, argv[0]);
232 strcpy(aarg1, argv[1]);
234 } else if (!strcmp(table, "svc")) {
235 strcpy(aarg0, argv[0]);
236 strcpy(aarg1, argv[1]);
237 strcpy(aarg2, argv[2]);
239 } else if (!strcmp(table, "filesys")) {
240 ## range of fs is filesys
241 ## retrieve (aarg0 = fs.label, aarg1 = fs.type,
242 ## aarg2 = text(fs.mach_id),
243 ## aarg3 = fs.name, aarg4 = fs.mount, aarg5 = fs.access,
244 ## aarg6 = fs.comments, aarg7 = text(fs.owner),
245 ## aarg8 = text(fs.owners), aarg9 = text(fs.createflg),
246 ## aarg10 = fs.lockertype)
249 } else if (!strcmp(table, "quota")) {
250 strcpy(aarg0, argv[0]);
251 strcpy(aarg1, argv[1]);
252 strcpy(aarg2, argv[2]);
253 sprintf(buffer, "%s and filesys.filsys_id = q.filsys_id", qual);
255 ## range of q is quota
256 ## retrieve (aarg3 = text(q.quota), aarg4 = filesys.name) where qual
258 } else if (!strcmp(table, "list")) {
259 ## retrieve (aarg0 = l.name, aarg1 = text(l.active),
260 ## aarg2 = text(l.public), aarg3 = text(l.hidden),
261 ## aarg4 = text(l.maillist), aarg5 = text(l.group),
262 ## aarg6 = text(l.gid), aarg7 = l.acl_type,
263 ## aarg8 = text(l.acl_id), aarg9 = l.desc)
266 } else if (!strcmp(table, "members")) {
269 id_to_name(id, "LIST", &name);
271 strcpy(aarg1, argv[1]);
273 if (!strcmp(aarg1, "USER")) {
274 id_to_name(id, aarg1, &name);
275 } else if (!strcmp(aarg1, "LIST")) {
276 id_to_name(id, aarg1, &name);
277 } else if (!strcmp(aarg1, "STRING")) {
278 id_to_name(id, aarg1, &name);
279 } else if (!strcmp(aarg1, "KERBEROS")) {
280 id_to_name(id, "STRING", &name);
285 } else if (!strcmp(table, "clear")) {
289 com_err(whoami, 0, "unknown table in incremental_after"); */
291 iu = (struct iupdate *) malloc(sizeof(struct iupdate));
292 iu->table = strsave(table);
293 iu->beforec = beforec;
294 iu->before = copy_argv(before, beforec);
296 iu->after = copy_argv(after, afterc);
297 sq_save_data(incremental_sq, iu);
300 sprintf(buffer, "INCREMENTAL(%s, [", table);
301 for (i = 0; i < beforec; i++) {
303 strcat(buffer, strtrim(before[0]));
305 strcat(buffer, ", ");
306 strcat(buffer, strtrim(before[i]));
309 strcat(buffer, "], [");
310 for (i = 0; i < afterc; i++) {
312 strcat(buffer, strtrim(after[0]));
314 strcat(buffer, ", ");
315 strcat(buffer, strtrim(after[i]));
318 strcat(buffer, "])");
319 com_err(whoami, 0, buffer);
324 /* Called when the current transaction is committed to start any queued
325 * incremental updates. This caches the update table the first time it
330 struct inc_cache *next;
338 static int inited = 0;
339 static struct inc_cache *cache;
341 ## char tab[17], serv[17];
347 ## retrieve (tab = incremental.table, serv = incremental.service) {
348 c = (struct inc_cache *)malloc(sizeof(struct inc_cache));
350 c->table = strsave(strtrim(tab));
351 c->service = strsave(strtrim(serv));
356 while (sq_remove_data(incremental_sq, &iu)) {
357 for (c = cache; c; c = c->next) {
358 if (!strcmp(c->table, iu->table)) {
359 iu->service = c->service;
360 sq_save_data(incremental_exec, iu);
364 if (inc_running == 0)
372 char *argv[MAXARGC * 2 + 4], cafter[3], cbefore[3], prog[BUFSIZ];
375 if (incremental_exec == NULL)
378 if (sq_empty(incremental_exec) ||
379 (inc_running && now - inc_started < INC_TIMEOUT))
383 com_err(whoami, 0, "incremental timeout on pid %d", inc_pid);
385 sq_remove_data(incremental_exec, &iu);
387 sprintf(cbefore, "%d", iu->beforec);
389 sprintf(cafter, "%d", iu->afterc);
391 for (i = 0; i < iu->beforec; i++)
392 argv[4 + i] = iu->before[i];
393 for (i = 0; i < iu->afterc; i++)
394 argv[4 + iu->beforec + i] = iu->after[i];
396 sprintf(prog, "%s/%s.incr", BIN_DIR, iu->service);
398 com_err(whoami, 0, "forking %s", prog);
401 argv[4 + iu->beforec + iu->afterc] = 0;
408 com_err(whoami, 0, "Failed to start incremental update");
415 free_argv(iu->before, iu->beforec);
416 free_argv(iu->after, iu->afterc);
423 /* Called when the current transaction is aborted to throw away any queued
424 * incremental updates
431 while (sq_get_data(incremental_sq, &iu)) {
432 free_argv(iu->before, iu->beforec);
433 free_argv(iu->after, iu->afterc);
437 sq_destroy(incremental_sq);
438 incremental_sq = sq_create();
442 char **copy_argv(argv, argc)
446 char **ret = (char **)malloc(sizeof(char *) * argc);
448 ret[argc] = strsave(strtrim(argv[argc]));
452 free_argv(argv, argc)