Deleted Added
full compact
pty.c (9639) pty.c (9824)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. 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

--- 17 unchanged lines hidden (view full) ---

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 * @(#)tty_pty.c 8.2 (Berkeley) 9/23/93
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. 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

--- 17 unchanged lines hidden (view full) ---

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 * @(#)tty_pty.c 8.2 (Berkeley) 9/23/93
34 * $Id: tty_pty.c,v 1.14 1995/07/22 01:30:32 bde Exp $
34 * $Id: tty_pty.c,v 1.15 1995/07/22 16:45:08 bde Exp $
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "pty.h" /* XXX */
42

--- 84 unchanged lines hidden (view full) ---

127 tp->t_oflag = TTYDEF_OFLAG;
128 tp->t_lflag = TTYDEF_LFLAG;
129 tp->t_cflag = TTYDEF_CFLAG;
130 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
131 ttsetwater(tp); /* would be done in xxparam() */
132 } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0)
133 return (EBUSY);
134 if (tp->t_oproc) /* Ctrlr still around. */
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "pty.h" /* XXX */
42

--- 84 unchanged lines hidden (view full) ---

127 tp->t_oflag = TTYDEF_OFLAG;
128 tp->t_lflag = TTYDEF_LFLAG;
129 tp->t_cflag = TTYDEF_CFLAG;
130 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
131 ttsetwater(tp); /* would be done in xxparam() */
132 } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0)
133 return (EBUSY);
134 if (tp->t_oproc) /* Ctrlr still around. */
135 tp->t_state |= TS_CARR_ON;
135 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
136 while ((tp->t_state & TS_CARR_ON) == 0) {
137 if (flag&FNONBLOCK)
138 break;
139 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
140 "ptsopn", 0);
141 if (error)
142 return (error);
143 }

--- 119 unchanged lines hidden (view full) ---

263 wakeup(TSA_PTC_READ(tp));
264 }
265 if (flag & FWRITE) {
266 selwakeup(&pti->pt_selw);
267 wakeup(TSA_PTC_WRITE(tp));
268 }
269}
270
136 while ((tp->t_state & TS_CARR_ON) == 0) {
137 if (flag&FNONBLOCK)
138 break;
139 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
140 "ptsopn", 0);
141 if (error)
142 return (error);
143 }

--- 119 unchanged lines hidden (view full) ---

263 wakeup(TSA_PTC_READ(tp));
264 }
265 if (flag & FWRITE) {
266 selwakeup(&pti->pt_selw);
267 wakeup(TSA_PTC_WRITE(tp));
268 }
269}
270
271/*ARGSUSED*/
272#ifdef __STDC__
273int
271int
274ptcopen(dev_t dev, int flag, int devtype, struct proc *p)
275#else
276int
277ptcopen(dev, flag, devtype, p)
278 dev_t dev;
279 int flag, devtype;
280 struct proc *p;
272ptcopen(dev, flag, devtype, p)
273 dev_t dev;
274 int flag, devtype;
275 struct proc *p;
281#endif
282{
283 register struct tty *tp;
284 struct pt_ioctl *pti;
285
286 if (minor(dev) >= npty)
287 return (ENXIO);
288 tp = &pt_tty[minor(dev)];
289 if (tp->t_oproc)

--- 14 unchanged lines hidden (view full) ---

304int
305ptcclose(dev)
306 dev_t dev;
307{
308 register struct tty *tp;
309
310 tp = &pt_tty[minor(dev)];
311 (void)(*linesw[tp->t_line].l_modem)(tp, 0);
276{
277 register struct tty *tp;
278 struct pt_ioctl *pti;
279
280 if (minor(dev) >= npty)
281 return (ENXIO);
282 tp = &pt_tty[minor(dev)];
283 if (tp->t_oproc)

--- 14 unchanged lines hidden (view full) ---

298int
299ptcclose(dev)
300 dev_t dev;
301{
302 register struct tty *tp;
303
304 tp = &pt_tty[minor(dev)];
305 (void)(*linesw[tp->t_line].l_modem)(tp, 0);
312 tp->t_state &= ~TS_CARR_ON;
306
307 /*
308 * XXX MDMBUF makes no sense for ptys but would inhibit the above
309 * l_modem(). CLOCAL makes sense but isn't supported. Special
310 * l_modem()s that ignore carrier drop make no sense for ptys but
311 * may be in use because other parts of the line discipline make
312 * sense for ptys. Recover by doing everything that a normal
313 * ttymodem() would have done except for sending a SIGHUP.
314 */
315 tp->t_state &= ~(TS_CARR_ON | TS_CONNECTED);
316 tp->t_state |= TS_ZOMBIE;
317 ttyflush(tp, FREAD | FWRITE);
318
313 tp->t_oproc = 0; /* mark closed */
314 tp->t_session = 0;
315 return (0);
316}
317
318int
319ptcread(dev, uio, flag)
320 dev_t dev;

--- 31 unchanged lines hidden (view full) ---

352 if (error)
353 return (error);
354 pti->pt_ucntl = 0;
355 return (0);
356 }
357 if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0)
358 break;
359 }
319 tp->t_oproc = 0; /* mark closed */
320 tp->t_session = 0;
321 return (0);
322}
323
324int
325ptcread(dev, uio, flag)
326 dev_t dev;

