Deleted Added
full compact
tty.c (29041) tty.c (29354)
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

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

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)tty.c 8.8 (Berkeley) 1/21/94
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

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

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)tty.c 8.8 (Berkeley) 1/21/94
39 * $Id: tty.c,v 1.94 1997/03/24 12:02:59 bde Exp $
39 * $Id: tty.c,v 1.95 1997/09/02 20:05:54 bde Exp $
40 */
41
42/*-
43 * TODO:
44 * o Fix races for sending the start char in ttyflush().
45 * o Handle inter-byte timeout for "MIN > 0, TIME > 0" in ttyselect().
46 * With luck, there will be MIN chars before select() returns().
47 * o Handle CLOCAL consistently for ptys. Perhaps disallow setting it.

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

78#endif
79#include <sys/proc.h>
80#define TTYDEFCHARS
81#include <sys/tty.h>
82#undef TTYDEFCHARS
83#include <sys/fcntl.h>
84#include <sys/conf.h>
85#include <sys/dkstat.h>
40 */
41
42/*-
43 * TODO:
44 * o Fix races for sending the start char in ttyflush().
45 * o Handle inter-byte timeout for "MIN > 0, TIME > 0" in ttyselect().
46 * With luck, there will be MIN chars before select() returns().
47 * o Handle CLOCAL consistently for ptys. Perhaps disallow setting it.

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

78#endif
79#include <sys/proc.h>
80#define TTYDEFCHARS
81#include <sys/tty.h>
82#undef TTYDEFCHARS
83#include <sys/fcntl.h>
84#include <sys/conf.h>
85#include <sys/dkstat.h>
86#include <sys/poll.h>
86#include <sys/kernel.h>
87#include <sys/vnode.h>
88#include <sys/signalvar.h>
89#include <sys/resourcevar.h>
90#include <sys/malloc.h>
91#if NSNP > 0
92#include <sys/snoop.h>
93#endif

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

1026#else
1027 return (-1);
1028#endif
1029 }
1030 return (0);
1031}
1032
1033int
87#include <sys/kernel.h>
88#include <sys/vnode.h>
89#include <sys/signalvar.h>
90#include <sys/resourcevar.h>
91#include <sys/malloc.h>
92#if NSNP > 0
93#include <sys/snoop.h>
94#endif

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

1027#else
1028 return (-1);
1029#endif
1030 }
1031 return (0);
1032}
1033
1034int
1034ttyselect(tp, rw, p)
1035ttypoll(tp, events, p)
1035 struct tty *tp;
1036 struct tty *tp;
1036 int rw;
1037 int events;
1037 struct proc *p;
1038{
1039 int s;
1038 struct proc *p;
1039{
1040 int s;
1041 int revents = 0;
1040
1042
1041 if (tp == NULL)
1042 return (ENXIO);
1043 if (tp == NULL) /* XXX used to return ENXIO, but that means true! */
1044 return ((events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM))
1045 | POLLHUP);
1043
1044 s = spltty();
1046
1047 s = spltty();
1045 switch (rw) {
1046 case FREAD:
1048 if (events & (POLLIN | POLLRDNORM))
1047 if (ttnread(tp) > 0 || ISSET(tp->t_state, TS_ZOMBIE))
1049 if (ttnread(tp) > 0 || ISSET(tp->t_state, TS_ZOMBIE))
1048 goto win;
1049 selrecord(p, &tp->t_rsel);
1050 break;
1051 case FWRITE:
1050 revents |= events & (POLLIN | POLLRDNORM);
1051 else
1052 selrecord(p, &tp->t_rsel);
1053
1054 if (events & (POLLOUT | POLLWRNORM))
1052 if ((tp->t_outq.c_cc <= tp->t_lowat &&
1053 ISSET(tp->t_state, TS_CONNECTED))
1055 if ((tp->t_outq.c_cc <= tp->t_lowat &&
1056 ISSET(tp->t_state, TS_CONNECTED))
1054 || ISSET(tp->t_state, TS_ZOMBIE)) {
1055win: splx(s);
1056 return (1);
1057 }
1058 selrecord(p, &tp->t_wsel);
1059 break;
1060 }
1057 || ISSET(tp->t_state, TS_ZOMBIE))
1058 revents |= events & (POLLOUT | POLLWRNORM);
1059 else
1060 selrecord(p, &tp->t_wsel);
1061 splx(s);
1061 splx(s);
1062 return (0);
1062 return (revents);
1063}
1064
1065/*
1066 * This is a wrapper for compatibility with the select vector used by
1067 * cdevsw. It relies on a proper xxxdevtotty routine.
1068 */
1069int
1063}
1064
1065/*
1066 * This is a wrapper for compatibility with the select vector used by
1067 * cdevsw. It relies on a proper xxxdevtotty routine.
1068 */
1069int
1070ttselect(dev, rw, p)
1070ttpoll(dev, events, p)
1071 dev_t dev;
1071 dev_t dev;
1072 int rw;
1072 int events;
1073 struct proc *p;
1074{
1073 struct proc *p;
1074{
1075 return ttyselect((*cdevsw[major(dev)]->d_devtotty)(dev), rw, p);
1075 return ttypoll((*cdevsw[major(dev)]->d_devtotty)(dev), events, p);
1076}
1077
1078/*
1079 * Must be called at spltty().
1080 */
1081static int
1082ttnread(tp)
1083 struct tty *tp;

--- 1291 unchanged lines hidden ---
1076}
1077
1078/*
1079 * Must be called at spltty().
1080 */
1081static int
1082ttnread(tp)
1083 struct tty *tp;

--- 1291 unchanged lines hidden ---