7fe48cb
--- a/telnetd/telnetd.c
7fe48cb
+++ b/telnetd/telnetd.c
7fe48cb
@@ -772,7 +772,6 @@ void telnet(int f, int p)
7fe48cb
     int on = 1;
7fe48cb
     char *HE;
7fe48cb
     const char *IM;
7fe48cb
-    int pty_read_ok = 0; /* track whether the pty read has worked yet */
7fe48cb
 
7fe48cb
     /*
7fe48cb
      * Initialize the slc mapping table.
7fe48cb
@@ -1086,19 +1085,24 @@ void telnet(int f, int p)
7fe48cb
 	 * Something to read from the pty...
7fe48cb
 	 */
7fe48cb
 	if (FD_ISSET(p, &ibits)) {
7fe48cb
+	    int eio = 0;
7fe48cb
+read_pty:
7fe48cb
 	    pcc = read(p, ptyibuf, BUFSIZ);
7fe48cb
-	    /*
7fe48cb
-	     * On some systems, if we try to read something
7fe48cb
-	     * off the master side before the slave side is
7fe48cb
-	     * opened, we get EIO.
7fe48cb
-	     */
7fe48cb
-	    if (pcc < 0 && (errno == EWOULDBLOCK || (errno == EIO && pty_read_ok == 0))) {
7fe48cb
+	    if (pcc < 0 && errno == EWOULDBLOCK) {
7fe48cb
 		pcc = 0;
7fe48cb
 	    } 
7fe48cb
+	    /*
7fe48cb
+	     * If we try to read something off the master side while the slave
7fe48cb
+	     * side is temporarily closed by login process, we get EIO.
7fe48cb
+	     */
7fe48cb
+	    else if (pcc < 0 && errno == EIO && eio < 1000) {
7fe48cb
+		    eio++;
7fe48cb
+		    poll(NULL, 0, 10);
7fe48cb
+		    goto read_pty;
7fe48cb
+	    }
7fe48cb
 	    else {
7fe48cb
 		if (pcc <= 0)
7fe48cb
 		    break;
7fe48cb
-		pty_read_ok = 1;	/* mark connection up for read */
7fe48cb
 #ifdef	LINEMODE
7fe48cb
 				/*
7fe48cb
 				 * If ioctl from pty, pass it through net