use pty klibrary
authorMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Thu, 4 Jul 1991 07:33:00 +0000 (23:33 -0800)
committerMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Thu, 4 Jul 1991 07:33:00 +0000 (23:33 -0800)
SCCS-vsn: usr.bin/script/script.c 5.14
SCCS-vsn: usr.bin/script/Makefile 5.4

usr/src/usr.bin/script/Makefile
usr/src/usr.bin/script/script.c

index 4073a35..c1e2649 100644 (file)
@@ -1,5 +1,7 @@
-#      @(#)Makefile    5.3 (Berkeley) %G%
+#      @(#)Makefile    5.4 (Berkeley) %G%
 
 PROG=  script
 
 PROG=  script
+LDADD= -lutil
+DPADD= ${LIBUTIL}
 
 .include <bsd.prog.mk>
 
 .include <bsd.prog.mk>
index 971aaec..5bfd0ce 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)script.c   5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)script.c   5.14 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -79,9 +79,15 @@ main(argc, argv)
        if (shell == NULL)
                shell = _PATH_BSHELL;
 
        if (shell == NULL)
                shell = _PATH_BSHELL;
 
-       getmaster();
+       (void) tcgetattr(0, &tt);
+       (void) ioctl(0, TIOCGWINSZ, (char *)&win);
+       if (openpty(&master, &slave, NULL, &tt, &win) == -1) {
+               perror("openpty");
+               exit(1);
+       }
+
        printf("Script started, file is %s\n", fname);
        printf("Script started, file is %s\n", fname);
-       fixtty();
+       fixtty();       /* go raw */
 
        (void) signal(SIGCHLD, finish);
        child = fork();
 
        (void) signal(SIGCHLD, finish);
        child = fork();
@@ -152,22 +158,10 @@ dooutput()
 
 doshell()
 {
 
 doshell()
 {
-       int t;
 
 
-       /***
-       t = open(_PATH_TTY, O_RDWR);
-       if (t >= 0) {
-               (void) ioctl(t, TIOCNOTTY, (char *)0);
-               (void) close(t);
-       }
-       ***/
-       getslave();
-       (void) close(master);
+       close(master);
        (void) fclose(fscript);
        (void) fclose(fscript);
-       (void) dup2(slave, 0);
-       (void) dup2(slave, 1);
-       (void) dup2(slave, 2);
-       (void) close(slave);
+       login_tty(slave);
        execl(shell, "sh", "-i", 0);
        perror(shell);
        fail();
        execl(shell, "sh", "-i", 0);
        perror(shell);
        fail();
@@ -206,54 +200,3 @@ done()
        }
        exit(0);
 }
        }
        exit(0);
 }
-
-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);
-                       }
-               }
-       }
-       fprintf(stderr, "Out of pty's\n");
-       fail();
-}
-
-getslave()
-{
-
-       line[strlen("/dev/")] = 't';
-       slave = open(line, O_RDWR);
-       if (slave < 0) {
-               perror(line);
-               fail();
-       }
-       (void) tcsetattr(slave, TCSAFLUSH, &tt);
-       (void) ioctl(slave, TIOCSWINSZ, (char *)&win);
-       (void) setsid();
-       (void) ioctl(slave, TIOCSCTTY, 0);
-}