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