  
  	/* Set up some signals. */
  	signal(SIGPIPE, SIG_IGN);
-@@ -508,6 +646,34 @@ master_process(int s, char **argv, int w
+@@ -508,6 +655,34 @@ master_process(int s, char **argv, int w
  		alarm(alarm_time);
  	}
  

-		/* pty activity? */
-		if (FD_ISSET(the_pty.fd, &readfds))
-			pty_activity(s);
+				len = read(peer_pty, peer_buf, sizeof(peer_buf));
+				if (the_pty.fd >= 0 && len > 0)
+				{
+					if (is_edge_mode)
+					{
+						epoll_ctl(efd, EPOLL_CTL_MOD, peer_pty, &data_peer);
+						is_edge_mode = 0;
+					}
+					eintr_write(the_pty.fd, peer_buf, len);
+				}
+			}
+			else
+			{
+				/* The clients */
+				for (p = clients; p; p = next)
+				{
+					next = p->next;
+					if (events[i].data.fd == p->fd)
+					{
+						client_activity(p);
+						break;
+					}
+				}
+			}
+		}
+
+		/*
+		** When waitattach is set, wait until the client attaches
+		** before trying to read from the pty.

+	}
+
+	the_pty.fd = fd;
+	if (!tcgetattr(the_pty.fd, &the_pty.term))
+	{
+		/* Setup same as stty sane */
+		the_pty.term.c_iflag = ICRNL | BRKINT | IMAXBEL;
+		the_pty.term.c_oflag = ONLCR | OPOST;
+		the_pty.term.c_lflag = ECHO | ECHOE | ECHOK | ICANON |
+			ISIG | ECHOKE | ECHOCTL | IEXTEN;
+		tcsetattr(the_pty.fd, TCSADRAIN, &the_pty.term);
+		if (do_peer_pty)
+			tcsetattr(peer_pty, TCSADRAIN, &the_pty.term);
+	}
+
+	return 1;
+}
