bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch for NIS+


From: Alexander Belopolsky
Subject: Patch for NIS+
Date: Tue, 11 Dec 2001 21:34:01 -0500

I propose the following patch which fixes the problem of finding NIS+
server
on a slow network with fast clients.  Proposed patch makes the client
retry
with increasing timeouts when it does not get response.

Fixes the following bug:
libc/2520: problem finding NIS+ server
http://bugs.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=default&pr=2520

--
Alexander Belopolsky | Renaissance Technologies Corp.
600 Route 25A | East Setauket | NY 11733-1249
PH: 631-444-7125 | FAX: 631-444-7009


? nis/nis_findserv.c.diff
Index: nis/nis_findserv.c
===================================================================
RCS file: /cvs/glibc/libc/nis/nis_findserv.c,v
retrieving revision 1.11
diff -a -u -r1.11 nis_findserv.c
--- nis_findserv.c      2001/08/29 23:30:01     1.11
+++ nis_findserv.c      2001/12/12 02:19:17
@@ -110,27 +110,27 @@
   u_int server_ep;
 };
 
+static long
+__nis_findfastest_with_timeout (dir_binding *bind,  struct timeval const* 
timeout);
+
 long
 __nis_findfastest (dir_binding *bind)
 {
-#if 0
-  unsigned long i, j;
-
-  for (i = 0; i < bind->server_len; i++)
-    for (j = 0; j < bind->server_val[i].ep.ep_len; ++j)
-      if (strcmp (bind->server_val[i].ep.ep_val[j].family, "inet") == 0)
-       if ((bind->server_val[i].ep.ep_val[j].proto == NULL) ||
-           (bind->server_val[i].ep.ep_val[j].proto[0] ==  '-') ||
-           (bind->server_val[i].ep.ep_val[j].proto[0] == '\0'))
-         {
-           bind->server_used = i;
-           bind->current_ep = j;
-           return 1;
-         }
+  struct timeval timeout = {__NIS_PING_TIMEOUT_START, 0};
+  long found = -1;
+  long retry = __NIS_PING_RETRY + 1;
+  while (retry--) {
+    found = __nis_findfastest_with_timeout(bind, &timeout);
+    if (found != -1)
+      break;
+    timeout.tv_sec+=__NIS_PING_TIMEOUT_INCREMENT;
+  }
+  return found;
+}
 
-  return 0;
-#else
-  const struct timeval TIMEOUT50 = {5, 0};
+long
+__nis_findfastest_with_timeout (dir_binding *bind,  struct timeval const* 
timeout)
+{
   const struct timeval TIMEOUT00 = {0, 0};
   struct findserv_req *pings;
   struct sockaddr_in sin, saved_sin;
@@ -201,7 +201,7 @@
 
   /* Create RPC handle */
   sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
-  clnt = clntudp_create (&saved_sin, NIS_PROG, NIS_VERSION, TIMEOUT50, &sock);
+  clnt = clntudp_create (&saved_sin, NIS_PROG, NIS_VERSION, *timeout, &sock);
   if (clnt == NULL)
     {
       close (sock);
@@ -211,9 +211,12 @@
   auth_destroy (clnt->cl_auth);
   clnt->cl_auth = authunix_create_default ();
   cu = (struct cu_data *) clnt->cl_private;
-  clnt_control (clnt, CLSET_TIMEOUT, (char *) &TIMEOUT00);
+  /*
+    This would overrride timeout argument in all clnt_calls that
+    follow. We don't want it.
+    clnt_control (clnt, CLSET_TIMEOUT, (char *) &TIMEOUT00);
+  */
   ioctl (sock, FIONBIO, &dontblock);
-
   /* Send to all servers the NULLPROC */
   for (i = 0; i < pings_count; ++i)
     {
@@ -227,24 +230,25 @@
                 (xdrproc_t) xdr_void, (caddr_t) 0, TIMEOUT00);
     }
   
-  /* Receive reply from NULLPROC asynchronously */
-  while (RPC_SUCCESS == clnt_call (clnt, NULLPROC,
-                                  (xdrproc_t) NULL, (caddr_t) 0,
-                                  (xdrproc_t) xdr_void, (caddr_t) 0,
-                                  TIMEOUT00))
-    {
+  while (found == -1) {
+    /* Receive reply from NULLPROC asynchronously. Note null inproc. */
+    int rc = clnt_call (clnt, NULLPROC,
+                       (xdrproc_t) NULL, (caddr_t) 0,
+                       (xdrproc_t) xdr_void, (caddr_t) 0,
+                       *timeout);
+    if (RPC_SUCCESS == rc) {
       fastest = *((u_int32_t *) (cu->cu_inbuf)) - xid_seed;
       if (fastest < pings_count) {
-       break;
+       bind->server_used = pings[fastest].server_nr;
+       bind->current_ep = pings[fastest].server_ep;
+       found = 1;
       }
+    } else {
+      /*      clnt_perror(clnt, "__nis_findfastest"); */
+      break;
     }
+  }
   
-  if (fastest < pings_count)
-    {
-      bind->server_used = pings[fastest].server_nr;
-      bind->current_ep = pings[fastest].server_ep;
-      found = 1;
-    }
   
   auth_destroy (clnt->cl_auth);
   clnt_destroy (clnt);
@@ -253,5 +257,4 @@
   free (pings);
 
   return found;
-#endif
 }
Index: nis/nis_intern.h
===================================================================
RCS file: /cvs/glibc/libc/nis/nis_intern.h,v
retrieving revision 1.19
diff -a -u -r1.19 nis_intern.h
--- nis_intern.h        2001/07/06 04:55:36     1.19
+++ nis_intern.h        2001/12/12 02:19:17
@@ -22,6 +22,21 @@
 #define __NIS_INTERN_H
 #include <features.h>
 
+/* configurable parameters for pinging NIS servers        */
+/*        number of retries                               */
+#ifndef __NIS_PING_RETRY
+#        define __NIS_PING_RETRY 10
+#endif
+/*        initial timeout in seconds                      */
+#ifndef __NIS_PING_TIMEOUT_START
+#        define __NIS_PING_TIMEOUT_START 0
+#endif
+/*        timeout increment for retries in seconds        */
+#ifndef __NIS_PING_TIMEOUT_INCREMENT
+#        define __NIS_PING_TIMEOUT_INCREMENT 1
+#endif
+/* end of configurable parameters for pinging NIS servers */
+
 __BEGIN_DECLS
 
 struct nis_cb

reply via email to

[Prev in Thread] Current Thread [Next in Thread]