From d68f3f83e6c5b9bed9789279cbae346f240488cc Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 26 Feb 2003 02:28:35 +0000 Subject: [PATCH] 0.7.13.3 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 | 43 ------------------------------------------- src/runtime/run-program.c | 35 +++++++++++++++++++++++++++++++---- version.lisp-expr | 2 +- 3 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/code/run-program.lisp b/src/code/run-program.lisp index aee63b8bb..9153a8f2c 100644 --- a/src/code/run-program.lisp +++ b/src/code/run-program.lisp @@ -284,21 +284,6 @@ ;;; 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. @@ -315,34 +300,6 @@ 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 diff --git a/src/runtime/run-program.c b/src/runtime/run-program.c index 2e92d8363..241db7ff8 100644 --- a/src/runtime/run-program.c +++ b/src/runtime/run-program.c @@ -23,6 +23,34 @@ #include #endif +#include +#include + + +/* 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--) diff --git a/version.lisp-expr b/version.lisp-expr index e95ba52ad..3747e0ccb 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -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" -- 2.11.4.GIT