]> andersk Git - moira.git/blobdiff - server/increment.qc
mucked with host table authorization checks...
[moira.git] / server / increment.qc
index b792ca5b29726460ccc348d7d75210d326c7972d..c7b3b720f1d218b23e8d92bf6f7e1e89b0cb284b 100644 (file)
@@ -14,11 +14,16 @@ static char *rcsid_qrtn_qc = "$Header$";
 #endif lint
 
 #include <mit-copyright.h>
-#include <sms.h>
+#include <moira.h>
 #include "query.h"
-#include "sms_server.h"
+#include "mr_server.h"
 
 extern char *whoami;
+char *malloc();
+
+int inc_pid = 0;
+int inc_running = 0;
+time_t inc_started;
 
 #define MAXARGC 15
 
@@ -41,12 +46,14 @@ static int afterc;
 
 /* structures to save entire sets of incremental changes */
 struct save_queue *incremental_sq = NULL;
+struct save_queue *incremental_exec = NULL;
 struct iupdate {
     char *table;
     int beforec;
     char **before;
     int afterc;
     char **after;
+    char *service;
 };
 
 
@@ -90,6 +97,8 @@ incremental_init()
     aarg14 = after[14];
     if (incremental_sq == NULL)
       incremental_sq = sq_create();
+    if (incremental_exec == NULL)
+      incremental_exec = sq_create();
 }
 
 
@@ -99,7 +108,7 @@ incremental_init()
 char **argv;
 ##{
 ##  int id;
-    char buffer[512];
+    char buffer[512], *name;
 
     beforetable = table;
 
@@ -135,14 +144,15 @@ char **argv;
 ##               barg10 = fs.lockertype)
 ##       where qual
        beforec = 11;
-    } else if (!strcmp(table, "nfsquota")) {
-       strcpy(barg0, argv[0]);
+    } else if (!strcmp(table, "quota")) {
+       strcpy(barg0, "?");
        strcpy(barg1, argv[1]);
-       sprintf(buffer, "%s and filesys.filsys_id = nq.filsys_id", qual);
+       strcpy(barg2, "?");
+       sprintf(buffer, "%s and filesys.filsys_id = q.filsys_id", qual);
        qual = buffer;
-##     range of nq is nfsquota
-##     retrieve (barg2 = text(nq.quota), barg3 = filesys.name) where qual
-       beforec = 4;
+##     range of q is quota
+##     retrieve (barg3 = text(q.quota), barg4 = filesys.name) where qual
+       beforec = 5;
     } else if (!strcmp(table, "list")) {
 ##     retrieve (barg0 = l.name, barg1 = text(l.active),
 ##               barg2 = text(l.public), barg3 = text(l.hidden),
@@ -153,21 +163,24 @@ char **argv;
        beforec = 10;
     } else if (!strcmp(table, "members")) {
        id = (int) argv[0];
-##     repeat retrieve (barg0 = list.name) where list.list_id = @id
+##     retrieve (barg3 = text(list.group)) where list.list_id = id
+       name = malloc(0);
+       id_to_name(id, "LIST", &name);
+       strcpy(barg0, name);
        strcpy(barg1, argv[1]);
        id = (int) argv[2];
        if (!strcmp(barg1, "USER")) {
-##         repeat retrieve (barg2 = users.login) where users.users_id = @id
+           id_to_name(id, barg1, &name);
        } else if (!strcmp(barg1, "LIST")) {
-##         repeat retrieve (barg2 = list.name) where list.list_id = @id
+           id_to_name(id, barg1, &name);
        } else if (!strcmp(barg1, "STRING")) {
-##         repeat retrieve (barg2 = strings.string)
-##             where strings.string_id = @id
+           id_to_name(id, barg1, &name);
        } else if (!strcmp(barg1, "KERBEROS")) {
-##         repeat retrieve (barg2 = strings.string)
-##             where strings.string_id = @id
+           id_to_name(id, "STRING", &name);
        }
-       beforec = 3;
+       strcpy(barg2, name);
+       free(name);
+       beforec = 4;
     } /* else
       com_err(whoami, 0, "unknown table in incremental_before"); */
 ##}
