]> andersk Git - moira.git/commitdiff
Corrected faulty logic that could result in multiple attempts to
authorprobe <probe>
Mon, 9 Nov 1992 15:41:09 +0000 (15:41 +0000)
committerprobe <probe>
Mon, 9 Nov 1992 15:41:09 +0000 (15:41 +0000)
connect to the Moira server.  (Added a layer of abstraction w/ ref counts)

incremental/afs.c

index 60d9c2f98ca4f3f28a4aedb465124200fc3ebfc4..86327b345f4fefdf02aab8172ca64f0284706db8 100644 (file)
@@ -58,7 +58,6 @@ extern long pr_AddToGroup();
 extern long pr_RemoveUserFromGroup();
 
 static char tbl_buf[1024];
-static char hostname[64];
 
 main(argc, argv)
 char **argv;
@@ -173,9 +172,7 @@ int afterc;
 
        if (bstate != 0) {
            /* Reactivating a user; get his group list */
-           gethostname(hostname, sizeof(hostname));
-           code = mr_connect(hostname);
-           if (!code) code = mr_auth("afs.incr");
+           code = moira_connect();
            if (code) {
                critical_alert("incremental",
                               "Error contacting Moira server to retrieve grouplist of user %s: %s",
@@ -190,7 +187,7 @@ int afterc;
                critical_alert("incremental",
                               "Couldn't retrieve membership of user %s: %s",
                               after[U_NAME], error_message(code));
-           mr_disconnect();
+           moira_disconnect();
        }
        return;
     }
@@ -284,9 +281,7 @@ int afterc;
        /* We need to make sure the group is properly populated */
        if (beforec < L_ACTIVE) return;
 
-       gethostname(hostname, sizeof(hostname));
-       code = mr_connect(hostname);
-       if (!code) code = mr_auth("afs.incr");
+       code = moira_connect();
        if (code) {
            critical_alert("incremental",
                           "Error contacting Moira server to resolve %s: %s",
@@ -297,7 +292,7 @@ int afterc;
        av[1] = after[L_NAME];
        get_members(2, av, after[L_NAME]);
 
-       mr_disconnect();
+       moira_disconnect();
        return;
     }
 }
@@ -509,9 +504,7 @@ edit_group(op, group, type, member)
                return;
 
            /* Check whether the member being added is an active user */
-           gethostname(hostname, sizeof(hostname));
-           code = mr_connect(hostname);
-           if (!code) code = mr_auth("afs.incr");
+           code = moira_connect();
            if (!code) code = mr_query("get_user_by_login", 1, &member,
                                       check_user, &ustate);
            if (code) {
@@ -519,7 +512,7 @@ edit_group(op, group, type, member)
                               "Error contacting Moira server to lookup user %s: %s",
                               member, error_message(code));
            }
-           mr_disconnect();
+           moira_disconnect();
            if (!code && ustate!=1 && ustate!=2) return; /* inactive user */
        }
 
@@ -607,3 +600,28 @@ check_afs()
        sleep(60);
     }
 }
+
+
+static int mr_connections=0;
+
+moira_connect()
+{
+    static char hostname[64];
+    long code;
+
+    if (!mr_connections++) {
+       gethostname(hostname, sizeof(hostname));
+       code = mr_connect(hostname);
+       if (!code) code = mr_auth("afs.incr");
+       return code;    
+    }
+    return 0;
+}
+
+moira_disconnect()
+{
+    if (!--mr_connections) {
+       mr_disconnect();
+    }
+    return 0;
+}
This page took 0.045233 seconds and 5 git commands to generate.