Deleted Added
full compact
pty.c (29041) pty.c (29354)
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.4 (Berkeley) 2/20/95
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.4 (Berkeley) 2/20/95
34 * $Id: tty_pty.c,v 1.44 1997/07/30 10:05:18 jmg Exp $
34 * $Id: tty_pty.c,v 1.45 1997/09/02 20:05:55 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
43#include <sys/param.h>
44#include <sys/systm.h>
45#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
46#include <sys/ioctl_compat.h>
47#endif
48#include <sys/proc.h>
49#include <sys/tty.h>
50#include <sys/conf.h>
51#include <sys/fcntl.h>
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "pty.h" /* XXX */
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
46#include <sys/ioctl_compat.h>
47#endif
48#include <sys/proc.h>
49#include <sys/tty.h>
50#include <sys/conf.h>
51#include <sys/fcntl.h>
52#include <sys/poll.h>
52#include <sys/kernel.h>
53#include <sys/vnode.h>
54#include <sys/signalvar.h>
55
56#ifdef DEVFS
57#include <sys/devfsext.h>
58#endif /*DEVFS*/
59

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

69static d_write_t ptswrite;
70static d_ioctl_t ptyioctl;
71static d_stop_t ptsstop;
72static d_devtotty_t ptydevtotty;
73static d_open_t ptcopen;
74static d_close_t ptcclose;
75static d_read_t ptcread;
76static d_write_t ptcwrite;
53#include <sys/kernel.h>
54#include <sys/vnode.h>
55#include <sys/signalvar.h>
56
57#ifdef DEVFS
58#include <sys/devfsext.h>
59#endif /*DEVFS*/
60

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

70static d_write_t ptswrite;
71static d_ioctl_t ptyioctl;
72static d_stop_t ptsstop;
73static d_devtotty_t ptydevtotty;
74static d_open_t ptcopen;
75static d_close_t ptcclose;
76static d_read_t ptcread;
77static d_write_t ptcwrite;
77static d_select_t ptcselect;
78static d_poll_t ptcpoll;
78
79#define CDEV_MAJOR_S 5
80#define CDEV_MAJOR_C 6
81static struct cdevsw pts_cdevsw =
82 { ptsopen, ptsclose, ptsread, ptswrite, /*5*/
83 ptyioctl, ptsstop, nullreset, ptydevtotty,/* ttyp */
79
80#define CDEV_MAJOR_S 5
81#define CDEV_MAJOR_C 6
82static struct cdevsw pts_cdevsw =
83 { ptsopen, ptsclose, ptsread, ptswrite, /*5*/
84 ptyioctl, ptsstop, nullreset, ptydevtotty,/* ttyp */
84 ttselect, nommap, NULL, "pts", NULL, -1 };
85 ttpoll, nommap, NULL, "pts", NULL, -1 };
85
86static struct cdevsw ptc_cdevsw =
87 { ptcopen, ptcclose, ptcread, ptcwrite, /*6*/
88 ptyioctl, nullstop, nullreset, ptydevtotty,/* ptyp */
86
87static struct cdevsw ptc_cdevsw =
88 { ptcopen, ptcclose, ptcread, ptcwrite, /*6*/
89 ptyioctl, nullstop, nullreset, ptydevtotty,/* ptyp */
89 ptcselect, nommap, NULL, "ptc", NULL, -1 };
90 ptcpoll, nommap, NULL, "ptc", NULL, -1 };
90
91
92#if NPTY == 1
93#undef NPTY
94#define NPTY 32 /* crude XXX */
95#warning You have only one pty defined, redefining to 32.
96#endif
97

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

454 if (flush & FREAD)
455 flag |= FWRITE;
456 if (flush & FWRITE)
457 flag |= FREAD;
458 ptcwakeup(tp, flag);
459}
460
461static int
91
92
93#if NPTY == 1
94#undef NPTY
95#define NPTY 32 /* crude XXX */
96#warning You have only one pty defined, redefining to 32.
97#endif
98

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

