Date: Sun, 6 Sep 2009 10:27:45 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r196886 - in head: share/man/man4 sys/dev/pty sys/kern sys/sys Message-ID: <200909061027.n86ARjvr080188@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ed Date: Sun Sep 6 10:27:45 2009 New Revision: 196886 URL: http://svn.freebsd.org/changeset/base/196886 Log: Move ptmx into pty(4). Now that pty(4) is a loadable kernel module, I'd better move /dev/ptmx in there as well. This means that pty(4) now provides almost all pseudo-terminal compatibility code. This means it's very easy to test whether applications use the proper library interfaces when allocating pseudo-terminals (namely posix_openpt and openpty). Modified: head/share/man/man4/pts.4 head/share/man/man4/pty.4 head/sys/dev/pty/pty.c head/sys/kern/tty_pts.c head/sys/sys/tty.h Modified: head/share/man/man4/pts.4 ============================================================================== --- head/share/man/man4/pts.4 Sun Sep 6 09:59:02 2009 (r196885) +++ head/share/man/man4/pts.4 Sun Sep 6 10:27:45 2009 (r196886) @@ -147,15 +147,6 @@ The files used by this pseudo-terminals implementation are: .Pp .Bl -tag -width ".Pa /dev/pts/[num]" -.It Pa /dev/ptmx -Control device, returns a file descriptor to a new master -pseudo-terminal when opened. -This device should not be opened directly. -It's only available for binary compatibility. -New devices should only be allocated with -.Xr posix_openpt 2 -and -.Xr openpty 3 . .It Pa /dev/pts/[num] Pseudo-terminal slave devices. .El Modified: head/share/man/man4/pty.4 ============================================================================== --- head/share/man/man4/pty.4 Sun Sep 6 09:59:02 2009 (r196885) +++ head/share/man/man4/pty.4 Sun Sep 6 10:27:45 2009 (r196886) @@ -32,7 +32,7 @@ .Os .Sh NAME .Nm pty -.Nd BSD-style compatibility pseudo-terminal driver +.Nd BSD-style and System V-style compatibility pseudo-terminal driver .Sh SYNOPSIS .Cd "device pty" .Sh DESCRIPTION @@ -48,6 +48,12 @@ driver. A device node for this terminal shall be created, which has the name .Pa /dev/ttyXX . .Pp +The +.Nm +driver also provides a cloning System V +.Pa /dev/ptmx +device. +.Pp New code should not try to allocate pseudo-terminals using this interface. It is only provided for compatibility with older C libraries @@ -63,6 +69,9 @@ device names: Pseudo-terminal master devices. .It Pa /dev/tty[l-sL-S][0-9a-v] Pseudo-terminal slave devices. +.It Pa /dev/ptmx +Control device, returns a file descriptor to a new master +pseudo-terminal when opened. .El .Sh DIAGNOSTICS None. @@ -75,7 +84,7 @@ A pseudo-terminal driver appeared in .Bx 4.2 . .Sh BUGS -Unlike previous implementations, the master slave device nodes are +Unlike previous implementations, the master and slave device nodes are destroyed when the PTY becomes unused. A call to .Xr stat 2 Modified: head/sys/dev/pty/pty.c ============================================================================== --- head/sys/dev/pty/pty.c Sun Sep 6 09:59:02 2009 (r196885) +++ head/sys/dev/pty/pty.c Sun Sep 6 10:27:45 2009 (r196886) @@ -47,6 +47,9 @@ __FBSDID("$FreeBSD$"); * the pts(4) driver. We just call into pts(4) to create the actual PTY. * To make sure we don't use the same PTY multiple times, we abuse * si_drv1 inside the cdev to mark whether the PTY is in use. + * + * It also implements a /dev/ptmx device node, which is useful for Linux + * binary emulation. */ static unsigned int pty_warningcnt = 1; @@ -119,12 +122,27 @@ pty_clone(void *arg, struct ucred *cr, c } static int +ptmx_fdopen(struct cdev *dev __unused, int fflags, struct thread *td, + struct file *fp) +{ + + return (pts_alloc(fflags & (FREAD|FWRITE), td, fp)); +} + +static struct cdevsw ptmx_cdevsw = { + .d_version = D_VERSION, + .d_fdopen = ptmx_fdopen, + .d_name = "ptmx", +}; + +static int pty_modevent(module_t mod, int type, void *data) { switch(type) { case MOD_LOAD: EVENTHANDLER_REGISTER(dev_clone, pty_clone, 0, 1000); + make_dev(&ptmx_cdevsw, 0, UID_ROOT, GID_WHEEL, 0666, "ptmx"); break; case MOD_SHUTDOWN: break; Modified: head/sys/kern/tty_pts.c ============================================================================== --- head/sys/kern/tty_pts.c Sun Sep 6 09:59:02 2009 (r196885) +++ head/sys/kern/tty_pts.c Sun Sep 6 10:27:45 2009 (r196886) @@ -32,7 +32,7 @@ __FBSDID("$FreeBSD$"); /* Add compatibility bits for FreeBSD. */ #define PTS_COMPAT -/* Add /dev/ptyXX compat bits. */ +/* Add pty(4) compat bits. */ #define PTS_EXTERNAL /* Add bits to make Linux binaries work. */ #define PTS_LINUX @@ -694,7 +694,10 @@ static struct ttydevsw pts_class = { .tsw_free = ptsdrv_free, }; -static int +#ifndef PTS_EXTERNAL +static +#endif /* !PTS_EXTERNAL */ +int pts_alloc(int fflags, struct thread *td, struct file *fp) { int unit, ok; @@ -815,29 +818,11 @@ posix_openpt(struct thread *td, struct p return (0); } -#if defined(PTS_COMPAT) || defined(PTS_LINUX) -static int -ptmx_fdopen(struct cdev *dev, int fflags, struct thread *td, struct file *fp) -{ - - return (pts_alloc(fflags & (FREAD|FWRITE), td, fp)); -} - -static struct cdevsw ptmx_cdevsw = { - .d_version = D_VERSION, - .d_fdopen = ptmx_fdopen, - .d_name = "ptmx", -}; -#endif /* PTS_COMPAT || PTS_LINUX */ - static void pts_init(void *unused) { pts_pool = new_unrhdr(0, INT_MAX, NULL); -#if defined(PTS_COMPAT) || defined(PTS_LINUX) - make_dev(&ptmx_cdevsw, 0, UID_ROOT, GID_WHEEL, 0666, "ptmx"); -#endif /* PTS_COMPAT || PTS_LINUX */ } SYSINIT(pts, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, pts_init, NULL); Modified: head/sys/sys/tty.h ============================================================================== --- head/sys/sys/tty.h Sun Sep 6 09:59:02 2009 (r196885) +++ head/sys/sys/tty.h Sun Sep 6 10:27:45 2009 (r196886) @@ -202,6 +202,7 @@ void tty_info(struct tty *tp); void ttyconsdev_select(const char *name); /* Pseudo-terminal hooks. */ +int pts_alloc(int fflags, struct thread *td, struct file *fp); int pts_alloc_external(int fd, struct thread *td, struct file *fp, struct cdev *dev, const char *name);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200909061027.n86ARjvr080188>