The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/tty_tty.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $OpenBSD: tty_tty.c,v 1.10 2007/03/15 10:22:30 art Exp $        */
    2 /*      $NetBSD: tty_tty.c,v 1.13 1996/03/30 22:24:46 christos Exp $    */
    3 
    4 /*-
    5  * Copyright (c) 1982, 1986, 1991, 1993
    6  *      The Regents of the University of California.  All rights reserved.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 3. Neither the name of the University nor the names of its contributors
   17  *    may be used to endorse or promote products derived from this software
   18  *    without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   30  * SUCH DAMAGE.
   31  *
   32  *      @(#)tty_tty.c   8.2 (Berkeley) 9/23/93
   33  */
   34 
   35 /*
   36  * Indirect driver for controlling tty.
   37  */
   38 #include <sys/param.h>
   39 #include <sys/systm.h>
   40 #include <sys/ioctl.h>
   41 #include <sys/proc.h>
   42 #include <sys/tty.h>
   43 #include <sys/vnode.h>
   44 #include <sys/file.h>
   45 #include <sys/conf.h>
   46 
   47 
   48 #define cttyvp(p) ((p)->p_flag & P_CONTROLT ? (p)->p_session->s_ttyvp : NULL)
   49 
   50 /*ARGSUSED*/
   51 int
   52 cttyopen(dev_t dev, int flag, int mode, struct proc *p)
   53 {
   54         struct vnode *ttyvp = cttyvp(p);
   55         int error;
   56 
   57         if (ttyvp == NULL)
   58                 return (ENXIO);
   59         vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, p);
   60 #ifdef PARANOID
   61         /*
   62          * Since group is tty and mode is 620 on most terminal lines
   63          * and since sessions protect terminals from processes outside
   64          * your session, this check is probably no longer necessary.
   65          * Since it inhibits setuid root programs that later switch 
   66          * to another user from accessing /dev/tty, we have decided
   67          * to delete this test. (mckusick 5/93)
   68          */
   69         error = VOP_ACCESS(ttyvp,
   70           (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p);
   71         if (!error)
   72 #endif /* PARANOID */
   73                 error = VOP_OPEN(ttyvp, flag, NOCRED, p);
   74         VOP_UNLOCK(ttyvp, 0, p);
   75         return (error);
   76 }
   77 
   78 /*ARGSUSED*/
   79 int
   80 cttyread(dev_t dev, struct uio *uio, int flag)
   81 {
   82         struct proc *p = uio->uio_procp;
   83         struct vnode *ttyvp = cttyvp(uio->uio_procp);
   84         int error;
   85 
   86         if (ttyvp == NULL)
   87                 return (EIO);
   88         vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, p);
   89         error = VOP_READ(ttyvp, uio, flag, NOCRED);
   90         VOP_UNLOCK(ttyvp, 0, p);
   91         return (error);
   92 }
   93 
   94 /*ARGSUSED*/
   95 int
   96 cttywrite(dev_t dev, struct uio *uio, int flag)
   97 {
   98         struct proc *p = uio->uio_procp;
   99         struct vnode *ttyvp = cttyvp(uio->uio_procp);
  100         int error;
  101 
  102         if (ttyvp == NULL)
  103                 return (EIO);
  104         vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, p);
  105         error = VOP_WRITE(ttyvp, uio, flag, NOCRED);
  106         VOP_UNLOCK(ttyvp, 0, p);
  107         return (error);
  108 }
  109 
  110 /*ARGSUSED*/
  111 int
  112 cttyioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
  113 {
  114         struct vnode *ttyvp = cttyvp(p);
  115 
  116         if (ttyvp == NULL)
  117                 return (EIO);
  118         if (cmd == TIOCSCTTY)           /* XXX */
  119                 return (EINVAL);
  120         if (cmd == TIOCNOTTY) {
  121                 if (!SESS_LEADER(p)) {
  122                         atomic_clearbits_int(&p->p_flag, P_CONTROLT);
  123                         return (0);
  124                 } else
  125                         return (EINVAL);
  126         }
  127         return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p));
  128 }
  129 
  130 /*ARGSUSED*/
  131 int
  132 cttypoll(dev_t dev, int events, struct proc *p)
  133 {
  134         struct vnode *ttyvp = cttyvp(p);
  135 
  136         if (ttyvp == NULL)      /* try operation to get EOF/failure */
  137                 return (seltrue(dev, events, p));
  138         return (VOP_POLL(ttyvp, events, p));
  139 }

Cache object: 261d0de2d0c888f1dc86963104755f5e


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.