455 if (flush & FREAD)
456 flag |= FWRITE;
457 if (flush & FWRITE)
458 flag |= FREAD;
459 ptcwakeup(tp, flag);
460}
461
462static int
462ptcselect(dev, rw, p)
463ptcpoll(dev, events, p)
463 dev_t dev;
464 dev_t dev;
464 int rw;
465 int events;
465 struct proc *p;
466{
467 register struct tty *tp = &pt_tty[minor(dev)];
468 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
466 struct proc *p;
467{
468 register struct tty *tp = &pt_tty[minor(dev)];
469 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
470 int revents = 0;
469 int s;
470
471 if ((tp->t_state & TS_CONNECTED) == 0)
471 int s;
472
473 if ((tp->t_state & TS_CONNECTED) == 0)
472 return (1);
473 switch (rw) {
474 return (seltrue(dev, events, p) | POLLHUP);
474
475
475 case FREAD:
476 /*
477 * Need to block timeouts (ttrstart).
478 */
479 s = spltty();
480 if ((tp->t_state&TS_ISOPEN) &&
481 tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) {
482 splx(s);
483 return (1);
484 }
485 splx(s);
486 /* FALLTHROUGH */
476 /*
477 * Need to block timeouts (ttrstart).
478 */
479 s = spltty();
487
480
488 case 0: /* exceptional */
489 if ((tp->t_state&TS_ISOPEN) &&
490 ((pti->pt_flags&PF_PKT && pti->pt_send) ||
491 (pti->pt_flags&PF_UCNTL && pti->pt_ucntl)))
492 return (1);
493 selrecord(p, &pti->pt_selr);
494 break;
481 if (events & (POLLIN | POLLRDNORM))
482 if ((tp->t_state & TS_ISOPEN) &&
483 ((tp->t_outq.c_cc && (tp->t_state & TS_TTSTOP) == 0) ||
484 ((pti->pt_flags & PF_PKT) && pti->pt_send) ||
485 ((pti->pt_flags & PF_UCNTL) && pti->pt_ucntl)))
486 revents |= events & (POLLIN | POLLRDNORM);
495
487
488 if (events & (POLLOUT | POLLWRNORM))
489 if (tp->t_state & TS_ISOPEN &&
490 ((pti->pt_flags & PF_REMOTE) ?
491 (tp->t_canq.c_cc == 0) :
492 ((tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG - 2) ||
493 (tp->t_canq.c_cc == 0 && (tp->t_iflag & ICANON)))))
494 revents |= events & (POLLOUT | POLLWRNORM);
496
495
497 case FWRITE:
498 if (tp->t_state&TS_ISOPEN) {
499 if (pti->pt_flags & PF_REMOTE) {
500 if (tp->t_canq.c_cc == 0)
501 return (1);
502 } else {
503 if (tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG-2)
504 return (1);
505 if (tp->t_canq.c_cc == 0 && (tp->t_iflag&ICANON))
506 return (1);
507 }
508 }
509 selrecord(p, &pti->pt_selw);
510 break;
496 if (events & POLLHUP)
497 if ((tp->t_state & TS_CARR_ON) == 0)
498 revents |= POLLHUP;
511
499
500 if (revents == 0) {
501 if (events & (POLLIN | POLLRDNORM))
502 selrecord(p, &pti->pt_selr);
503
504 if (events & (POLLOUT | POLLWRNORM))
505 selrecord(p, &pti->pt_selw);
512 }
506 }
513 return (0);
507 splx(s);
508
509 return (revents);
514}
515
516static int
517ptcwrite(dev, uio, flag)
518 dev_t dev;
519 register struct uio *uio;
520 int flag;
521{

--- 307 unchanged lines hidden ---
510}
511
512static int
513ptcwrite(dev, uio, flag)
514 dev_t dev;
515 register struct uio *uio;
516 int flag;
517{

--- 307 unchanged lines hidden ---