tty_pty.c revision 1.25 1 /* $NetBSD: tty_pty.c,v 1.25 1994/12/13 19:59:25 mycroft Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)tty_pty.c 8.2 (Berkeley) 9/23/93
36 */
37
38 /*
39 * Pseudo-teletype Driver
40 * (Actually two drivers, requiring two entries in 'cdevsw')
41 */
42 #include "pty.h" /* XXX */
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/ioctl.h>
47 #include <sys/proc.h>
48 #include <sys/tty.h>
49 #include <sys/conf.h>
50 #include <sys/file.h>
51 #include <sys/uio.h>
52 #include <sys/kernel.h>
53 #include <sys/vnode.h>
54
55 #if NPTY == 1
56 #undef NPTY
57 #define NPTY 32 /* crude XXX */
58 #endif
59
60 #define BUFSIZ 100 /* Chunk size iomoved to/from user */
61
62 /*
63 * pts == /dev/tty[pqrs]?
64 * ptc == /dev/pty[pqrs]?
65 */
66 struct tty *pt_tty[NPTY]; /* XXX */
67 struct pt_ioctl {
68 int pt_flags;
69 struct selinfo pt_selr, pt_selw;
70 u_char pt_send;
71 u_char pt_ucntl;
72 } pt_ioctl[NPTY]; /* XXX */
73 int npty = NPTY; /* for pstat -t */
74
75 #define PF_PKT 0x08 /* packet mode */
76 #define PF_STOPPED 0x10 /* user told stopped */
77 #define PF_REMOTE 0x20 /* remote and flow controlled input */
78 #define PF_NOSTOP 0x40
79 #define PF_UCNTL 0x80 /* user control mode */
80
81 void ptsstop __P((struct tty *, int));
82
83 /*
84 * Establish n (or default if n is 1) ptys in the system.
85 *
86 * XXX cdevsw & pstat require the array `pty[]' to be an array
87 */
88 void
89 ptyattach(n)
90 int n;
91 {
92 #ifdef notyet
93 char *mem;
94 register u_long ntb;
95 #define DEFAULT_NPTY 32
96
97 /* maybe should allow 0 => none? */
98 if (n <= 1)
99 n = DEFAULT_NPTY;
100 ntb = n * sizeof(struct tty);
101 mem = malloc(ntb + ALIGNBYTES + n * sizeof(struct pt_ioctl),
102 M_DEVBUF, M_WAITOK);
103 pt_tty = (struct tty *)mem;
104 mem = (char *)ALIGN(mem + ntb);
105 pt_ioctl = (struct pt_ioctl *)mem;
106 npty = n;
107 #endif
108 }
109
110 /*ARGSUSED*/
111 ptsopen(dev, flag, devtype, p)
112 dev_t dev;
113 int flag, devtype;
114 struct proc *p;
115 {
116 register struct tty *tp;
117 int error;
118
119 if (minor(dev) >= npty)
120 return (ENXIO);
121 if (!pt_tty[minor(dev)]) {
122 tp = pt_tty[minor(dev)] = ttymalloc();
123 } else
124 tp = pt_tty[minor(dev)];
125 if ((tp->t_state & TS_ISOPEN) == 0) {
126 tp->t_state |= TS_WOPEN;
127 ttychars(tp); /* Set up default chars */
128 tp->t_iflag = TTYDEF_IFLAG;
129 tp->t_oflag = TTYDEF_OFLAG;
130 tp->t_lflag = TTYDEF_LFLAG;
131 tp->t_cflag = TTYDEF_CFLAG;
132 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
133 ttsetwater(tp); /* would be done in xxparam() */
134 } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0)
135 return (EBUSY);
136 if (tp->t_oproc) /* Ctrlr still around. */
137 tp->t_state |= TS_CARR_ON;
138 while ((tp->t_state & TS_CARR_ON) == 0) {
139 tp->t_state |= TS_WOPEN;
140 if (flag&FNONBLOCK)
141 break;
142 if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH,
143 ttopen, 0))
144 return (error);
145 }
146 error = (*linesw[tp->t_line].l_open)(dev, tp);
147 ptcwakeup(tp, FREAD|FWRITE);
148 return (error);
149 }
150
151 ptsclose(dev, flag, mode, p)
152 dev_t dev;
153 int flag, mode;
154 struct proc *p;
155 {
156 register struct tty *tp;
157 int err;
158
159 tp = pt_tty[minor(dev)];
160 err = (*linesw[tp->t_line].l_close)(tp, flag);
161 err |= ttyclose(tp);
162 ptcwakeup(tp, FREAD|FWRITE);
163 return (err);
164 }
165
166 ptsread(dev, uio, flag)
167 dev_t dev;
168 struct uio *uio;
169 int flag;
170 {
171 struct proc *p = curproc;
172 register struct tty *tp = pt_tty[minor(dev)];
173 register struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
174 int error = 0;
175
176 again:
177 if (pti->pt_flags & PF_REMOTE) {
178 while (isbackground(p, tp)) {
179 if ((p->p_sigignore & sigmask(SIGTTIN)) ||
180 (p->p_sigmask & sigmask(SIGTTIN)) ||
181 p->p_pgrp->pg_jobc == 0 ||
182 p->p_flag & P_PPWAIT)
183 return (EIO);
184 pgsignal(p->p_pgrp, SIGTTIN, 1);
185 if (error = ttysleep(tp, (caddr_t)&lbolt,
186 TTIPRI | PCATCH, ttybg, 0))
187 return (error);
188 }
189 if (tp->t_canq.c_cc == 0) {
190 if (flag & IO_NDELAY)
191 return (EWOULDBLOCK);
192 if (error = ttysleep(tp, (caddr_t)&tp->t_canq,
193 TTIPRI | PCATCH, ttyin, 0))
194 return (error);
195 goto again;
196 }
197 while (tp->t_canq.c_cc > 1 && uio->uio_resid > 0)
198 if (ureadc(getc(&tp->t_canq), uio) < 0) {
199 error = EFAULT;
200 break;
201 }
202 if (tp->t_canq.c_cc == 1)
203 (void) getc(&tp->t_canq);
204 if (tp->t_canq.c_cc)
205 return (error);
206 } else
207 if (tp->t_oproc)
208 error = (*linesw[tp->t_line].l_read)(tp, uio, flag);
209 ptcwakeup(tp, FWRITE);
210 return (error);
211 }
212
213 /*
214 * Write to pseudo-tty.
215 * Wakeups of controlling tty will happen
216 * indirectly, when tty driver calls ptsstart.
217 */
218 ptswrite(dev, uio, flag)
219 dev_t dev;
220 struct uio *uio;
221 int flag;
222 {
223 register struct tty *tp;
224
225 tp = pt_tty[minor(dev)];
226 if (tp->t_oproc == 0)
227 return (EIO);
228 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
229 }
230
231 /*
232 * Start output on pseudo-tty.
233 * Wake up process selecting or sleeping for input from controlling tty.
234 */
235 void
236 ptsstart(tp)
237 struct tty *tp;
238 {
239 register struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
240
241 if (tp->t_state & TS_TTSTOP)
242 return;
243 if (pti->pt_flags & PF_STOPPED) {
244 pti->pt_flags &= ~PF_STOPPED;
245 pti->pt_send = TIOCPKT_START;
246 }
247 ptcwakeup(tp, FREAD);
248 }
249
250 ptcwakeup(tp, flag)
251 struct tty *tp;
252 int flag;
253 {
254 struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
255
256 if (flag & FREAD) {
257 selwakeup(&pti->pt_selr);
258 wakeup((caddr_t)&tp->t_outq.c_cf);
259 }
260 if (flag & FWRITE) {
261 selwakeup(&pti->pt_selw);
262 wakeup((caddr_t)&tp->t_rawq.c_cf);
263 }
264 }
265
266 int ptcopen __P((dev_t, int, int, struct proc *, struct file *));
267
268 /*ARGSUSED*/
269 int
270 ptcopen(dev, flag, devtype, p, fp)
271 dev_t dev;
272 int flag, devtype;
273 struct proc *p;
274 struct file *fp;
275 {
276 register struct tty *tp;
277 struct pt_ioctl *pti;
278
279 if (minor(dev) >= npty)
280 return (ENXIO);
281 if(!pt_tty[minor(dev)]) {
282 tp = pt_tty[minor(dev)] = ttymalloc();
283 } else
284 tp = pt_tty[minor(dev)];
285 if (tp->t_oproc)
286 return (EIO);
287 tp->t_oproc = ptsstart;
288 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
289 tp->t_lflag &= ~EXTPROC;
290 pti = &pt_ioctl[minor(dev)];
291 pti->pt_flags = 0;
292 pti->pt_send = 0;
293 pti->pt_ucntl = 0;
294 return (0);
295 }
296
297 int
298 ptcclose(dev)
299 dev_t dev;
300 {
301 register struct tty *tp;
302
303 tp = pt_tty[minor(dev)];
304 (void)(*linesw[tp->t_line].l_modem)(tp, 0);
305 tp->t_state &= ~TS_CARR_ON;
306 tp->t_oproc = 0; /* mark closed */
307 return (0);
308 }
309
310 ptcread(dev, uio, flag)
311 dev_t dev;
312 struct uio *uio;
313 int flag;
314 {
315 register struct tty *tp = pt_tty[minor(dev)];
316 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
317 char buf[BUFSIZ];
318 int error = 0, cc;
319
320 /*
321 * We want to block until the slave
322 * is open, and there's something to read;
323 * but if we lost the slave or we're NBIO,
324 * then return the appropriate error instead.
325 */
326 for (;;) {
327 if (tp->t_state&TS_ISOPEN) {
328 if (pti->pt_flags&PF_PKT && pti->pt_send) {
329 error = ureadc((int)pti->pt_send, uio);
330 if (error)
331 return (error);
332 if (pti->pt_send & TIOCPKT_IOCTL) {
333 cc = min(uio->uio_resid,
334 sizeof(tp->t_termios));
335 uiomove(&tp->t_termios, cc, uio);
336 }
337 pti->pt_send = 0;
338 return (0);
339 }
340 if (pti->pt_flags&PF_UCNTL && pti->pt_ucntl) {
341 error = ureadc((int)pti->pt_ucntl, uio);
342 if (error)
343 return (error);
344 pti->pt_ucntl = 0;
345 return (0);
346 }
347 if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0)
348 break;
349 }
350 if ((tp->t_state&TS_CARR_ON) == 0)
351 return (0); /* EOF */
352 if (flag & IO_NDELAY)
353 return (EWOULDBLOCK);
354 if (error = tsleep((caddr_t)&tp->t_outq.c_cf, TTIPRI | PCATCH,
355 ttyin, 0))
356 return (error);
357 }
358 if (pti->pt_flags & (PF_PKT|PF_UCNTL))
359 error = ureadc(0, uio);
360 while (uio->uio_resid > 0 && error == 0) {
361 cc = q_to_b(&tp->t_outq, buf, min(uio->uio_resid, BUFSIZ));
362 if (cc <= 0)
363 break;
364 error = uiomove(buf, cc, uio);
365 }
366 if (tp->t_outq.c_cc <= tp->t_lowat) {
367 if (tp->t_state&TS_ASLEEP) {
368 tp->t_state &= ~TS_ASLEEP;
369 wakeup((caddr_t)&tp->t_outq);
370 }
371 selwakeup(&tp->t_wsel);
372 }
373 return (error);
374 }
375
376 void
377 ptsstop(tp, flush)
378 register struct tty *tp;
379 int flush;
380 {
381 struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
382 int flag;
383
384 /* note: FLUSHREAD and FLUSHWRITE already ok */
385 if (flush == 0) {
386 flush = TIOCPKT_STOP;
387 pti->pt_flags |= PF_STOPPED;
388 } else
389 pti->pt_flags &= ~PF_STOPPED;
390 pti->pt_send |= flush;
391 /* change of perspective */
392 flag = 0;
393 if (flush & FREAD)
394 flag |= FWRITE;
395 if (flush & FWRITE)
396 flag |= FREAD;
397 ptcwakeup(tp, flag);
398 }
399
400 ptcselect(dev, rw, p)
401 dev_t dev;
402 int rw;
403 struct proc *p;
404 {
405 register struct tty *tp = pt_tty[minor(dev)];
406 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
407 int s;
408
409 if ((tp->t_state&TS_CARR_ON) == 0)
410 return (1);
411 switch (rw) {
412
413 case FREAD:
414 /*
415 * Need to block timeouts (ttrstart).
416 */
417 s = spltty();
418 if ((tp->t_state&TS_ISOPEN) &&
419 tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) {
420 splx(s);
421 return (1);
422 }
423 splx(s);
424 /* FALLTHROUGH */
425
426 case 0: /* exceptional */
427 if ((tp->t_state&TS_ISOPEN) &&
428 (pti->pt_flags&PF_PKT && pti->pt_send ||
429 pti->pt_flags&PF_UCNTL && pti->pt_ucntl))
430 return (1);
431 selrecord(p, &pti->pt_selr);
432 break;
433
434
435 case FWRITE:
436 if (tp->t_state&TS_ISOPEN) {
437 if (pti->pt_flags & PF_REMOTE) {
438 if (tp->t_canq.c_cc == 0)
439 return (1);
440 } else {
441 if (tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG-2)
442 return (1);
443 if (tp->t_canq.c_cc == 0 && (tp->t_iflag&ICANON))
444 return (1);
445 }
446 }
447 selrecord(p, &pti->pt_selw);
448 break;
449
450 }
451 return (0);
452 }
453
454 ptcwrite(dev, uio, flag)
455 dev_t dev;
456 register struct uio *uio;
457 int flag;
458 {
459 register struct tty *tp = pt_tty[minor(dev)];
460 register u_char *cp;
461 register int cc = 0;
462 u_char locbuf[BUFSIZ];
463 int cnt = 0;
464 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
465 int error = 0;
466
467 again:
468 if ((tp->t_state&TS_ISOPEN) == 0)
469 goto block;
470 if (pti->pt_flags & PF_REMOTE) {
471 if (tp->t_canq.c_cc)
472 goto block;
473 while (uio->uio_resid > 0 && tp->t_canq.c_cc < TTYHOG - 1) {
474 if (cc == 0) {
475 cc = min(uio->uio_resid, BUFSIZ);
476 cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc);
477 cp = locbuf;
478 error = uiomove((caddr_t)cp, cc, uio);
479 if (error)
480 return (error);
481 /* check again for safety */
482 if ((tp->t_state&TS_ISOPEN) == 0)
483 return (EIO);
484 }
485 if (cc)
486 (void) b_to_q((char *)cp, cc, &tp->t_canq);
487 cc = 0;
488 }
489 (void) putc(0, &tp->t_canq);
490 ttwakeup(tp);
491 wakeup((caddr_t)&tp->t_canq);
492 return (0);
493 }
494 while (uio->uio_resid > 0) {
495 if (cc == 0) {
496 cc = min(uio->uio_resid, BUFSIZ);
497 cp = locbuf;
498 error = uiomove((caddr_t)cp, cc, uio);
499 if (error)
500 return (error);
501 /* check again for safety */
502 if ((tp->t_state&TS_ISOPEN) == 0)
503 return (EIO);
504 }
505 while (cc > 0) {
506 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
507 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) {
508 wakeup((caddr_t)&tp->t_rawq);
509 goto block;
510 }
511 (*linesw[tp->t_line].l_rint)(*cp++, tp);
512 cnt++;
513 cc--;
514 }
515 cc = 0;
516 }
517 return (0);
518 block:
519 /*
520 * Come here to wait for slave to open, for space
521 * in outq, or space in rawq.
522 */
523 if ((tp->t_state&TS_CARR_ON) == 0)
524 return (EIO);
525 if (flag & IO_NDELAY) {
526 /* adjust for data copied in but not written */
527 uio->uio_resid += cc;
528 if (cnt == 0)
529 return (EWOULDBLOCK);
530 return (0);
531 }
532 if (error = tsleep((caddr_t)&tp->t_rawq.c_cf, TTOPRI | PCATCH,
533 ttyout, 0)) {
534 /* adjust for data copied in but not written */
535 uio->uio_resid += cc;
536 return (error);
537 }
538 goto again;
539 }
540
541 /*ARGSUSED*/
542 ptyioctl(dev, cmd, data, flag, p)
543 dev_t dev;
544 u_long cmd;
545 caddr_t data;
546 int flag;
547 struct proc *p;
548 {
549 register struct tty *tp = pt_tty[minor(dev)];
550 register struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
551 register u_char *cc = tp->t_cc;
552 int stop, error;
553
554 /*
555 * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG.
556 * ttywflush(tp) will hang if there are characters in the outq.
557 */
558 if (cmd == TIOCEXT) {
559 /*
560 * When the EXTPROC bit is being toggled, we need
561 * to send an TIOCPKT_IOCTL if the packet driver
562 * is turned on.
563 */
564 if (*(int *)data) {
565 if (pti->pt_flags & PF_PKT) {
566 pti->pt_send |= TIOCPKT_IOCTL;
567 ptcwakeup(tp, FREAD);
568 }
569 tp->t_lflag |= EXTPROC;
570 } else {
571 if ((tp->t_state & EXTPROC) &&
572 (pti->pt_flags & PF_PKT)) {
573 pti->pt_send |= TIOCPKT_IOCTL;
574 ptcwakeup(tp, FREAD);
575 }
576 tp->t_lflag &= ~EXTPROC;
577 }
578 return(0);
579 } else
580 if (cdevsw[major(dev)].d_open == ptcopen)
581 switch (cmd) {
582
583 case TIOCGPGRP:
584 /*
585 * We aviod calling ttioctl on the controller since,
586 * in that case, tp must be the controlling terminal.
587 */
588 *(int *)data = tp->t_pgrp ? tp->t_pgrp->pg_id : 0;
589 return (0);
590
591 case TIOCPKT:
592 if (*(int *)data) {
593 if (pti->pt_flags & PF_UCNTL)
594 return (EINVAL);
595 pti->pt_flags |= PF_PKT;
596 } else
597 pti->pt_flags &= ~PF_PKT;
598 return (0);
599
600 case TIOCUCNTL:
601 if (*(int *)data) {
602 if (pti->pt_flags & PF_PKT)
603 return (EINVAL);
604 pti->pt_flags |= PF_UCNTL;
605 } else
606 pti->pt_flags &= ~PF_UCNTL;
607 return (0);
608
609 case TIOCREMOTE:
610 if (*(int *)data)
611 pti->pt_flags |= PF_REMOTE;
612 else
613 pti->pt_flags &= ~PF_REMOTE;
614 ttyflush(tp, FREAD|FWRITE);
615 return (0);
616
617 #ifdef COMPAT_43
618 case TIOCSETP:
619 case TIOCSETN:
620 #endif
621 case TIOCSETD:
622 case TIOCSETA:
623 case TIOCSETAW:
624 case TIOCSETAF:
625 ndflush(&tp->t_outq, tp->t_outq.c_cc);
626 break;
627
628 case TIOCSIG:
629 if (*(unsigned int *)data >= NSIG)
630 return(EINVAL);
631 if ((tp->t_lflag&NOFLSH) == 0)
632 ttyflush(tp, FREAD|FWRITE);
633 pgsignal(tp->t_pgrp, *(unsigned int *)data, 1);
634 if ((*(unsigned int *)data == SIGINFO) &&
635 ((tp->t_lflag&NOKERNINFO) == 0))
636 ttyinfo(tp);
637 return(0);
638 }
639 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
640 if (error < 0)
641 error = ttioctl(tp, cmd, data, flag, p);
642 if (error < 0) {
643 if (pti->pt_flags & PF_UCNTL &&
644 (cmd & ~0xff) == UIOCCMD(0)) {
645 if (cmd & 0xff) {
646 pti->pt_ucntl = (u_char)cmd;
647 ptcwakeup(tp, FREAD);
648 }
649 return (0);
650 }
651 error = ENOTTY;
652 }
653 /*
654 * If external processing and packet mode send ioctl packet.
655 */
656 if ((tp->t_lflag&EXTPROC) && (pti->pt_flags & PF_PKT)) {
657 switch(cmd) {
658 case TIOCSETA:
659 case TIOCSETAW:
660 case TIOCSETAF:
661 #ifdef COMPAT_43
662 case TIOCSETP:
663 case TIOCSETN:
664 #endif
665 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
666 case TIOCSETC:
667 case TIOCSLTC:
668 case TIOCLBIS:
669 case TIOCLBIC:
670 case TIOCLSET:
671 #endif
672 pti->pt_send |= TIOCPKT_IOCTL;
673 ptcwakeup(tp, FREAD);
674 default:
675 break;
676 }
677 }
678 stop = (tp->t_iflag & IXON) && CCEQ(cc[VSTOP], CTRL('s'))
679 && CCEQ(cc[VSTART], CTRL('q'));
680 if (pti->pt_flags & PF_NOSTOP) {
681 if (stop) {
682 pti->pt_send &= ~TIOCPKT_NOSTOP;
683 pti->pt_send |= TIOCPKT_DOSTOP;
684 pti->pt_flags &= ~PF_NOSTOP;
685 ptcwakeup(tp, FREAD);
686 }
687 } else {
688 if (!stop) {
689 pti->pt_send &= ~TIOCPKT_DOSTOP;
690 pti->pt_send |= TIOCPKT_NOSTOP;
691 pti->pt_flags |= PF_NOSTOP;
692 ptcwakeup(tp, FREAD);
693 }
694 }
695 return (error);
696 }
697