summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoritojun <>2000-02-18 04:12:20 +0000
committeritojun <>2000-02-18 04:12:20 +0000
commitbe3dce7b46358d47347a0fa9232513d2e3a2ff4a (patch)
tree2c27f011f29fe250ead76e1602bbe3abe673595b
parentc18b79066bbe0d2f6f70a042e575d8ef87e5aab5 (diff)
downloadopenbsd-be3dce7b46358d47347a0fa9232513d2e3a2ff4a.tar.gz
openbsd-be3dce7b46358d47347a0fa9232513d2e3a2ff4a.tar.bz2
openbsd-be3dce7b46358d47347a0fa9232513d2e3a2ff4a.zip
do not perform sleep() every time we get ECONNREFUSED.
try all the set of addresses before go to sleep() and retry. not sure if we still need sleep() - retry logic. why is it so persistent?
-rw-r--r--src/lib/libc/net/rcmd.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lib/libc/net/rcmd.c b/src/lib/libc/net/rcmd.c
index 3cd3029a03..874c810782 100644
--- a/src/lib/libc/net/rcmd.c
+++ b/src/lib/libc/net/rcmd.c
@@ -34,7 +34,7 @@
34 */ 34 */
35 35
36#if defined(LIBC_SCCS) && !defined(lint) 36#if defined(LIBC_SCCS) && !defined(lint)
37static char *rcsid = "$OpenBSD: rcmd.c,v 1.34 2000/01/30 05:17:49 itojun Exp $"; 37static char *rcsid = "$OpenBSD: rcmd.c,v 1.35 2000/02/18 04:12:20 itojun Exp $";
38#endif /* LIBC_SCCS and not lint */ 38#endif /* LIBC_SCCS and not lint */
39 39
40#include <sys/param.h> 40#include <sys/param.h>
@@ -90,6 +90,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
90 pid_t pid; 90 pid_t pid;
91 int s, lport, timo; 91 int s, lport, timo;
92 char c, *p; 92 char c, *p;
93 int refused;
93 94
94 /* call rcmdsh() with specified remote shell if appropriate. */ 95 /* call rcmdsh() with specified remote shell if appropriate. */
95 if (!issetugid() && (p = getenv("RSH"))) { 96 if (!issetugid() && (p = getenv("RSH"))) {
@@ -130,6 +131,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
130 ; /*XXX*/ 131 ; /*XXX*/
131 132
132 r = res; 133 r = res;
134 refused = 0;
133 oldmask = sigblock(sigmask(SIGURG)); 135 oldmask = sigblock(sigmask(SIGURG));
134 for (timo = 1, lport = IPPORT_RESERVED - 1;;) { 136 for (timo = 1, lport = IPPORT_RESERVED - 1;;) {
135 s = rresvport_af(&lport, r->ai_family); 137 s = rresvport_af(&lport, r->ai_family);
@@ -157,11 +159,8 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
157 lport--; 159 lport--;
158 continue; 160 continue;
159 } 161 }
160 if (errno == ECONNREFUSED && timo <= 16) { 162 if (errno == ECONNREFUSED)
161 (void)sleep(timo); 163 refused++;
162 timo *= 2;
163 continue;
164 }
165 if (r->ai_next) { 164 if (r->ai_next) {
166 int oerrno = errno; 165 int oerrno = errno;
167 char hbuf[NI_MAXHOST]; 166 char hbuf[NI_MAXHOST];
@@ -186,6 +185,13 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
186 (void)fprintf(stderr, "Trying %s...\n", hbuf); 185 (void)fprintf(stderr, "Trying %s...\n", hbuf);
187 continue; 186 continue;
188 } 187 }
188 if (refused && timo <= 16) {
189 (void)sleep(timo);
190 timo *= 2;
191 r = res;
192 refused = 0;
193 continue;
194 }
189 (void)fprintf(stderr, "%s: %s\n", res->ai_canonname, 195 (void)fprintf(stderr, "%s: %s\n", res->ai_canonname,
190 strerror(errno)); 196 strerror(errno));
191 sigsetmask(oldmask); 197 sigsetmask(oldmask);