Commit | Line | Data |
---|---|---|
f406ae69 | 1 | /*- |
ec54f0cc KB |
2 | * Copyright (c) 1982, 1986, 1991, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
f406ae69 KB |
4 | * |
5 | * %sccs.include.redist.c% | |
da7c5cc6 | 6 | * |
ec54f0cc | 7 | * @(#)tty_tty.c 8.1 (Berkeley) %G% |
da7c5cc6 | 8 | */ |
63c57592 BJ |
9 | |
10 | /* | |
964bcfb1 | 11 | * Indirect driver for controlling tty. |
63c57592 | 12 | */ |
38a01dbe KB |
13 | #include <sys/param.h> |
14 | #include <sys/systm.h> | |
15 | #include <sys/conf.h> | |
16 | #include <sys/ioctl.h> | |
17 | #include <sys/proc.h> | |
18 | #include <sys/tty.h> | |
19 | #include <sys/vnode.h> | |
20 | #include <sys/file.h> | |
63c57592 | 21 | |
232c0273 MT |
22 | #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL) |
23 | ||
63c57592 | 24 | /*ARGSUSED*/ |
431fd894 | 25 | cttyopen(dev, flag, mode, p) |
830bbc16 | 26 | dev_t dev; |
431fd894 MK |
27 | int flag, mode; |
28 | struct proc *p; | |
63c57592 | 29 | { |
3789a403 | 30 | struct vnode *ttyvp = cttyvp(p); |
232c0273 | 31 | int error; |
63c57592 | 32 | |
232c0273 | 33 | if (ttyvp == NULL) |
830bbc16 | 34 | return (ENXIO); |
29e3ce7f | 35 | VOP_LOCK(ttyvp); |
952694af KM |
36 | #ifdef PARANOID |
37 | /* | |
7210ce77 | 38 | * Since group is tty and mode is 620 on most terminal lines |
952694af KM |
39 | * and since sessions protect terminals from processes outside |
40 | * your session, this check is probably no longer necessary. | |
41 | * Since it inhibits setuid root programs that later switch | |
42 | * to another user from accessing /dev/tty, we have decided | |
7210ce77 | 43 | * to delete this test. (mckusick 5/93) |
952694af | 44 | */ |
29e3ce7f | 45 | error = VOP_ACCESS(ttyvp, |
f254ddb7 | 46 | (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p); |
f21184ce | 47 | if (!error) |
952694af | 48 | #endif /* PARANOID */ |
f21184ce | 49 | error = VOP_OPEN(ttyvp, flag, NOCRED, p); |
29e3ce7f | 50 | VOP_UNLOCK(ttyvp); |
f21184ce | 51 | return (error); |
63c57592 BJ |
52 | } |
53 | ||
54 | /*ARGSUSED*/ | |
758b32dd | 55 | cttyread(dev, uio, flag) |
be3a1208 BJ |
56 | dev_t dev; |
57 | struct uio *uio; | |
3e2a6ec5 | 58 | int flag; |
63c57592 | 59 | { |
758b32dd | 60 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); |
18b87772 | 61 | int error; |
63c57592 | 62 | |
232c0273 | 63 | if (ttyvp == NULL) |
431fd894 | 64 | return (EIO); |
18b87772 KM |
65 | VOP_LOCK(ttyvp); |
66 | error = VOP_READ(ttyvp, uio, flag, NOCRED); | |
67 | VOP_UNLOCK(ttyvp); | |
68 | return (error); | |
63c57592 BJ |
69 | } |
70 | ||
71 | /*ARGSUSED*/ | |
758b32dd | 72 | cttywrite(dev, uio, flag) |
be3a1208 BJ |
73 | dev_t dev; |
74 | struct uio *uio; | |
3e2a6ec5 | 75 | int flag; |
63c57592 | 76 | { |
758b32dd | 77 | register struct vnode *ttyvp = cttyvp(uio->uio_procp); |
18b87772 | 78 | int error; |
63c57592 | 79 | |
232c0273 | 80 | if (ttyvp == NULL) |
431fd894 | 81 | return (EIO); |
18b87772 KM |
82 | VOP_LOCK(ttyvp); |
83 | error = VOP_WRITE(ttyvp, uio, flag, NOCRED); | |
84 | VOP_UNLOCK(ttyvp); | |
85 | return (error); | |
63c57592 BJ |
86 | } |
87 | ||
88 | /*ARGSUSED*/ | |
431fd894 | 89 | cttyioctl(dev, cmd, addr, flag, p) |
35c1dcdb BJ |
90 | dev_t dev; |
91 | int cmd; | |
92 | caddr_t addr; | |
93 | int flag; | |
431fd894 | 94 | struct proc *p; |
63c57592 | 95 | { |
431fd894 | 96 | struct vnode *ttyvp = cttyvp(p); |
63c57592 | 97 | |
232c0273 | 98 | if (ttyvp == NULL) |
431fd894 | 99 | return (EIO); |
9060c89c | 100 | if (cmd == TIOCNOTTY) { |
431fd894 MK |
101 | if (!SESS_LEADER(p)) { |
102 | p->p_flag &= ~SCTTY; | |
232c0273 MT |
103 | return (0); |
104 | } else | |
105 | return (EINVAL); | |
4460d508 | 106 | } |
f254ddb7 | 107 | return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p)); |
63c57592 | 108 | } |
231ed58b | 109 | |
a8d3bf7f | 110 | /*ARGSUSED*/ |
431fd894 | 111 | cttyselect(dev, flag, p) |
a8d3bf7f BJ |
112 | dev_t dev; |
113 | int flag; | |
431fd894 | 114 | struct proc *p; |
231ed58b | 115 | { |
431fd894 | 116 | struct vnode *ttyvp = cttyvp(p); |
231ed58b | 117 | |
232c0273 | 118 | if (ttyvp == NULL) |
620eb66b | 119 | return (1); /* try operation to get EOF/failure */ |
f254ddb7 | 120 | return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p)); |
231ed58b | 121 | } |