$NetBSD: patch-aj,v 1.1 2000/02/07 03:18:13 christos Exp $ --- fep_main.c.orig Wed Jun 9 22:53:06 1993 +++ fep_main.c Sun Feb 6 22:00:22 2000 @@ -10,8 +10,17 @@ #include #include #include -#include +#ifdef TERMIOS +#include +#ifdef __linux__ +#ifndef _POSIX_VDISABLE +#define _POSIX_VDISABLE '\0' +#endif +#endif +#else #include +#endif +#include #include #include #include @@ -38,9 +47,9 @@ /* delimiter characters */ int master; /* file discriptor for pty master */ int slave; /* file discriptor for pty slave */ -int mastermask; /* 1<_cnt) - if (CHAR_IN_BUFFER) - goto RETURNCHAR; + FD_ZERO(&writefd); + FD_ZERO(&exceptfd); RETRY: readfd = selectmask; @@ -409,13 +429,13 @@ while ((nfound = select (selectnfds, &readfd, 0, 0, *timeout)) < 0) if (errno != EINTR) { perror ("select"); - terminate(); + terminate(0); } /* * Found output from pty. */ - if (readfd & mastermask) { + if (FD_ISSET(master, &readfd)) { int nbyte; /* @@ -451,7 +471,7 @@ /* * Found input from terminal */ - if (CHAR_IN_BUFFER || readfd & stdinmask) { + if (FD_ISSET(fileno(stdin), &readfd)) { #ifndef USE_TIMEOUT /* @@ -468,7 +488,7 @@ if ((c = getc (stdin)) == EOF) { if (debug) printf ("EOF chatched\n"); - terminate (); + terminate (0); } else return (c & CHARMASK); @@ -596,7 +616,7 @@ swallow_output() { - int readfd = mastermask; + fd_set readfd = mastermask; int r; int nbyte; int ncount = 10; @@ -604,7 +624,7 @@ while ( ncount-- && select (selectnfds, &readfd, 0, 0, TIMEOUT_NOBLOCK) > 0 && - readfd & mastermask + FD_ISSET(master, &mastermask) ) { nbyte = buf_read (master, output_buffer); if (nbyte > 0) { @@ -636,9 +656,11 @@ #include #endif -catchsig() +void +catchsig(n) + int n; { - union wait status; + int status; struct rusage ru; if (wait3 (&status, WNOHANG | WUNTRACED, &ru) != child_pid) @@ -650,7 +672,7 @@ suspend (); return; } - terminate (); + terminate (0); } exec_to_command(argv) @@ -675,13 +697,37 @@ dup2 (slave, 2); (void) close (slave); +#ifdef TERMIOS + tcsetattr(0, TCSANOW, &slave_ttymode); +#elif defined(TIOCSETN) ioctl (0, TIOCSETN, (char *) & slave_ttymode); - +#endif execvp (*argv, argv, 0); perror (*argv); exit (1); } +#ifdef TERMIOS +fix_tty() +{ + int i; + master_ttymode = initial_ttymode; + slave_ttymode = initial_ttymode; + master_ttymode.c_lflag &= ~(ECHO|ECHOE|ECHOK|ICANON); + + for (i = 0; i < NCCS; i++) + master_ttymode.c_cc[i] = _POSIX_VDISABLE; + + master_ttymode.c_cc[VMIN] = 1; + master_ttymode.c_cc[VTIME] = 0; + slave_ttymode.c_lflag &= ~(ECHO|ECHOE|ECHOK); + slave_ttymode.c_iflag &= ~(ICRNL); + slave_ttymode.c_oflag &= ~(ONLCR); + tcsetattr(0, TCSANOW, &master_ttymode); +} + +#elif defined(TIOCSETN) + fix_tty() { struct tchars tcbuf; @@ -719,6 +765,7 @@ ioctl (0, TIOCSETC, (char *) & tcbuf); ioctl (0, TIOCSLTC, (char *) & lcbuf); } +#endif kill_process() { @@ -727,7 +774,9 @@ (void) killpg (child_pid, SIGTERM); } -terminate() +void +terminate(n) + int n; { extern int errno; @@ -759,9 +808,13 @@ if (killpg (child_pid, SIGKILL) < 0) perror ("kill"); +#ifdef TERMIOS + tcsetattr(0, TCSANOW, &initial_ttymode); +#elif defined(TIOCSETN) ioctl (0, TIOCSETN, (char *) & initial_ttymode); ioctl (0, TIOCSETC, (char *) & tchars_buf); ioctl (0, TIOCSLTC, (char *) & ltchars_buf); +#endif exit (0); } @@ -796,11 +849,15 @@ } FOUND: +#ifdef TERMIOS + tcgetattr(0, &initial_ttymode); +#elif defined(TIOCSETN) ioctl (0, TIOCGETP, (char *) &initial_ttymode); ioctl (0, TIOCGETC, (char *) &tchars_buf); ioctl (0, TIOCGETD, (char *) &line_desc); ioctl (0, TIOCGLTC, (char *) <chars_buf); ioctl (0, TIOCLGET, (char *) &lmode_buf); +#endif #ifdef TIOCGWINSZ { @@ -822,9 +879,13 @@ # endif #endif KANJI - stdinmask = 1 << fileno (stdin); - mastermask = 1 << master; - selectmask = stdinmask | mastermask; + FD_ZERO(&stdinmask); + FD_ZERO(&mastermask); + FD_ZERO(&selectmask); + FD_SET(fileno(stdin), &stdinmask); + FD_SET(master, &mastermask); + FD_SET(fileno(stdin), &selectmask); + FD_SET(master, &selectmask); selectnfds = max (fileno(stdin), master) + 1; return; @@ -838,11 +899,15 @@ perror (slave_tty); exit (1); } +#ifdef TERMIOS + tcsetattr(slave, TCSANOW, &initial_ttymode); +#elif defined(TIOCSETN) ioctl (slave, TIOCSETN, (char *) &initial_ttymode); ioctl (slave, TIOCSETC, (char *) &tchars_buf); ioctl (slave, TIOCSLTC, (char *) <chars_buf); ioctl (slave, TIOCLSET, (char *) &lmode_buf); ioctl (slave, TIOCSETD, (char *) &line_desc); +#endif #ifdef KANJI # if defined(TIOCKGET) && defined(TIOCKSET) @@ -866,16 +931,19 @@ recover_tty() { - +#ifdef TERMIOS + tcsetattr(0, TCSANOW, &initial_ttymode); +#elif defined(TIOCSETN) ioctl (0, TIOCSETN, (char *) & initial_ttymode); ioctl (0, TIOCSETC, (char *) & tchars_buf); ioctl (0, TIOCSLTC, (char *) & ltchars_buf); +#endif } suspend() { long pid; - void (*func) (); + void (*func) __P((int)); int omask; extern int errno; @@ -890,7 +958,7 @@ if (kill (child_pid, SIGCONT) < 0 && errno == ESRCH) { printf ("Where my child has gone?!\n"); - terminate (); + terminate (0); } killpg (child_pid, SIGCONT); kill (0, SIGCONT);