+ } else if (pti->pt_flags & PF_TIOC) {
+ while (pti->pt_flags & PF_LIOC) {
+ pti->pt_flags |= PF_WIOC;
+ switch (tsleep((caddr_t)&pti->pt_flags,TTIPRI-1,5*hz)) {
+ case TS_OK:
+ continue;
+ case TS_SIG:
+ case TS_TIME:
+ return (EBUSY);
+ }
+ }
+ pti->pt_flags |= PF_LIOC | PF_BLOCK;
+ while (pti->pt_ioc.c_cc)
+ (void) getc(&pti->pt_ioc);
+ (void) b_to_q(&cmd, sizeof cmd, &pti->pt_ioc);
+ if (cmd & IOC_IN)
+ (void) b_to_q(data, IOCPARM_LEN(cmd), &pti->pt_ioc);
+ ptcwakeup(tp, FREAD);
+ switch (tsleep((caddr_t)&pti->pt_ioc, TTIPRI-1, 5*hz)) {
+ case TS_SIG:
+ case TS_TIME:
+ while (pti->pt_ioc.c_cc)
+ (void) getc(&pti->pt_ioc);
+ if (pti->pt_flags & PF_WIOC)
+ wakeup((caddr_t)&pti->pt_flags);
+ if (pti->pt_flags & PF_OWAIT)
+ wakeup((caddr_t)pti + 1);
+ pti->pt_flags &= ~(PF_LIOC|PF_WIOC|PF_BLOCK|PF_OWAIT);
+ ptswake(tp);
+ return (EBUSY);
+ case TS_OK:
+ break;
+ }
+ if (pti->pt_ioc.c_cc == 0) {
+ if (pti->pt_flags & PF_WIOC)
+ wakeup((caddr_t)&pti->pt_flags);
+ if (pti->pt_flags & PF_OWAIT)
+ wakeup((caddr_t)pti + 1);
+ pti->pt_flags &= ~(PF_LIOC|PF_WIOC|PF_BLOCK|PF_OWAIT);
+ ptswake(tp);
+ goto doioctl;
+ }
+ if (q_to_b(&pti->pt_ioc, &error, sizeof error) != sizeof error)
+ error = EINVAL;
+ if (error == 0 && cmd & IOC_OUT) {
+ if (IOCPARM_LEN(cmd) != pti->pt_ioc.c_cc)
+ error = EINVAL;
+ else
+ (void) q_to_b(&pti->pt_ioc, data,
+ pti->pt_ioc.c_cc);
+ }
+ while (pti->pt_ioc.c_cc)
+ (void) getc(&pti->pt_ioc);
+ if (pti->pt_flags & PF_WIOC)
+ wakeup((caddr_t)&pti->pt_flags);
+ if (pti->pt_flags & PF_OWAIT)
+ wakeup((caddr_t)pti + 1);
+ pti->pt_flags &= ~(PF_LIOC|PF_WIOC|PF_BLOCK|PF_OWAIT);
+ ptswake(tp);
+ return (error);
+ }
+
+ doioctl:
+ error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag);
+ if (error < 0)
+ error = ttioctl(tp, cmd, data, flag);
+ /*
+ * Since we use the tty queues internally,
+ * pty's can't be switched to disciplines which overwrite
+ * the queues. We can't tell anything about the discipline
+ * from here...
+ *
+ * Nb: this is not really good enough, the line disc open routine
+ * may have done anything at all, no guarantees that close
+ * will fix it. This also has the effect of losing the
+ * previous discipline, which an error on a TIOCSETD shouldn't
+ * do... Sometime it should be done via an explicit check
+ * for TIOCSETD, then check to see what linesw[new_number].l_rint
+ * really is.
+ */
+ if (linesw[tp->t_line].l_rint != ttyinput) {
+ (*linesw[tp->t_line].l_close)(tp);
+ tp->t_line = 0;
+ (void)(*linesw[tp->t_line].l_open)(dev, tp, flag);
+ error = ENOTTY;
+ }
+