;;; 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
#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)
{
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);
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--)