Index: authfd.c
===================================================================
RCS file: /usr/local/src/security/openssh/cvs/openssh_cvs/authfd.c,v
retrieving revision 1.59
diff -u -p -r1.59 authfd.c
--- authfd.c	13 Aug 2004 11:19:38 -0000	1.59
+++ authfd.c	21 Dec 2004 10:41:44 -0000
@@ -84,8 +84,9 @@ int
 ssh_get_authentication_socket(void)
 {
 	const char *authsocket;
-	int sock;
+	int i, sock;
 	struct sockaddr_un sunaddr;
+	struct timespec ts;
 
 	authsocket = getenv(SSH_AUTHSOCKET_ENV_NAME);
 	if (!authsocket)
@@ -103,12 +104,22 @@ ssh_get_authentication_socket(void)
 		close(sock);
 		return -1;
 	}
-	if (connect(sock, (struct sockaddr *) &sunaddr, sizeof sunaddr) < 0) {
-		close(sock);
-		return -1;
+	for (i = 0; i < 6; i++) {
+		if (connect(sock, (struct sockaddr *) &sunaddr,
+		    sizeof sunaddr) != -1) {
+			agent_present = 1;
+			return sock;
+		}
+		debug3("connect to %s: %s", authsocket, strerror(errno));
+		if (errno != ECONNREFUSED)
+			break;
+		/* wait 200 - 400ms before retry */
+		ts.tv_sec = 0;
+		ts.tv_nsec = ((arc4random() % 200) + 200) * 1000000;
+		nanosleep(&ts, NULL);
 	}
-	agent_present = 1;
-	return sock;
+	close(sock);
+	return -1;
 }
 
 static int
