tty_tty.c (83366) | tty_tty.c (91140) |
---|---|
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 | 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 $ | 34 * $FreeBSD: head/sys/kern/tty_tty.c 91140 2002-02-23 11:12:57Z tanimura $ |
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> | 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/mutex.h> 47#include <sys/sx.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{ | 48#include <sys/proc.h> 49#include <sys/ttycom.h> 50#include <sys/vnode.h> 51 52static d_open_t cttyopen; 53static d_read_t cttyread; 54static d_write_t cttywrite; 55static d_ioctl_t cttyioctl; --- 21 unchanged lines hidden (view full) --- 77 78/*ARGSUSED*/ 79static int 80cttyopen(dev, flag, mode, td) 81 dev_t dev; 82 int flag, mode; 83 struct thread *td; 84{ |
83 struct vnode *ttyvp = cttyvp(td); | 85 struct vnode *ttyvp; |
84 int error; 85 | 86 int error; 87 |
88 PROC_LOCK(td->td_proc); 89 SESS_LOCK(td->td_proc->p_session); 90 ttyvp = cttyvp(td); 91 SESS_UNLOCK(td->td_proc->p_session); 92 PROC_UNLOCK(td->td_proc); 93 |
|
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; | 94 if (ttyvp == NULL) 95 return (ENXIO); 96 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, td); 97 error = VOP_OPEN(ttyvp, flag, NOCRED, td); 98 VOP_UNLOCK(ttyvp, 0, td); 99 return (error); 100} 101 102/*ARGSUSED*/ 103static int 104cttyread(dev, uio, flag) 105 dev_t dev; 106 struct uio *uio; 107 int flag; 108{ 109 struct thread *td = uio->uio_td; |
102 register struct vnode *ttyvp = cttyvp(td); | 110 register struct vnode *ttyvp; |
103 int error; 104 | 111 int error; 112 |
113 PROC_LOCK(td->td_proc); 114 SESS_LOCK(td->td_proc->p_session); 115 ttyvp = cttyvp(td); 116 SESS_UNLOCK(td->td_proc->p_session); 117 PROC_UNLOCK(td->td_proc); 118 |
|
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; | 119 if (ttyvp == NULL) 120 return (EIO); 121 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, td); 122 error = VOP_READ(ttyvp, uio, flag, NOCRED); 123 VOP_UNLOCK(ttyvp, 0, td); 124 return (error); 125} 126 127/*ARGSUSED*/ 128static int 129cttywrite(dev, uio, flag) 130 dev_t dev; 131 struct uio *uio; 132 int flag; 133{ 134 struct thread *td = uio->uio_td; |
121 struct vnode *ttyvp = cttyvp(uio->uio_td); | 135 struct vnode *ttyvp; |
122 struct mount *mp; 123 int error; 124 | 136 struct mount *mp; 137 int error; 138 |
139 PROC_LOCK(td->td_proc); 140 SESS_LOCK(td->td_proc->p_session); 141 ttyvp = cttyvp(td); 142 SESS_UNLOCK(td->td_proc->p_session); 143 PROC_UNLOCK(td->td_proc); 144 |
|
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{ | 145 if (ttyvp == NULL) 146 return (EIO); 147 mp = NULL; 148 if (ttyvp->v_type != VCHR && 149 (error = vn_start_write(ttyvp, &mp, V_WAIT | PCATCH)) != 0) 150 return (error); 151 vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, td); 152 error = VOP_WRITE(ttyvp, uio, flag, NOCRED); --- 6 unchanged lines hidden (view full) --- 159static int 160cttyioctl(dev, cmd, addr, flag, td) 161 dev_t dev; 162 u_long cmd; 163 caddr_t addr; 164 int flag; 165 struct thread *td; 166{ |
147 struct vnode *ttyvp = cttyvp(td); | 167 struct vnode *ttyvp; 168 int error; |
148 | 169 |
170 PROC_LOCK(td->td_proc); 171 SESS_LOCK(td->td_proc->p_session); 172 ttyvp = cttyvp(td); 173 SESS_UNLOCK(td->td_proc->p_session); 174 PROC_UNLOCK(td->td_proc); 175 |
|
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) { | 176 if (ttyvp == NULL) 177 return (EIO); 178 if (cmd == TIOCSCTTY) /* don't allow controlling tty to be set */ 179 return EINVAL; /* to controlling tty -- infinite recursion */ 180 if (cmd == TIOCNOTTY) { |
154 if (!SESS_LEADER(td->td_proc)) { | 181 PROC_LOCK(td->td_proc); 182 SESS_LOCK(td->td_proc->p_session); 183 error = 0; 184 if (!SESS_LEADER(td->td_proc)) |
155 td->td_proc->p_flag &= ~P_CONTROLT; | 185 td->td_proc->p_flag &= ~P_CONTROLT; |
156 return (0); 157 } else 158 return (EINVAL); | 186 else 187 error = EINVAL; 188 SESS_UNLOCK(td->td_proc->p_session); 189 PROC_UNLOCK(td->td_proc); 190 return (error); |
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{ | 191 } 192 return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, td)); 193} 194 195/*ARGSUSED*/ 196static int 197cttypoll(dev, events, td) 198 dev_t dev; 199 int events; 200 struct thread *td; 201{ |
170 struct vnode *ttyvp = cttyvp(td); | 202 struct vnode *ttyvp; |
171 | 203 |
204 PROC_LOCK(td->td_proc); 205 SESS_LOCK(td->td_proc->p_session); 206 ttyvp = cttyvp(td); 207 SESS_UNLOCK(td->td_proc->p_session); 208 PROC_UNLOCK(td->td_proc); 209 |
|
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 --- | 210 if (ttyvp == NULL) 211 /* try operation to get EOF/failure */ 212 return (seltrue(dev, events, td)); 213 return (VOP_POLL(ttyvp, events, td->td_proc->p_ucred, td)); 214} 215 216static void ctty_clone __P((void *arg, char *name, int namelen, dev_t *dev)); 217 --- 35 unchanged lines hidden --- |