OpenSSH 2.5.0p1

Todd C. Miller Todd.Miller at courtesan.com
Sun Feb 18 02:43:15 EST 2001


OpenSSH 2.5.0p1 should be more robust in the face of EGD problems
and deal with SIGPIPE gracefully.  Below is a more self-contained
patch similar to the one I sent in before (and also similar to one
Lutz Jaenicke posted in the past).

This doesn't include the change to catch ECONNREFUSED and retry
since that needs usleep.  See:
    http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=98207528123346&w=2
for those bits if you are interested.  I do think that is a good
idea as well but since I haven't whipped up a generic usleep() it's
probably too late for that to be in 2.5.0p1.

 - todd

--- entropy.c.DIST	Mon Feb  5 05:42:17 2001
+++ entropy.c	Sat Feb 17 08:47:18 2001
@@ -71,7 +71,8 @@
 	int fd;
 	char msg[2];
 	struct sockaddr_un addr;
-	int addr_len;
+	int addr_len, rval, errors;
+	struct sigaction nsa, osa;
 
 	/* Sanity checks */
 	if (sizeof(EGD_SOCKET) > sizeof(addr.sun_path))
@@ -84,17 +85,22 @@
 	strlcpy(addr.sun_path, EGD_SOCKET, sizeof(addr.sun_path));
 	addr_len = offsetof(struct sockaddr_un, sun_path) + sizeof(EGD_SOCKET);
 
+	memset(&nsa, 0, sizeof(nsa));
+	nsa.sa_handler = SIG_IGN;
+	(void) sigaction(SIGPIPE, &nsa, &osa);
+
+	errors = rval = 0;
+reopen:
 	fd = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (fd == -1) {
 		error("Couldn't create AF_UNIX socket: %s", strerror(errno));
-		return(0);
+		goto done;
 	}
 
 	if (connect(fd, (struct sockaddr*)&addr, addr_len) == -1) {
 		error("Couldn't connect to EGD socket \"%s\": %s",
 			addr.sun_path, strerror(errno));
-		close(fd);
-		return(0);
+		goto done;
 	}
 
 	/* Send blocking read request to EGD */
@@ -102,22 +108,33 @@
 	msg[1] = len;
 
 	if (atomicio(write, fd, msg, sizeof(msg)) != sizeof(msg)) {
+		if (errno == EPIPE && errors < 10) {
+			close(fd);
+			errors++;
+			goto reopen;
+		}
 		error("Couldn't write to EGD socket \"%s\": %s",
 			EGD_SOCKET, strerror(errno));
-		close(fd);
-		return(0);
+		goto done;
 	}
 
 	if (atomicio(read, fd, buf, len) != len) {
+		if (errno == EPIPE && errors < 10) {
+			close(fd);
+			errors++;
+			goto reopen;
+		}
 		error("Couldn't read from EGD socket \"%s\": %s",
 			EGD_SOCKET, strerror(errno));
-		close(fd);
-		return(0);
+		goto done;
 	}
 
-	close(fd);
-
-	return(1);
+	rval = 1;
+done:
+	(void) sigaction(SIGPIPE, &osa, NULL);
+	if (fd != -1)
+		close(fd);
+	return(rval);
 }
 #else /* !EGD_SOCKET */
 #ifdef RANDOM_POOL





More information about the openssh-unix-dev mailing list