From 0ce1f7308efff0290bda1c9854ca7ec29ee0fbd9 Mon Sep 17 00:00:00 2001 From: mar Date: Mon, 28 Aug 1989 19:15:30 +0000 Subject: [PATCH] make sure that incremental_init() can be called multiple times without bad side effects; fix do_incremental_update() to read config from database --- server/increment.qc | 74 +++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/server/increment.qc b/server/increment.qc index 7f682a9d..3f7771cf 100644 --- a/server/increment.qc +++ b/server/increment.qc @@ -40,7 +40,7 @@ static char *after[MAXARGC]; static int afterc; /* structures to save entire sets of incremental changes */ -struct save_queue *incremental_sq; +struct save_queue *incremental_sq = NULL; struct iupdate { char *table; int beforec; @@ -88,7 +88,8 @@ incremental_init() aarg12 = after[12]; aarg13 = after[13]; aarg14 = after[14]; - incremental_sq = sq_create(); + if (incremental_sq == NULL) + incremental_sq = sq_create(); } @@ -329,34 +330,61 @@ incremental_update() } -/* THIS IS WRONG. We should keep a table of services getting incremental - * updates. But for now, just assume AFS +/* Actually start incremental updates. This caches the update table + * the first time it is called. */ +struct inc_cache { + struct inc_cache *next; + char *table; + char *service; +}; + + invoke_updates(argv, argc) char **argv; int argc; -{ +##{ + static int inited = 0; + static struct inc_cache *cache; + struct inc_cache *c; +## char tab[17], serv[17]; int pid, i; - char *prog; - - prog = "/u1/sms/bin/afs.incr"; - argv[0] = prog; - argv[argc] = 0; - pid = vfork(); - switch (pid) { - case 0: - for (i = getdtablesize() - 1; i > 2; i--) - close(i); - execv(prog, argv); - exit(1); - case -1: - com_err(whoami, 0, "Failed to start incremental update"); - return; - default: - return; + char prog[64]; + + if (!inited) { + inited++; + +## retrieve (tab = incremental.table, serv = incremental.service) { + c = (struct inc_cache *)malloc(sizeof(struct inc_cache)); + c->next = cache; + c->table = strsave(tab); + c->service = strsave(serv); + cache = c; +## } } -} + + for (c = cache; c; c = c->next) { + if (!strcmp(c->table, argv[1])) { + sprintf(prog, "/u1/sms/bin/%s.incr", c->table); + argv[0] = prog; + argv[argc] = 0; + pid = vfork(); + switch (pid) { + case 0: + for (i = getdtablesize() - 1; i > 2; i--) + close(i); + execv(prog, argv); + exit(1); + case -1: + com_err(whoami, 0, "Failed to start incremental update"); + return; + default: + return; + } + } + } +##} /* Called when the current transaction is aborted to throw away any queued -- 2.45.2