0.7.13.3
authorDaniel Barlow <dan@telent.net>
Wed, 26 Feb 2003 02:28:35 +0000 (02:28 +0000)
committerDaniel Barlow <dan@telent.net>
Wed, 26 Feb 2003 02:28:35 +0000 (02:28 +0000)
RUN-PROGRAM fixes: make the :pty option actually work (even on
other-than-BSD systems) and run-program.lisp rather shorter in
the process.

src/code/run-program.lisp
src/runtime/run-program.c
version.lisp-expr

index aee63b8..9153a8f 100644 (file)
 ;;; list of handlers installed by RUN-PROGRAM
 (defvar *handlers-installed* nil)
 
-#+FreeBSD
-(define-alien-type nil
-  (struct sgttyb
-         (sg-ispeed sb-alien:char)     ; input speed
-         (sg-ospeed sb-alien:char)     ; output speed
-         (sg-erase sb-alien:char)      ; erase character
-         (sg-kill sb-alien:char)       ; kill character
-         (sg-flags sb-alien:short)))   ; mode flags
-#+OpenBSD
-(define-alien-type nil
-  (struct sgttyb
-         (sg-four sb-alien:int)
-         (sg-chars (array sb-alien:char 4))
-         (sg-flags sb-alien:int)))
-
 ;;; Find an unused pty. Return three values: the file descriptor for
 ;;; the master side of the pty, the file descriptor for the slave side
 ;;; of the pty, and the name of the tty device for the slave side.
                                              sb-unix:o_rdwr
                                              #o666)))
            (when slave-fd
-             ;; comment from classic CMU CL:
-             ;;   Maybe put a vhangup here?
-             ;;
-             ;; FIXME: It seems as though this logic should be in
-             ;; OPEN-PTY, not FIND-A-PTY (both from the comments
-             ;; documenting DEFUN FIND-A-PTY, and from the
-             ;; connotations of the function names).
-             ;;
-             ;; FIXME: It would be nice to have a note, and/or a pointer
-             ;; to some reference material somewhere, explaining
-             ;; why we need this on *BSD and not on Linux.
-              #+bsd
-             (sb-alien:with-alien ((stuff (sb-alien:struct sgttyb)))
-               (let ((sap (sb-alien:alien-sap stuff)))
-                 (sb-unix:unix-ioctl slave-fd sb-unix:TIOCGETP sap)
-                 (setf (sb-alien:slot stuff 'sg-flags)
-                       ;; This is EVENP|ODDP, the same numeric code
-                       ;; both on FreeBSD and on OpenBSD. -- WHN 20000929
-                       #o300) ; EVENP|ODDP
-                 (sb-unix:unix-ioctl slave-fd sb-unix:TIOCSETP sap)
-                 (sb-unix:unix-ioctl master-fd sb-unix:TIOCGETP sap)
-                 (setf (sb-alien:slot stuff 'sg-flags)
-                       (logand (sb-alien:slot stuff 'sg-flags)
-                               ;; This is ~ECHO, the same numeric
-                               ;; code both on FreeBSD and on OpenBSD.
-                               ;; -- WHN 20000929
-                               (lognot 8))) ; ~ECHO
-                 (sb-unix:unix-ioctl master-fd sb-unix:TIOCSETP sap)))
              (return-from find-a-pty
                (values master-fd
                        slave-fd
index 2e92d83..241db7f 100644 (file)
 #include <unistd.h>
 #endif
 
+#include <sys/ioctl.h>
+#include <termios.h>
+
+
+/* borrowed from detachtty's detachtty.c, in turn borrowed from APUE
+ * example code found at
+ * http://www.yendor.com/programming/unix/apue/pty/main.c
+
+-brkint 
+
+ */
+
+int set_noecho(int fd) 
+{
+    struct termios  stermios;
+    
+    if (tcgetattr(fd, &stermios) < 0) return 0;
+    
+    stermios.c_lflag &= ~(  ECHO | /* ECHOE |  ECHOK | */  ECHONL);
+    stermios.c_oflag |= (ONLCR); 
+    stermios.c_iflag &= ~(BRKINT);
+    stermios.c_iflag |= (ICANON|ICRNL); 
+
+    stermios.c_cc[VERASE]=0177;
+    if (tcsetattr(fd, TCSANOW, &stermios) < 0) return 0;
+    return 1;
+}
+
 int spawn(char *program, char *argv[], char *envp[], char *pty_name,
          int stdin, int stdout, int stderr)
 {
@@ -50,14 +78,13 @@ int spawn(char *program, char *argv[], char *envp[], char *pty_name,
            close(fd);
        }
 #endif
-
        fd = open(pty_name, O_RDWR, 0);
        dup2(fd, 0);
+       set_noecho(0);
        dup2(fd, 1);
        dup2(fd, 2);
        close(fd);
-    }
-
+    } else{
     /* Set up stdin, stdout, and stderr */
     if (stdin >= 0)
        dup2(stdin, 0);
@@ -65,7 +92,7 @@ int spawn(char *program, char *argv[], char *envp[], char *pty_name,
        dup2(stdout, 1);
     if (stderr >= 0)
        dup2(stderr, 2);
-
+    }
     /* Close all other fds. */
 #ifdef SVR4
     for (fd = sysconf(_SC_OPEN_MAX)-1; fd >= 3; fd--)
index e95ba52..3747e0c 100644 (file)
@@ -18,4 +18,4 @@
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
 
-"0.7.13.2"
+"0.7.13.3"