]> andersk Git - moira.git/commitdiff
Made a common protection-server handling routine (pr_try) to handle
authorprobe <probe>
Mon, 27 Jul 1992 20:25:46 +0000 (20:25 +0000)
committerprobe <probe>
Mon, 27 Jul 1992 20:25:46 +0000 (20:25 +0000)
ptserver calls and retry appropriately.

Don't test for AFS stop file until we need to execute an AFS function.
There is no need to give errors when the function does not involve AFS.

Added prototypes of various internal stub routines, and re-organized the
functions.

Added some debugging code to test retry code.

incremental/afs.c

index 3714ad1720df6f4431ba8bdb3a8892500dbb70bc..5f930fbc1c059e5f7bdfb118521a5247797ed611 100644 (file)
 #include <afs/pterror.h>
 
 #define STOP_FILE "/moira/afs/noafs"
-#define PR_TRIES 3
-#define PR_DELAY 15
-
 #define file_exists(file) (access((file), F_OK) == 0)
 
 char *whoami;
 
+/* Main stub routines */
+int do_user();
+int do_list();
+int do_member();
+int do_filesys();
+int do_quota();
+
+/* Support stub routines */
+int run_cmd();
+int add_user_lists();
+int get_members();
+int edit_group();
+int pr_try();
+int check_afs();
+
+/* libprot.a routines */
+extern long pr_Initialize();
+extern long pr_CreateUser();
+extern long pr_CreateGroup();
+extern long pr_DeleteByID();
+extern long pr_ChangeEntry();
+extern long pr_SetFieldsEntry();
+extern long pr_AddToGroup();
+extern long pr_RemoveUserFromGroup();
+
+static char tbl_buf[1024];
+
 main(argc, argv)
 char **argv;
 int argc;
 {
     int beforec, afterc, i;
     char *table, **before, **after;
-    char buf[1024];
 
     for (i = getdtablesize() - 1; i > 2; i--)
       close(i);
@@ -47,37 +70,29 @@ int argc;
     after = &argv[4 + beforec];
     whoami = argv[0];
 
-    strcpy(buf, table);
-    strcat(buf, " (");
+    setlinebuf(stdout);
+
+    strcpy(tbl_buf, table);
+    strcat(tbl_buf, " (");
     for (i = 0; i < beforec; i++) {
        if (i > 0)
-         strcat(buf, ",");
-       strcat(buf, before[i]);
+         strcat(tbl_buf, ",");
+       strcat(tbl_buf, before[i]);
     }
-    strcat(buf, ")->(");
+    strcat(tbl_buf, ")->(");
     for (i = 0; i < afterc; i++) {
        if (i > 0)
-         strcat(buf, ",");
-       strcat(buf, after[i]);
+         strcat(tbl_buf, ",");
+       strcat(tbl_buf, after[i]);
     }
-    strcat(buf, ")");
+    strcat(tbl_buf, ")");
 #ifdef DEBUG
-    printf("%s\n", buf);
+    printf("%s\n", tbl_buf);
 #endif
 
     initialize_sms_error_table();
     initialize_krb_error_table();
 
-    for (i=0; file_exists(STOP_FILE); i++) {
-       if (i > 30) {
-           critical_alert("incremental",
-                          "AFS incremental failed (%s exists): %s",
-                          STOP_FILE, buf);
-           exit(1);
-       }
-       sleep(60);
-    }
-
     if (!strcmp(table, "users")) {
        do_user(before, beforec, after, afterc);
     } else if (!strcmp(table, "list")) {
@@ -93,42 +108,13 @@ int argc;
 }
 
 
-do_cmd(cmd)
-char *cmd;
-{
-    int success = 0, tries = 0;
-
-    while (success == 0 && tries < 2) {
-       if (tries++)
-           sleep(90);
-       com_err(whoami, 0, "Executing command: %s", cmd);
-       if (system(cmd) == 0)
-           success++;
-    }
-    if (!success)
-       critical_alert("incremental", "failed command: %s", cmd);
-}
-
-
-add_user_lists(ac, av, user)
-    int ac;
-    char *av[];
-    char *user;
-{
-    if (atoi(av[5])) {
-       sleep(1);                               /* give ptserver some time */
-       edit_group(1, av[0], "USER", user);
-    }
-}
-
-
 do_user(before, beforec, after, afterc)
 char **before;
 int beforec;
 char **after;
 int afterc;
 {
-    int astate, bstate, auid, buid, code, tries;
+    int astate, bstate, auid, buid, code;
     char hostname[64];
     char *av[2];
 
@@ -150,22 +136,9 @@ int afterc;
        /* No AFS related attributes have changed */
        return;
 
-    code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0);
-    if (code) {
-       critical_alert("incremental", "Couldn't initialize libprot: %s",
-                      error_message(code));
-       return;
-    }
-    
     if (astate == bstate) {
        /* Only a modify has to be done */
-       tries = 0;
-       while (code=pr_ChangeEntry(before[U_NAME], after[U_NAME], auid, "")) {
-           if (++tries > PR_TRIES)
-               break;
-           if (code == UNOQUORUM) { sleep(90); continue; }
-           sleep(PR_DELAY);
-       }
+       code = pr_try(pr_ChangeEntry, before[U_NAME], after[U_NAME], auid, "");
        if (code) {
            critical_alert("incremental",
                           "Couldn't change user %s (id %d) to %s (id %d): %s",
@@ -175,13 +148,7 @@ int afterc;
        return;
     }
     if (bstate == 1) {
-       tries = 0;
-       while (code = pr_DeleteByID(buid)) {
-           if (++tries > PR_TRIES)
-               break;
-           if (code == UNOQUORUM) { sleep(90); continue; }
-           sleep(PR_DELAY);
-       }
+       code = pr_try(pr_DeleteByID, buid);
        if (code && code != PRNOENT) {
            critical_alert("incremental",
                           "Couldn't delete user %s (id %d): %s",
@@ -190,13 +157,7 @@ int afterc;
        return;
     }
     if (astate == 1) {
-       tries = 0;
-       while (code = pr_CreateUser(after[U_NAME], &auid)) {
-           if (++tries > PR_TRIES)
-               break;
-           if (code == UNOQUORUM) { sleep(90); continue; }
-           sleep(PR_DELAY);
-       }
+       code = pr_try(pr_CreateUser, after[U_NAME], &auid);
        if (code) {
            critical_alert("incremental",
                           "Couldn't create user %s (id %d): %s",
@@ -230,7 +191,6 @@ int afterc;
 }
 
 
-
 do_list(before, beforec, after, afterc)
 char **before;
 int beforec;
@@ -238,7 +198,7 @@ char **after;
 int afterc;
 {
     register int agid, bgid;
-    int ahide, bhide, tries;
+    int ahide, bhide;
     long code, id;
     char hostname[64];
     char g1[PR_MAXNAMELEN], g2[PR_MAXNAMELEN];
@@ -257,13 +217,6 @@ int afterc;
     if (agid == 0 && bgid == 0)                        /* Not active groups */
        return;
 
-    code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0);
-    if (code) {
-       critical_alert("incremental", "Couldn't initialize libprot: %s",
-                      error_message(code));
-       return;
-    }
-
     if (agid && bgid) {
        if (strcmp(after[L_NAME], before[L_NAME])) {
            /* Only a modify is required */
@@ -271,13 +224,7 @@ int afterc;
            strcpy(g2, "system:");
            strcat(g1, before[L_NAME]);
            strcat(g2, after[L_NAME]);
-           tries = 0;
-           while (code = pr_ChangeEntry(g1, g2, -agid, "")) {
-               if (++tries > PR_TRIES)
-                   break;
-               if (code == UNOQUORUM) { sleep(90); continue; }
-               sleep(PR_DELAY);
-           }
+           code = pr_try(pr_ChangeEntry, g1, g2, -agid, "");
            if (code) {
                critical_alert("incremental",
                               "Couldn't change group %s (id %d) to %s (id %d): %s",
@@ -286,16 +233,9 @@ int afterc;
            }
        }
        if (ahide != bhide) {
-           tries = 0;
-           while (code = pr_SetFieldsEntry
-                  (-agid, PR_SF_ALLBITS,
-                   (ahide ?PRP_STATUS_ANY :PRP_GROUP_DEFAULT)>>PRIVATE_SHIFT,
-                   0 /*ngroups*/, 0 /*nusers*/)) {
-               if (++tries > PR_TRIES)
-                   break;
-               if (code == UNOQUORUM) { sleep(90); continue; }
-               sleep(PR_DELAY);
-           }
+           code = pr_try(pr_SetFieldsEntry, -agid, PR_SF_ALLBITS,
+                         (ahide ? PRP_STATUS_ANY : PRP_GROUP_DEFAULT) >>PRIVATE_SHIFT,
+                         0 /*ngroups*/, 0 /*nusers*/);
            if (code) {
                critical_alert("incremental",
                               "Couldn't set flags of group %s: %s",
@@ -305,13 +245,7 @@ int afterc;
        return;
     }
     if (bgid) {
-       tries = 0;
-       while (code = pr_DeleteByID(-bgid)) {
-           if (++tries > PR_TRIES)
-               break;
-           if (code == UNOQUORUM) { sleep(90); continue; }
-           sleep(PR_DELAY);
-       }
+       code = pr_try(pr_DeleteByID, -bgid);
        if (code && code != PRNOENT) {
            critical_alert("incremental",
                           "Couldn't delete group %s (id %d): %s",
@@ -324,13 +258,7 @@ int afterc;
        strcat(g1, after[L_NAME]);
        strcpy(g2, "system:administrators");
        id = -agid;
-       tries = 0;
-       while (code = pr_CreateGroup(g1, g2, &id)) {
-           if (++tries > PR_TRIES)
-               break;
-           if (code == UNOQUORUM) { sleep(90); continue; }
-           sleep(PR_DELAY);
-       }
+       code = pr_try(pr_CreateGroup, g1, g2, &id);
        if (code) {
            critical_alert("incremental",
                           "Couldn't create group %s (id %d): %s",
@@ -338,16 +266,9 @@ int afterc;
            return;
        }
        if (ahide) {
-           tries = 0;
-           while (code = pr_SetFieldsEntry
-                  (-agid, PR_SF_ALLBITS,
-                   (ahide ?PRP_STATUS_ANY :PRP_GROUP_DEFAULT)>>PRIVATE_SHIFT,
-                   0 /*ngroups*/, 0 /*nusers*/)) {
-               if (++tries > PR_TRIES)
-                   break;
-               if (code == UNOQUORUM) { sleep(90); continue; }
-               sleep(PR_DELAY);
-           }
+           code = pr_try(pr_SetFieldsEntry, -agid, PR_SF_ALLBITS,
+                         (ahide ? PRP_STATUS_ANY : PRP_GROUP_DEFAULT) >>PRIVATE_SHIFT,
+                         0 /*ngroups*/, 0 /*nusers*/);
            if (code) {
                critical_alert("incremental",
                               "Couldn't set flags of group %s: %s",
@@ -355,8 +276,6 @@ int afterc;
            }
        }
 
-       sleep(1);                               /* give ptserver some time */
-
        /* We need to make sure the group is properly populated */
        if (beforec < L_ACTIVE || atoi(before[L_ACTIVE]) == 0) return;
 
@@ -392,13 +311,6 @@ int afterc;
        (afterc < 4 || !atoi(after[LM_END])))
        return;
 
-    code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0);
-    if (code) {
-       critical_alert("incremental", "Couldn't initialize libprot: %s",
-                      error_message(code));
-       return;
-    }
-
     if (afterc) 
        edit_group(1, after[LM_LIST], after[LM_TYPE], after[LM_MEMBER]);
     if (beforec)
@@ -406,6 +318,108 @@ int afterc;
 }
 
 
+do_filesys(before, beforec, after, afterc)
+char **before;
+int beforec;
+char **after;
+int afterc;
+{
+    char cmd[1024];
+    
+    if (beforec < FS_CREATE) {
+       if (afterc < FS_CREATE || atoi(after[FS_CREATE])==0 ||
+           strcmp(after[FS_TYPE], "AFS"))
+           return;
+
+       /* new locker creation */
+       sprintf(cmd, "%s/perl -I%s %s/afs_create.pl %s %s %s %s %s %s",
+               BIN_DIR, BIN_DIR, BIN_DIR,
+               after[FS_NAME], after[FS_L_TYPE], after[FS_MACHINE],
+               after[FS_PACK], after[FS_OWNER], after[FS_OWNERS]);
+       run_cmd(cmd);
+       return;
+    }
+
+    /* What do we do?  When do we use FS_CREATE?
+     * 
+     * TYPE change:  AFS->ERR, ERR->AFS: rename/unmount/remount
+     * LOCKERTYPE change: rename/remount
+     * PACK change: remount
+     * LABEL change: rename/remount
+     * Deletion: rename/unmount
+     */
+    if (afterc < FS_CREATE) {
+       if (!strcmp(before[FS_TYPE], "AFS"))
+           critical_alert("incremental",
+                          "Could not delete AFS filesystem %s: Operation not supported",
+                          before[FS_NAME]);
+       return;
+    }
+
+    if (!strcmp(after[FS_TYPE], "AFS")) {
+       if (strcmp(before[FS_TYPE], "AFS")) {
+           critical_alert("incremental",
+                          "Cannot convert %s to an AFS filesystem: Operation not supported",
+                          after[FS_NAME]);
+       } else {
+           critical_alert("incremental",
+                          "Cannot change attributes of AFS filesystem %s: Operation not supported",
+                          after[FS_NAME]);
+       }
+       return;
+    }
+}
+
+
+do_quota(before, beforec, after, afterc)
+char **before;
+int beforec;
+char **after;
+int afterc;
+{
+    char cmd[1024];
+
+    if (afterc < Q_DIRECTORY || strcmp("ANY", after[Q_TYPE]) ||
+       strncmp("/afs/", after[Q_DIRECTORY], 5))
+       return;
+
+    sprintf(cmd, "%s/perl -I%s %s/afs_quota.pl %s %s",
+           BIN_DIR, BIN_DIR, BIN_DIR,
+           after[Q_DIRECTORY], after[Q_QUOTA]);
+    run_cmd(cmd);
+    return;
+}
+
+
+run_cmd(cmd)
+char *cmd;
+{
+    int success=0, tries=0;
+
+    check_afs();
+    
+    while (success == 0 && tries < 2) {
+       if (tries++)
+           sleep(90);
+       com_err(whoami, 0, "Executing command: %s", cmd);
+       if (system(cmd) == 0)
+           success++;
+    }
+    if (!success)
+       critical_alert("incremental", "failed command: %s", cmd);
+}
+
+
+add_user_lists(ac, av, user)
+    int ac;
+    char *av[];
+    char *user;
+{
+    if (atoi(av[5]))
+       edit_group(1, av[0], "USER", user);
+}
+
+
 get_members(ac, av, group)
     int ac;
     char *av[];
@@ -414,7 +428,6 @@ get_members(ac, av, group)
     int code=0;
 
     if (strcmp(av[0], "LIST")) {
-       sleep(1);                               /* give ptserver some time */
        edit_group(1, group, av[0], av[1]);
     } else {
        code = mr_query("get_end_members_of_list", 1, &av[1],
@@ -436,14 +449,9 @@ edit_group(op, group, type, member)
 {
     char *p = 0;
     char buf[PR_MAXNAMELEN];
-    int (*fn)();
     int code;
-    int tries = 0;
     static char local_realm[REALM_SZ+1] = "";
-    extern long pr_AddToGroup(), pr_RemoveUserFromGroup();
 
-    fn = op ? pr_AddToGroup : pr_RemoveUserFromGroup;
-    
     /* The following KERBEROS code allows for the use of entities
      * user@foreign_cell.
      */
@@ -458,13 +466,7 @@ edit_group(op, group, type, member)
 
     strcpy(buf, "system:");
     strcat(buf, group);
-    sleep(1);                                  /* give ptserver some time */
-    while (code = (*fn)(member, buf)) {
-       if (++tries > PR_TRIES)
-           break;
-       if (code == UNOQUORUM) { sleep(90); continue; }
-       sleep(PR_DELAY);
-    }
+    code=pr_try(op ? pr_AddToGroup : pr_RemoveUserFromGroup, member, buf);
     if (code) {
        if (op==0 && code == PRNOENT) return;
        if (op==1 && code == PRIDEXIST) return;
@@ -476,78 +478,73 @@ edit_group(op, group, type, member)
                           error_message(code));
        }
     }
-    if (p) *p = '@';
 }
 
 
-do_filesys(before, beforec, after, afterc)
-char **before;
-int beforec;
-char **after;
-int afterc;
+long pr_try(fn, a1, a2, a3, a4, a5, a6, a7, a8)
+    long (*fn)();
+    char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
 {
-    char cmd[1024];
+    static int initd=0;
+    register long code;
+    register int tries = 0;
+#ifdef DEBUG
+    char fname[64];
+#endif
+
+    check_afs();
     
-    if (beforec < FS_CREATE) {
-       if (afterc < FS_CREATE || atoi(after[FS_CREATE])==0 ||
-           strcmp(after[FS_TYPE], "AFS"))
+    if (!initd) {
+       code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0);
+       if (code) {
+           critical_alert("incremental", "Couldn't initialize libprot: %s",
+                          error_message(code));
            return;
-
-       /* new locker creation */
-       sprintf(cmd, "%s/perl -I%s %s/afs_create.pl %s %s %s %s %s %s",
-               BIN_DIR, BIN_DIR, BIN_DIR,
-               after[FS_NAME], after[FS_L_TYPE], after[FS_MACHINE],
-               after[FS_PACK], after[FS_OWNER], after[FS_OWNERS]);
-       do_cmd(cmd);
-       return;
-    }
-
-    /* What do we do?  When do we use FS_CREATE?
-     * 
-     * TYPE change:  AFS->ERR, ERR->AFS: rename/unmount/remount
-     * LOCKERTYPE change: rename/remount
-     * PACK change: remount
-     * LABEL change: rename/remount
-     * Deletion: rename/unmount
-     */
-    if (afterc < FS_CREATE) {
-       if (!strcmp(before[FS_TYPE], "AFS"))
-           critical_alert("incremental",
-                          "Could not delete AFS filesystem %s: Operation not supported",
-                          before[FS_NAME]);
-       return;
+       }
+       initd = 1;
+    } else {
+       sleep(1);                               /* give ptserver room */
     }
 
-    if (!strcmp(after[FS_TYPE], "AFS")) {
-       if (strcmp(before[FS_TYPE], "AFS")) {
-           critical_alert("incremental",
-                          "Cannot convert %s to an AFS filesystem: Operation not supported",
-                          after[FS_NAME]);
-       } else {
-           critical_alert("incremental",
-                          "Cannot change attributes of AFS filesystem %s: Operation not supported",
-                          after[FS_NAME]);
+    while (code = (*fn)(a1, a2, a3, a4, a5, a6, a7, a8)) {
+#ifdef DEBUG
+       long t;
+       t = time(0);
+       if (fn == pr_AddToGroup) strcpy(fname, "pr_AddToGroup");
+       else if (fn == pr_RemoveUserFromGroup)
+           strcpy(fname, "pr_RemoveUserFromGroup");
+       else if (fn == pr_CreateUser) strcpy(fname, "pr_CreateUser");
+       else if (fn == pr_CreateGroup) strcpy(fname, "pr_CreateGroup");
+       else if (fn == pr_DeleteByID) strcpy(fname, "pr_DeleteByID");
+       else if (fn == pr_ChangeEntry) strcpy(fname, "pr_ChangeEntry");
+       else if (fn == pr_SetFieldsEntry) strcpy(fname, "pr_SetFieldsEntry");
+       else if (fn == pr_AddToGroup) strcpy(fname, "pr_AddToGroup");
+       else {
+           sprintf(fname, "pr_??? (0x%08x)", (long)fn);
        }
-       return;
+
+       com_err(whoami, code, "%s failed (try %d @%u)", fname, tries+1, t);
+#endif
+       if (++tries > 2)
+           return code;
+       if (code == UNOQUORUM) { sleep(90); continue; }
+       else { sleep(15); continue; }
     }
+    return code;
 }
 
 
-do_quota(before, beforec, after, afterc)
-char **before;
-int beforec;
-char **after;
-int afterc;
+check_afs()
 {
-    char cmd[1024];
-
-    if (afterc < Q_DIRECTORY || strcmp("ANY", after[Q_TYPE]) ||
-       strncmp("/afs/", after[Q_DIRECTORY], 5))
-       return;
-
-    sprintf(cmd, "%s/perl -I%s %s/afs_quota.pl %s %s",
-           BIN_DIR, BIN_DIR, BIN_DIR,
-           after[Q_DIRECTORY], after[Q_QUOTA]);
-    do_cmd(cmd);
-    return;
+    int i;
+    
+    for (i=0; file_exists(STOP_FILE); i++) {
+       if (i > 30) {
+           critical_alert("incremental",
+                          "AFS incremental failed (%s exists): %s",
+                          STOP_FILE, tbl_buf);
+           exit(1);
+       }
+       sleep(60);
+    }
 }
This page took 0.657347 seconds and 5 git commands to generate.