summaryrefslogtreecommitdiff
path: root/lib/libc/net/rcmd.c
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2000-02-18 04:12:21 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2000-02-18 04:12:21 +0000
commitefd9b5b2701001e506716293d6c7e6bb16e9999c (patch)
tree204d31f2765ad500121b36db08743db50b615bf6 /lib/libc/net/rcmd.c
parent856a0b03de5207c5d6d3e1ef0f5f4f8b7c59b0f7 (diff)
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?
Diffstat (limited to 'lib/libc/net/rcmd.c')
-rw-r--r--lib/libc/net/rcmd.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c
index 3cd3029a03d..874c8107822 100644
--- a/lib/libc/net/rcmd.c
+++ b/lib/libc/net/rcmd.c
@@ -34,7 +34,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: rcmd.c,v 1.34 2000/01/30 05:17:49 itojun Exp $";
+static char *rcsid = "$OpenBSD: rcmd.c,v 1.35 2000/02/18 04:12:20 itojun Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -90,6 +90,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
pid_t pid;
int s, lport, timo;
char c, *p;
+ int refused;
/* call rcmdsh() with specified remote shell if appropriate. */
if (!issetugid() && (p = getenv("RSH"))) {
@@ -130,6 +131,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
; /*XXX*/
r = res;
+ refused = 0;
oldmask = sigblock(sigmask(SIGURG));
for (timo = 1, lport = IPPORT_RESERVED - 1;;) {
s = rresvport_af(&lport, r->ai_family);
@@ -157,11 +159,8 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
lport--;
continue;
}
- if (errno == ECONNREFUSED && timo <= 16) {
- (void)sleep(timo);
- timo *= 2;
- continue;
- }
+ if (errno == ECONNREFUSED)
+ refused++;
if (r->ai_next) {
int oerrno = errno;
char hbuf[NI_MAXHOST];
@@ -186,6 +185,13 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
(void)fprintf(stderr, "Trying %s...\n", hbuf);
continue;
}
+ if (refused && timo <= 16) {
+ (void)sleep(timo);
+ timo *= 2;
+ r = res;
+ refused = 0;
+ continue;
+ }
(void)fprintf(stderr, "%s: %s\n", res->ai_canonname,
strerror(errno));
sigsetmask(oldmask);