pty.c (302408) | pty.c (303432) |
---|---|
1/*- 2 * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Portions of this software were developed under sponsorship from Snow 6 * B.V., the Netherlands. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Portions of this software were developed under sponsorship from Snow 6 * B.V., the Netherlands. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: stable/11/sys/dev/pty/pty.c 298337 2016-04-20 04:50:33Z cem $"); | 31__FBSDID("$FreeBSD: stable/11/sys/dev/pty/pty.c 303432 2016-07-28 11:43:25Z kib $"); |
32 33#include <sys/param.h> 34#include <sys/conf.h> 35#include <sys/eventhandler.h> 36#include <sys/fcntl.h> 37#include <sys/kernel.h> 38#include <sys/module.h> 39#include <sys/proc.h> --- 7 unchanged lines hidden (view full) --- 47 * the pts(4) driver. We just call into pts(4) to create the actual PTY. 48 * To make sure we don't use the same PTY multiple times, we abuse 49 * si_drv1 inside the cdev to mark whether the PTY is in use. 50 * 51 * It also implements a /dev/ptmx device node, which is useful for Linux 52 * binary emulation. 53 */ 54 | 32 33#include <sys/param.h> 34#include <sys/conf.h> 35#include <sys/eventhandler.h> 36#include <sys/fcntl.h> 37#include <sys/kernel.h> 38#include <sys/module.h> 39#include <sys/proc.h> --- 7 unchanged lines hidden (view full) --- 47 * the pts(4) driver. We just call into pts(4) to create the actual PTY. 48 * To make sure we don't use the same PTY multiple times, we abuse 49 * si_drv1 inside the cdev to mark whether the PTY is in use. 50 * 51 * It also implements a /dev/ptmx device node, which is useful for Linux 52 * binary emulation. 53 */ 54 |
55static unsigned int pty_warningcnt = 1; | 55static unsigned pty_warningcnt = 1; |
56SYSCTL_UINT(_kern, OID_AUTO, tty_pty_warningcnt, CTLFLAG_RW, | 56SYSCTL_UINT(_kern, OID_AUTO, tty_pty_warningcnt, CTLFLAG_RW, |
57 &pty_warningcnt, 0, 58 "Warnings that will be triggered upon legacy PTY allocation"); | 57 &pty_warningcnt, 0, 58 "Warnings that will be triggered upon legacy PTY allocation"); |
59 60static int 61ptydev_fdopen(struct cdev *dev, int fflags, struct thread *td, struct file *fp) 62{ 63 int error; 64 char name[6]; /* "ttyXX" */ 65 66 if (!atomic_cmpset_ptr((uintptr_t *)&dev->si_drv1, 0, 1)) --- 5 unchanged lines hidden (view full) --- 72 73 error = pts_alloc_external(fflags & (FREAD|FWRITE), td, fp, dev, name); 74 if (error != 0) { 75 destroy_dev_sched(dev); 76 return (error); 77 } 78 79 /* Raise a warning when a legacy PTY has been allocated. */ | 59 60static int 61ptydev_fdopen(struct cdev *dev, int fflags, struct thread *td, struct file *fp) 62{ 63 int error; 64 char name[6]; /* "ttyXX" */ 65 66 if (!atomic_cmpset_ptr((uintptr_t *)&dev->si_drv1, 0, 1)) --- 5 unchanged lines hidden (view full) --- 72 73 error = pts_alloc_external(fflags & (FREAD|FWRITE), td, fp, dev, name); 74 if (error != 0) { 75 destroy_dev_sched(dev); 76 return (error); 77 } 78 79 /* Raise a warning when a legacy PTY has been allocated. */ |
80 if (pty_warningcnt > 0) { 81 pty_warningcnt--; 82 log(LOG_INFO, "pid %d (%s) is using legacy pty devices%s\n", 83 td->td_proc->p_pid, td->td_name, 84 pty_warningcnt ? "" : " - not logging anymore"); 85 } | 80 counted_warning(&pty_warningcnt, "is using legacy pty devices"); |
86 87 return (0); 88} 89 90static struct cdevsw ptydev_cdevsw = { 91 .d_version = D_VERSION, 92 .d_fdopen = ptydev_fdopen, 93 .d_name = "ptydev", --- 76 unchanged lines hidden --- | 81 82 return (0); 83} 84 85static struct cdevsw ptydev_cdevsw = { 86 .d_version = D_VERSION, 87 .d_fdopen = ptydev_fdopen, 88 .d_name = "ptydev", --- 76 unchanged lines hidden --- |