--- script.c.orig	Sun May 24 15:29:15 1998
+++ script.c	Sun May 24 17:32:51 1998
@@ -57,6 +57,7 @@
 #ifdef __linux__
 #include <unistd.h>
 #include <string.h>
+#include <ptmx_fake.h>
 #endif
 
 void done(void);
@@ -121,10 +122,12 @@
 		shell = _PATH_BSHELL;
 
 	getmaster();
+	getslave();
 	printf("Script started, file is %s\n", fname);
 	fixtty();
 
 	(void) signal(SIGCHLD, finish);
+	fflush(NULL);
 	child = fork();
 	if (child < 0) {
 		perror("fork");
@@ -151,6 +154,7 @@
 	char ibuf[BUFSIZ];
 
 	(void) fclose(fscript);
+	(void) close(slave);
 	while ((cc = read(0, ibuf, BUFSIZ)) > 0)
 		(void) write(master, ibuf, cc);
 	done();
@@ -181,6 +185,7 @@
 	char obuf[BUFSIZ], *ctime();
 
 	(void) close(0);
+	(void) close(slave);
 	tvec = time((time_t *)NULL);
 	fprintf(fscript, "Script started on %s", ctime(&tvec));
 	for (;;) {
@@ -205,7 +210,6 @@
 		(void) close(t);
 	}
 	***/
-	getslave();
 	(void) close(master);
 	(void) fclose(fscript);
 	(void) dup2(slave, 0);
@@ -261,36 +265,17 @@
 void
 getmaster()
 {
-	char *pty, *bank, *cp;
-	struct stat stb;
-
-	pty = &line[strlen("/dev/ptyp")];
-	for (bank = "pqrs"; *bank; bank++) {
-		line[strlen("/dev/pty")] = *bank;
-		*pty = '0';
-		if (stat(line, &stb) < 0)
-			break;
-		for (cp = "0123456789abcdef"; *cp; cp++) {
-			*pty = *cp;
-			master = open(line, O_RDWR);
-			if (master >= 0) {
-				char *tp = &line[strlen("/dev/")];
-				int ok;
-
-				/* verify slave side is usable */
-				*tp = 't';
-				ok = access(line, R_OK|W_OK) == 0;
-				*tp = 'p';
-				if (ok) {
-					(void) tcgetattr(0, &tt);
-				    	(void) ioctl(0, TIOCGWINSZ, 
-						(char *)&win);
-					return;
-				}
-				(void) close(master);
-			}
-		}
+	master=open(PTMX, O_RDWR);
+	if (master < 0) {
+		perror(PTMX);
+		fail();
+	}
+	if (!grantpt(master) && !unlockpt(master)) {
+		(void) tcgetattr(0, &tt);
+		(void) ioctl(0, TIOCGWINSZ, (char *)&win);
+		return;
 	}
+	(void) close(master);
 	fprintf(stderr, "Out of pty's\n");
 	fail();
 }
@@ -298,8 +283,11 @@
 void
 getslave()
 {
-
-	line[strlen("/dev/")] = 't';
+	char *line;
+	if (!(line=ptsname(master))) {
+		fprintf(stderr, "Can't get line of pty slave\n");
+		fail();
+	}
 	slave = open(line, O_RDWR);
 	if (slave < 0) {
 		perror(line);

