summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty_tty.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2001-05-14 08:22:56 +0000
committerphk <phk@FreeBSD.org>2001-05-14 08:22:56 +0000
commit112e6fb13811bdd16ea648860e5006495d1b402a (patch)
tree699514888b435197eae0e0bc26223547723de2b0 /sys/kern/tty_tty.c
parent4fe46b461d3e3ef69656d2e1a1f2fd6a072b8d56 (diff)
downloadFreeBSD-src-112e6fb13811bdd16ea648860e5006495d1b402a.zip
FreeBSD-src-112e6fb13811bdd16ea648860e5006495d1b402a.tar.gz
Use the new ability to avoid practically all the gunk in this file.
When people access /dev/tty, locate their controlling tty and return the dev_t of it to them. This basically makes /dev/tty act like a variant symlink sort of thing which is much simpler than all the mucking about with vnodes.
Diffstat (limited to 'sys/kern/tty_tty.c')
-rw-r--r--sys/kern/tty_tty.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/sys/kern/tty_tty.c b/sys/kern/tty_tty.c
index d1d9705..8be458c 100644
--- a/sys/kern/tty_tty.c
+++ b/sys/kern/tty_tty.c
@@ -54,8 +54,8 @@ static d_ioctl_t cttyioctl;
static d_poll_t cttypoll;
#define CDEV_MAJOR 1
-/* Don't make this static, since fdesc_vnops uses it. */
-struct cdevsw ctty_cdevsw = {
+
+static struct cdevsw ctty_cdevsw = {
/* open */ cttyopen,
/* close */ nullclose,
/* read */ cttyread,
@@ -86,20 +86,7 @@ cttyopen(dev, flag, mode, p)
if (ttyvp == NULL)
return (ENXIO);
vn_lock(ttyvp, LK_EXCLUSIVE | LK_RETRY, p);
-#ifdef PARANOID
- /*
- * Since group is tty and mode is 620 on most terminal lines
- * and since sessions protect terminals from processes outside
- * your session, this check is probably no longer necessary.
- * Since it inhibits setuid root programs that later switch
- * to another user from accessing /dev/tty, we have decided
- * to delete this test. (mckusick 5/93)
- */
- error = VOP_ACCESS(ttyvp,
- (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p);
- if (!error)
-#endif /* PARANOID */
- error = VOP_OPEN(ttyvp, flag, NOCRED, p);
+ error = VOP_OPEN(ttyvp, flag, NOCRED, p);
VOP_UNLOCK(ttyvp, 0, p);
return (error);
}
@@ -188,13 +175,35 @@ cttypoll(dev, events, p)
return (VOP_POLL(ttyvp, events, p->p_ucred, p));
}
+static void ctty_clone __P((void *arg, char *name, int namelen, dev_t *dev));
+
+static void
+ctty_clone(void *arg, char *name, int namelen, dev_t *dev)
+{
+ struct vnode *vp;
+
+ if (*dev != NODEV)
+ return;
+ if (strcmp(name, "tty"))
+ return;
+ vp = cttyvp(curproc);
+ if (vp == NULL)
+ return;
+ *dev = vp->v_rdev;
+}
+
+
static void ctty_drvinit __P((void *unused));
static void
ctty_drvinit(unused)
void *unused;
{
- make_dev(&ctty_cdevsw, 0, 0, 0, 0666, "tty");
+ if (devfs_present) {
+ EVENTHANDLER_REGISTER(dev_clone, ctty_clone, 0, 1000);
+ } else {
+ make_dev(&ctty_cdevsw, 0, 0, 0, 0666, "tty");
+ }
}
SYSINIT(cttydev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,ctty_drvinit,NULL)
OpenPOWER on IntegriCloud