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 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> |
46#include <sys/mutex.h> 47#include <sys/sx.h> |
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{ |
85 struct vnode *ttyvp; |
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 |
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; |
110 register struct vnode *ttyvp; |
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 |
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; |
135 struct vnode *ttyvp; |
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 |
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{ |
167 struct vnode *ttyvp; 168 int error; |
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 |
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) { |
181 PROC_LOCK(td->td_proc); 182 SESS_LOCK(td->td_proc->p_session); 183 error = 0; 184 if (!SESS_LEADER(td->td_proc)) |
185 td->td_proc->p_flag &= ~P_CONTROLT; |
186 else 187 error = EINVAL; 188 SESS_UNLOCK(td->td_proc->p_session); 189 PROC_UNLOCK(td->td_proc); 190 return (error); |
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{ |
202 struct vnode *ttyvp; |
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 |
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 --- |