1/*-
2 * Copyright (c) 1982, 1986, 1991, 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_tty.c 8.2 (Berkeley) 9/23/93
34 * $FreeBSD: head/sys/kern/tty_tty.c 83366 2001-09-12 08:38:13Z julian $
35 */
36
37/*
38 * Indirect driver for controlling tty.
39 */
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/conf.h>
44#include <sys/kernel.h>
45#include <sys/lock.h>
46#include <sys/proc.h>
47#include <sys/ttycom.h>
48#include <sys/vnode.h>
49
50static d_open_t cttyopen;
51static d_read_t cttyread;
52static d_write_t cttywrite;
53static d_ioctl_t cttyioctl;
--- 21 unchanged lines hidden (view full) ---
75
76/*ARGSUSED*/
77static int
78cttyopen(dev, flag, mode, td)
79 dev_t dev;
80 int flag, mode;
81 struct thread *td;
82{
83 struct vnode *ttyvp = cttyvp(td);
84 int error;
85
86 if (ttyvp == NULL)
87 return (ENXIO);
88 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, td);
89 error = VOP_OPEN(ttyvp, flag, NOCRED, td);
90 VOP_UNLOCK(ttyvp, 0, td);
91 return (error);
92}
93
94/*ARGSUSED*/
95static int
96cttyread(dev, uio, flag)
97 dev_t dev;
98 struct uio *uio;
99 int flag;
100{
101 struct thread *td = uio->uio_td;
102 register struct vnode *ttyvp = cttyvp(td);
103 int error;
104
105 if (ttyvp == NULL)
106 return (EIO);
107 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, td);
108 error = VOP_READ(ttyvp, uio, flag, NOCRED);
109 VOP_UNLOCK(ttyvp, 0, td);
110 return (error);
111}
112
113/*ARGSUSED*/
114static int
115cttywrite(dev, uio, flag)
116 dev_t dev;
117 struct uio *uio;
118 int flag;
119{
120 struct thread *td = uio->uio_td;
121 struct vnode *ttyvp = cttyvp(uio->uio_td);
122 struct mount *mp;
123 int error;
124
125 if (ttyvp == NULL)
126 return (EIO);
127 mp = NULL;
128 if (ttyvp->v_type != VCHR &&
129 (error = vn_start_write(ttyvp, &mp, V_WAIT | PCATCH)) != 0)
130 return (error);
131 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, td);
132 error = VOP_WRITE(ttyvp, uio, flag, NOCRED);
--- 6 unchanged lines hidden (view full) ---
139static int
140cttyioctl(dev, cmd, addr, flag, td)
141 dev_t dev;
142 u_long cmd;
143 caddr_t addr;
144 int flag;
145 struct thread *td;
146{
147 struct vnode *ttyvp = cttyvp(td);
148
149 if (ttyvp == NULL)
150 return (EIO);
151 if (cmd == TIOCSCTTY) /* don't allow controlling tty to be set */
152 return EINVAL; /* to controlling tty -- infinite recursion */
153 if (cmd == TIOCNOTTY) {
154 if (!SESS_LEADER(td->td_proc)) {
155 td->td_proc->p_flag &= ~P_CONTROLT;
156 return (0);
157 } else
158 return (EINVAL);
159 }
160 return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, td));
161}
162
163/*ARGSUSED*/
164static int
165cttypoll(dev, events, td)
166 dev_t dev;
167 int events;
168 struct thread *td;
169{
170 struct vnode *ttyvp = cttyvp(td);
171
172 if (ttyvp == NULL)
173 /* try operation to get EOF/failure */
174 return (seltrue(dev, events, td));
175 return (VOP_POLL(ttyvp, events, td->td_proc->p_ucred, td));
176}
177
178static void ctty_clone __P((void *arg, char *name, int namelen, dev_t *dev));
179
--- 35 unchanged lines hidden ---
2 * Copyright (c) 1982, 1986, 1991, 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_tty.c 8.2 (Berkeley) 9/23/93
34 * $FreeBSD: head/sys/kern/tty_tty.c 83366 2001-09-12 08:38:13Z julian $
35 */
36
37/*
38 * Indirect driver for controlling tty.
39 */
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/conf.h>
44#include <sys/kernel.h>
45#include <sys/lock.h>
46#include <sys/proc.h>
47#include <sys/ttycom.h>
48#include <sys/vnode.h>
49
50static d_open_t cttyopen;
51static d_read_t cttyread;
52static d_write_t cttywrite;
53static d_ioctl_t cttyioctl;
--- 21 unchanged lines hidden (view full) ---
75
76/*ARGSUSED*/
77static int
78cttyopen(dev, flag, mode, td)
79 dev_t dev;
80 int flag, mode;
81 struct thread *td;
82{
83 struct vnode *ttyvp = cttyvp(td);
84 int error;
85
86 if (ttyvp == NULL)
87 return (ENXIO);
88 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, td);
89 error = VOP_OPEN(ttyvp, flag, NOCRED, td);
90 VOP_UNLOCK(ttyvp, 0, td);
91 return (error);
92}
93
94/*ARGSUSED*/
95static int
96cttyread(dev, uio, flag)
97 dev_t dev;
98 struct uio *uio;
99 int flag;
100{
101 struct thread *td = uio->uio_td;
102 register struct vnode *ttyvp = cttyvp(td);
103 int error;
104
105 if (ttyvp == NULL)
106 return (EIO);
107 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, td);
108 error = VOP_READ(ttyvp, uio, flag, NOCRED);
109 VOP_UNLOCK(ttyvp, 0, td);
110 return (error);
111}
112
113/*ARGSUSED*/
114static int
115cttywrite(dev, uio, flag)
116 dev_t dev;
117 struct uio *uio;
118 int flag;
119{
120 struct thread *td = uio->uio_td;
121 struct vnode *ttyvp = cttyvp(uio->uio_td);
122 struct mount *mp;
123 int error;
124
125 if (ttyvp == NULL)
126 return (EIO);
127 mp = NULL;
128 if (ttyvp->v_type != VCHR &&
129 (error = vn_start_write(ttyvp, &mp, V_WAIT | PCATCH)) != 0)
130 return (error);
131 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, td);
132 error = VOP_WRITE(ttyvp, uio, flag, NOCRED);
--- 6 unchanged lines hidden (view full) ---
139static int
140cttyioctl(dev, cmd, addr, flag, td)
141 dev_t dev;
142 u_long cmd;
143 caddr_t addr;
144 int flag;
145 struct thread *td;
146{
147 struct vnode *ttyvp = cttyvp(td);
148
149 if (ttyvp == NULL)
150 return (EIO);
151 if (cmd == TIOCSCTTY) /* don't allow controlling tty to be set */
152 return EINVAL; /* to controlling tty -- infinite recursion */
153 if (cmd == TIOCNOTTY) {
154 if (!SESS_LEADER(td->td_proc)) {
155 td->td_proc->p_flag &= ~P_CONTROLT;
156 return (0);
157 } else
158 return (EINVAL);
159 }
160 return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, td));
161}
162
163/*ARGSUSED*/
164static int
165cttypoll(dev, events, td)
166 dev_t dev;
167 int events;
168 struct thread *td;
169{
170 struct vnode *ttyvp = cttyvp(td);
171
172 if (ttyvp == NULL)
173 /* try operation to get EOF/failure */
174 return (seltrue(dev, events, td));
175 return (VOP_POLL(ttyvp, events, td->td_proc->p_ucred, td));
176}
177
178static void ctty_clone __P((void *arg, char *name, int namelen, dev_t *dev));
179
--- 35 unchanged lines hidden ---