From 4e23e6eb166c98a130242db54491500f3d2ebce5 Mon Sep 17 00:00:00 2001 From: luoqi Date: Tue, 18 May 1999 14:53:52 +0000 Subject: TIOCEXT is also inapproriate before the slave is open, return EAGAIN when these ioctls are attempted. Move a misplaced comment. Pointed out by: Bruce --- sys/kern/tty_pty.c | 60 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'sys/kern/tty_pty.c') diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index 5cdb711..87f21f0 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95 - * $Id: tty_pty.c,v 1.57 1999/05/08 06:39:43 phk Exp $ + * $Id: tty_pty.c,v 1.58 1999/05/14 20:44:20 luoqi Exp $ */ /* @@ -649,32 +649,7 @@ ptyioctl(dev, cmd, data, flag, p) register u_char *cc = tp->t_cc; int stop, error; - /* - * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG. - * ttywflush(tp) will hang if there are characters in the outq. - */ - if (cmd == TIOCEXT) { - /* - * When the EXTPROC bit is being toggled, we need - * to send an TIOCPKT_IOCTL if the packet driver - * is turned on. - */ - if (*(int *)data) { - if (pti->pt_flags & PF_PKT) { - pti->pt_send |= TIOCPKT_IOCTL; - ptcwakeup(tp, FREAD); - } - tp->t_lflag |= EXTPROC; - } else { - if ((tp->t_lflag & EXTPROC) && - (pti->pt_flags & PF_PKT)) { - pti->pt_send |= TIOCPKT_IOCTL; - ptcwakeup(tp, FREAD); - } - tp->t_lflag &= ~EXTPROC; - } - return(0); - } else if (devsw(dev)->d_open == ptcopen) { + if (devsw(dev)->d_open == ptcopen) { switch (cmd) { case TIOCGPGRP: @@ -714,10 +689,10 @@ ptyioctl(dev, cmd, data, flag, p) /* * The rest of the ioctls shouldn't be called until - * the slave is open. (Should we return an error?) + * the slave is open. */ if ((tp->t_state & TS_ISOPEN) == 0) - return (0); + return (EAGAIN); switch (cmd) { #ifdef COMPAT_43 @@ -728,6 +703,11 @@ ptyioctl(dev, cmd, data, flag, p) case TIOCSETA: case TIOCSETAW: case TIOCSETAF: + /* + * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG. + * ttywflush(tp) will hang if there are characters in + * the outq. + */ ndflush(&tp->t_outq, tp->t_outq.c_cc); break; @@ -744,6 +724,28 @@ ptyioctl(dev, cmd, data, flag, p) return(0); } } + if (cmd == TIOCEXT) { + /* + * When the EXTPROC bit is being toggled, we need + * to send an TIOCPKT_IOCTL if the packet driver + * is turned on. + */ + if (*(int *)data) { + if (pti->pt_flags & PF_PKT) { + pti->pt_send |= TIOCPKT_IOCTL; + ptcwakeup(tp, FREAD); + } + tp->t_lflag |= EXTPROC; + } else { + if ((tp->t_lflag & EXTPROC) && + (pti->pt_flags & PF_PKT)) { + pti->pt_send |= TIOCPKT_IOCTL; + ptcwakeup(tp, FREAD); + } + tp->t_lflag &= ~EXTPROC; + } + return(0); + } error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p); if (error == ENOIOCTL) error = ttioctl(tp, cmd, data, flag); -- cgit v1.1