|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved */ ! 26: /*- ! 27: * Copyright (c) 1982, 1986, 1991, 1993, 1995 ! 28: * The Regents of the University of California. All rights reserved. ! 29: * ! 30: * Redistribution and use in source and binary forms, with or without ! 31: * modification, are permitted provided that the following conditions ! 32: * are met: ! 33: * 1. Redistributions of source code must retain the above copyright ! 34: * notice, this list of conditions and the following disclaimer. ! 35: * 2. Redistributions in binary form must reproduce the above copyright ! 36: * notice, this list of conditions and the following disclaimer in the ! 37: * documentation and/or other materials provided with the distribution. ! 38: * 3. All advertising materials mentioning features or use of this software ! 39: * must display the following acknowledgement: ! 40: * This product includes software developed by the University of ! 41: * California, Berkeley and its contributors. ! 42: * 4. Neither the name of the University nor the names of its contributors ! 43: * may be used to endorse or promote products derived from this software ! 44: * without specific prior written permission. ! 45: * ! 46: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 47: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 48: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 49: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 50: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 51: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 52: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 53: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 54: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 55: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 56: * SUCH DAMAGE. ! 57: * ! 58: * @(#)tty_tty.c 8.4 (Berkeley) 5/14/95 ! 59: */ ! 60: ! 61: /* ! 62: * Indirect driver for controlling tty. ! 63: */ ! 64: #include <sys/param.h> ! 65: #include <sys/systm.h> ! 66: #include <sys/conf.h> ! 67: #include <sys/ioctl.h> ! 68: #include <sys/proc.h> ! 69: #include <sys/tty.h> ! 70: #include <sys/vnode.h> ! 71: #include <sys/file.h> ! 72: #ifndef NeXT ! 73: #include <sys/kernel.h> ! 74: #ifdef DEVFS ! 75: #include <sys/devfsext.h> ! 76: #endif /*DEVFS*/ ! 77: ! 78: static d_open_t cttyopen; ! 79: static d_read_t cttyread; ! 80: static d_write_t cttywrite; ! 81: static d_ioctl_t cttyioctl; ! 82: static d_select_t cttyselect; ! 83: ! 84: #define CDEV_MAJOR 1 ! 85: /* Don't make static, fdesc_vnops uses this. */ ! 86: struct cdevsw ctty_cdevsw = ! 87: { cttyopen, nullclose, cttyread, cttywrite, /*1*/ ! 88: cttyioctl, nullstop, nullreset, nodevtotty,/* tty */ ! 89: cttyselect, nommap, NULL, "ctty", NULL, -1 }; ! 90: ! 91: #endif /* !NeXT */ ! 92: ! 93: #define cttyvp(p) ((p)->p_flag & P_CONTROLT ? (p)->p_session->s_ttyvp : NULL) ! 94: ! 95: /*ARGSUSED*/ ! 96: int ! 97: cttyopen(dev, flag, mode, p) ! 98: dev_t dev; ! 99: int flag, mode; ! 100: struct proc *p; ! 101: { ! 102: struct vnode *ttyvp = cttyvp(p); ! 103: int error; ! 104: ! 105: if (ttyvp == NULL) ! 106: return (ENXIO); ! 107: #ifndef NeXT ! 108: VOP_LOCK(ttyvp); ! 109: #else ! 110: /* ! 111: * This is the only place that NeXT Guarding has been used for ! 112: * VOP_.*LOCK style calls. Note all of the other diffs should ! 113: * use the three paramater lock/unlock. ! 114: */ ! 115: vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, p); ! 116: #endif ! 117: ! 118: #ifdef PARANOID ! 119: /* ! 120: * Since group is tty and mode is 620 on most terminal lines ! 121: * and since sessions protect terminals from processes outside ! 122: * your session, this check is probably no longer necessary. ! 123: * Since it inhibits setuid root programs that later switch ! 124: * to another user from accessing /dev/tty, we have decided ! 125: * to delete this test. (mckusick 5/93) ! 126: */ ! 127: error = VOP_ACCESS(ttyvp, ! 128: (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p); ! 129: if (!error) ! 130: #endif /* PARANOID */ ! 131: error = VOP_OPEN(ttyvp, flag, NOCRED, p); ! 132: VOP_UNLOCK(ttyvp, 0, p); ! 133: return (error); ! 134: } ! 135: ! 136: /*ARGSUSED*/ ! 137: int ! 138: cttyread(dev, uio, flag) ! 139: dev_t dev; ! 140: struct uio *uio; ! 141: int flag; ! 142: { ! 143: struct proc *p = uio->uio_procp; ! 144: register struct vnode *ttyvp = cttyvp(uio->uio_procp); ! 145: int error; ! 146: ! 147: if (ttyvp == NULL) ! 148: return (EIO); ! 149: vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, p); ! 150: error = VOP_READ(ttyvp, uio, flag, NOCRED); ! 151: VOP_UNLOCK(ttyvp, 0, p); ! 152: return (error); ! 153: } ! 154: ! 155: /*ARGSUSED*/ ! 156: int ! 157: cttywrite(dev, uio, flag) ! 158: dev_t dev; ! 159: struct uio *uio; ! 160: int flag; ! 161: { ! 162: struct proc *p = uio->uio_procp; ! 163: register struct vnode *ttyvp = cttyvp(uio->uio_procp); ! 164: int error; ! 165: ! 166: if (ttyvp == NULL) ! 167: return (EIO); ! 168: vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, p); ! 169: error = VOP_WRITE(ttyvp, uio, flag, NOCRED); ! 170: VOP_UNLOCK(ttyvp, 0, p); ! 171: return (error); ! 172: } ! 173: ! 174: /*ARGSUSED*/ ! 175: #ifndef NeXT ! 176: static int ! 177: cttyioctl(dev, cmd, addr, flag, p) ! 178: dev_t dev; ! 179: int cmd; ! 180: caddr_t addr; ! 181: int flag; ! 182: struct proc *p; ! 183: #else ! 184: int ! 185: cttyioctl(dev, cmd, addr, flag, p) ! 186: dev_t dev; ! 187: u_long cmd; ! 188: caddr_t addr; ! 189: int flag; ! 190: struct proc *p; ! 191: #endif /* !NeXT */ ! 192: { ! 193: struct vnode *ttyvp = cttyvp(p); ! 194: ! 195: if (ttyvp == NULL) ! 196: return (EIO); ! 197: if (cmd == TIOCSCTTY) /* don't allow controlling tty to be set */ ! 198: return EINVAL; /* to controlling tty -- infinite recursion */ ! 199: if (cmd == TIOCNOTTY) { ! 200: if (!SESS_LEADER(p)) { ! 201: p->p_flag &= ~P_CONTROLT; ! 202: return (0); ! 203: } else ! 204: return (EINVAL); ! 205: } ! 206: return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p)); ! 207: } ! 208: ! 209: /*ARGSUSED*/ ! 210: int ! 211: cttyselect(dev, flag, p) ! 212: dev_t dev; ! 213: int flag; ! 214: struct proc *p; ! 215: { ! 216: struct vnode *ttyvp = cttyvp(p); ! 217: ! 218: if (ttyvp == NULL) ! 219: return (1); /* try operation to get EOF/failure */ ! 220: return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p)); ! 221: } ! 222: ! 223: #ifndef NeXT ! 224: static ctty_devsw_installed = 0; ! 225: #ifdef DEVFS ! 226: static void *ctty_devfs_token; ! 227: #endif ! 228: ! 229: static void ! 230: ctty_drvinit(void *unused) ! 231: { ! 232: dev_t dev; ! 233: ! 234: if( ! ctty_devsw_installed ) { ! 235: dev = makedev(CDEV_MAJOR,0); ! 236: cdevsw_add(&dev,&ctty_cdevsw,NULL); ! 237: ctty_devsw_installed = 1; ! 238: #ifdef DEVFS ! 239: ctty_devfs_token = ! 240: devfs_add_devswf(&ctty_cdevsw, 0, DV_CHR, 0, 0, ! 241: 0666, "tty"); ! 242: #endif ! 243: } ! 244: } ! 245: ! 246: SYSINIT(cttydev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,ctty_drvinit,NULL) ! 247: ! 248: ! 249: #endif /* !NeXT */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.