aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--nis/nis_findserv.c85
-rw-r--r--nis/nis_intern.h18
3 files changed, 69 insertions, 45 deletions
diff --git a/ChangeLog b/ChangeLog
index c5d59c3..ebe1553 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,17 @@
+2001-12-12 Ulrich Drepper <drepper@redhat.com>
+
+ * nis/nis_findserv.c (__nis_findfastest_with_timeout): Mostly the code
+ from __nis_findfastest. Take timeout value from parameter.
+ (__nis_findfastest): Call __nis_findfastest_with_timeout repeatedly.
+ * nis/nis_intern.h: Define parameters controlling __nis_findfastest.
+ Patch by Alexander Belopolsky <alexb@rentec.com>.
+
2001-12-12 Andreas Jaeger <aj@suse.de>
* configure.in: Use -nostartfiles -nostdlib for linker tests, fix
combreloc test so that it works in this case.
- * sysdeps/arm/dl-machine.h (elf_machine_rela): Fix typo in last
- patch.
+ * sysdeps/arm/dl-machine.h (elf_machine_rela): Fix typo in last patch.
2001-12-12 NIIBE Yutaka <gniibe@m17n.org>
diff --git a/nis/nis_findserv.c b/nis/nis_findserv.c
index a82c115..472a2bf 100644
--- a/nis/nis_findserv.c
+++ b/nis/nis_findserv.c
@@ -110,28 +110,12 @@ struct findserv_req
u_int server_ep;
};
-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;
- }
-
- return 0;
-#else
- const struct timeval TIMEOUT50 = {5, 0};
- const struct timeval TIMEOUT00 = {0, 0};
+static long int
+__nis_findfastest_with_timeout (dir_binding *bind,
+ const struct timeval *timeout)
+{
+ static const struct timeval TIMEOUT00 = { 0, 0 };
struct findserv_req *pings;
struct sockaddr_in sin, saved_sin;
int found = -1;
@@ -201,7 +185,7 @@ __nis_findfastest (dir_binding *bind)
/* 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 +195,7 @@ __nis_findfastest (dir_binding *bind)
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);
ioctl (sock, FIONBIO, &dontblock);
-
/* Send to all servers the NULLPROC */
for (i = 0; i < pings_count; ++i)
{
@@ -222,30 +204,31 @@ __nis_findfastest (dir_binding *bind)
memcpy ((char *) &cu->cu_raddr, (char *) &pings[i].sin,
sizeof (struct sockaddr_in));
/* Transmit to NULLPROC, return immediately. */
- clnt_call (clnt, NULLPROC,
+ clnt_call (clnt, NULLPROC,
(xdrproc_t) xdr_void, (caddr_t) 0,
(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);
close (sock);
@@ -253,5 +236,23 @@ __nis_findfastest (dir_binding *bind)
free (pings);
return found;
-#endif
+}
+
+
+long int
+__nis_findfastest (dir_binding *bind)
+{
+ struct timeval timeout = { __NIS_PING_TIMEOUT_START, 0 };
+ long int found = -1;
+ long int 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;
}
diff --git a/nis/nis_intern.h b/nis/nis_intern.h
index 53413ea..29a80a9 100644
--- a/nis/nis_intern.h
+++ b/nis/nis_intern.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -22,6 +22,22 @@
#define __NIS_INTERN_H
#include <features.h>
+/* Configurable parameters for pinging NIS servers: */
+
+/* Number of retries. */
+#ifndef __NIS_PING_RETRY
+# define __NIS_PING_RETRY 2
+#endif
+/* Initial timeout in seconds. */
+#ifndef __NIS_PING_TIMEOUT_START
+# define __NIS_PING_TIMEOUT_START 3
+#endif
+/* Timeout increment for retries in seconds. */
+#ifndef __NIS_PING_TIMEOUT_INCREMENT
+# define __NIS_PING_TIMEOUT_INCREMENT 3
+#endif
+
+
__BEGIN_DECLS
struct nis_cb