@@ -190,7 +203,7 @@ incremental_clear_after()
 ##char *qual;
 char **argv;
 ##{
-    char buffer[2048];
+    char buffer[2048], *name;
 ##  int id, i;
     struct iupdate *iu;
     char **copy_argv();
@@ -228,14 +241,15 @@ char **argv;
 ##               aarg10 = fs.lockertype)
 ##       where qual
        afterc = 11;
-    } else if (!strcmp(table, "nfsquota")) {
-       strcpy(aarg0, argv[0]);
+    } else if (!strcmp(table, "quota")) {
+       strcpy(aarg0, "?");
        strcpy(aarg1, argv[1]);
-       sprintf(buffer, "%s and filesys.filsys_id = nq.filsys_id", qual);
+       strcpy(aarg2, "?");
+       sprintf(buffer, "%s and filesys.filsys_id = q.filsys_id", qual);
        qual = buffer;
-##     range of nq is nfsquota
-##     retrieve (aarg2 = text(nq.quota), aarg3 = filesys.name) where qual
-       afterc = 4;
+##     range of q is quota
+##     retrieve (aarg3 = text(q.quota), aarg4 = filesys.name) where qual
+       afterc = 5;
     } else if (!strcmp(table, "list")) {
 ##     retrieve (aarg0 = l.name, aarg1 = text(l.active),
 ##               aarg2 = text(l.public), aarg3 = text(l.hidden),
@@ -246,21 +260,24 @@ char **argv;
        afterc = 10;
     } else if (!strcmp(table, "members")) {
        id = (int) argv[0];
-##     repeat retrieve (aarg0 = list.name) where list.list_id = @id
+##     retrieve (aarg3 = text(list.group)) where list.list_id = id
+       name = malloc(0);
+       id_to_name(id, "LIST", &name);
+       strcpy(aarg0, name);
        strcpy(aarg1, argv[1]);
        id = (int) argv[2];
        if (!strcmp(aarg1, "USER")) {
-##         repeat retrieve (aarg2 = users.login) where users.users_id = @id
+           id_to_name(id, aarg1, &name);
        } else if (!strcmp(aarg1, "LIST")) {
-##         repeat retrieve (aarg2 = list.name) where list.list_id = @id
+           id_to_name(id, aarg1, &name);
        } else if (!strcmp(aarg1, "STRING")) {
-##         repeat retrieve (aarg2 = strings.string)
-##             where strings.string_id = @id
+           id_to_name(id, aarg1, &name);
        } else if (!strcmp(aarg1, "KERBEROS")) {
-##         repeat retrieve (aarg2 = strings.string)
-##             where strings.string_id = @id
+           id_to_name(id, "STRING", &name);
        }
-       afterc = 3;
+       strcpy(aarg2, name);
+       free(name);
+       afterc = 4;
     } else if (!strcmp(table, "clear")) {
        afterc = 0;
        table = beforetable;
@@ -268,7 +285,7 @@ char **argv;
       com_err(whoami, 0, "unknown table in incremental_after"); */
 
     iu = (struct iupdate *) malloc(sizeof(struct iupdate));
-    iu->table = table;
+    iu->table = strsave(table);
     iu->beforec = beforec;
     iu->before = copy_argv(before, beforec);
     iu->afterc = afterc;
@@ -301,37 +318,8 @@ char **argv;
 
 
 /* Called when the current transaction is committed to start any queued
- * incremental updates
- */
-
-incremental_update()
-{
-    struct iupdate *iu;
-    char *argv[MAXARGC * 2 + 4], cafter[3], cbefore[3];
-    int i;
-
-    while (sq_get_data(incremental_sq, &iu)) {
-       argv[1] = iu->table;
-       sprintf(cbefore, "%d", iu->beforec);
-       argv[2] = cbefore;
-       sprintf(cafter, "%d", iu->afterc);
-       argv[3] = cafter;
-       for (i = 0; i < iu->beforec; i++)
-         argv[4 + i] = iu->before[i];
-       for (i = 0; i < iu->afterc; i++)
-         argv[4 + iu->beforec + i] = iu->after[i];
-       invoke_updates(argv, 4 + iu->beforec + iu->afterc);
-       free_argv(iu->before, iu->beforec);
-       free_argv(iu->after, iu->afterc);
-       free(iu);
-    }
-    sq_destroy(incremental_sq);
-    incremental_sq = sq_create();
-}
-
-
-/* Actually start incremental updates.  This caches the update table
- * the first time it is called.
+ * incremental updates.  This caches the update table the first time it
+ * is called.
  */
 
 struct inc_cache {
@@ -341,16 +329,13 @@ struct inc_cache {
 };
 
 
-invoke_updates(argv, argc)
-char **argv;
-int argc;
-##{
+incremental_update()
+{
     static int inited = 0;
     static struct inc_cache *cache;
     struct inc_cache *c;
 ##  char tab[17], serv[17];
-    int pid, i;
-    char prog[64];
+    struct iupdate *iu;
 
     if (!inited) {
        inited++;
@@ -364,30 +349,71 @@ int argc;
 ##     }
     }
 
-    for (c = cache; c; c = c->next) {
-       if (!strcmp(c->table, argv[1])) {
-           sprintf(prog, "%s/%s.incr", BIN_DIR, c->service);
-#ifdef DEBUG
-           com_err(whoami, 0, "forking %s", prog);
-#endif
-           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;
+    while (sq_remove_data(incremental_sq, &iu)) {
+       for (c = cache; c; c = c->next) {
+           if (!strcmp(c->table, iu->table)) {
+               iu->service = c->service;
+               sq_save_data(incremental_exec, iu);
            }
        }
     }
-##}
+    if (inc_running == 0)
+      next_incremental();
+}
+
+
+next_incremental()
+{
+    struct iupdate *iu;
+    char *argv[MAXARGC * 2 + 4], cafter[3], cbefore[3], prog[BUFSIZ];
+    int i;
+
+    if (incremental_exec == NULL)
+      incremental_init();
+
+    if (sq_empty(incremental_exec) ||
+       (inc_running && now - inc_started < INC_TIMEOUT))
+      return;
+
+    if (inc_running)
+      com_err(whoami, 0, "incremental timeout on pid %d", inc_pid);
+
+    sq_remove_data(incremental_exec, &iu);
+    argv[1] = iu->table;
+    sprintf(cbefore, "%d", iu->beforec);
+    argv[2] = cbefore;
+    sprintf(cafter, "%d", iu->afterc);
+    argv[3] = cafter;
+    for (i = 0; i < iu->beforec; i++)
+      argv[4 + i] = iu->before[i];
+    for (i = 0; i < iu->afterc; i++)
+      argv[4 + iu->beforec + i] = iu->after[i];
+
+    sprintf(prog, "%s/%s.incr", BIN_DIR, iu->service);
+#ifdef DEBUG
+    com_err(whoami, 0, "forking %s", prog);
+#endif
+    argv[0] = prog;
+    argv[4 + iu->beforec + iu->afterc] = 0;
+    inc_pid = vfork();
+    switch (inc_pid) {
+    case 0:
+       execv(prog, argv);
+       exit(1);
+    case -1:
+       com_err(whoami, 0, "Failed to start incremental update");
+       break;
+    default:
+       inc_running = 1;
+       inc_started = now;
+    }
+
+    free_argv(iu->before, iu->beforec);
+    free_argv(iu->after, iu->afterc);
+    free(iu->table);
+    free(iu);
+
+}
 
 
 /* Called when the current transaction is aborted to throw away any queued
@@ -401,6 +427,7 @@ incremental_flush()
     while (sq_get_data(incremental_sq, &iu)) {
        free_argv(iu->before, iu->beforec);
        free_argv(iu->after, iu->afterc);
+       free(iu->table);
        free(iu);
     }
     sq_destroy(incremental_sq);
This page took 0.047737 seconds and 4 git commands to generate.