--- 31 unchanged lines hidden (view full) ---

358 if (error)
359 return (error);
360 pti->pt_ucntl = 0;
361 return (0);
362 }
363 if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0)
364 break;
365 }
360 if ((tp->t_state&TS_CARR_ON) == 0)
366 if ((tp->t_state & TS_CONNECTED) == 0)
361 return (0); /* EOF */
362 if (flag & IO_NDELAY)
363 return (EWOULDBLOCK);
364 error = tsleep(TSA_PTC_READ(tp), TTIPRI | PCATCH, "ptcin", 0);
365 if (error)
366 return (error);
367 }
368 if (pti->pt_flags & (PF_PKT|PF_UCNTL))

--- 37 unchanged lines hidden (view full) ---

406 dev_t dev;
407 int rw;
408 struct proc *p;
409{
410 register struct tty *tp = &pt_tty[minor(dev)];
411 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
412 int s;
413
367 return (0); /* EOF */
368 if (flag & IO_NDELAY)
369 return (EWOULDBLOCK);
370 error = tsleep(TSA_PTC_READ(tp), TTIPRI | PCATCH, "ptcin", 0);
371 if (error)
372 return (error);
373 }
374 if (pti->pt_flags & (PF_PKT|PF_UCNTL))

--- 37 unchanged lines hidden (view full) ---

412 dev_t dev;
413 int rw;
414 struct proc *p;
415{
416 register struct tty *tp = &pt_tty[minor(dev)];
417 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
418 int s;
419
414 if ((tp->t_state&TS_CARR_ON) == 0)
420 if ((tp->t_state & TS_CONNECTED) == 0)
415 return (1);
416 switch (rw) {
417
418 case FREAD:
419 /*
420 * Need to block timeouts (ttrstart).
421 */
422 s = spltty();

--- 83 unchanged lines hidden (view full) ---

506 return (error);
507 /* check again for safety */
508 if ((tp->t_state&TS_ISOPEN) == 0)
509 return (EIO);
510 }
511 while (cc > 0) {
512 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
513 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) {
421 return (1);
422 switch (rw) {
423
424 case FREAD:
425 /*
426 * Need to block timeouts (ttrstart).
427 */
428 s = spltty();

--- 83 unchanged lines hidden (view full) ---

512 return (error);
513 /* check again for safety */
514 if ((tp->t_state&TS_ISOPEN) == 0)
515 return (EIO);
516 }
517 while (cc > 0) {
518 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
519 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) {
514 wakeup(TSA_CARR_ON(tp));
520 wakeup(TSA_HUP_OR_INPUT(tp));
515 goto block;
516 }
517 (*linesw[tp->t_line].l_rint)(*cp++, tp);
518 cnt++;
519 cc--;
520 }
521 cc = 0;
522 }
523 return (0);
524block:
525 /*
526 * Come here to wait for slave to open, for space
527 * in outq, or space in rawq.
528 */
521 goto block;
522 }
523 (*linesw[tp->t_line].l_rint)(*cp++, tp);
524 cnt++;
525 cc--;
526 }
527 cc = 0;
528 }
529 return (0);
530block:
531 /*
532 * Come here to wait for slave to open, for space
533 * in outq, or space in rawq.
534 */
529 if ((tp->t_state&TS_CARR_ON) == 0)
535 if ((tp->t_state & TS_CONNECTED) == 0)
530 return (EIO);
531 if (flag & IO_NDELAY) {
532 /* adjust for data copied in but not written */
533 uio->uio_resid += cc;
534 if (cnt == 0)
535 return (EWOULDBLOCK);
536 return (0);
537 }

--- 176 unchanged lines hidden ---
536 return (EIO);
537 if (flag & IO_NDELAY) {
538 /* adjust for data copied in but not written */
539 uio->uio_resid += cc;
540 if (cnt == 0)
541 return (EWOULDBLOCK);
542 return (0);
543 }

--- 176 unchanged lines hidden ---