From dc7e7b3e7dbff2636fe6a2d2ae95a757f87a9fbc Mon Sep 17 00:00:00 2001 From: mpi Date: Mon, 8 Jan 2018 11:52:14 +0000 Subject: [PATCH] Translate the TIOCSBRK & TIOCCBRK ioctl(2)s issued on a pty(4) slave to corresponding user mode ioctls. If the master part of the pseudo terminal previously enabled TIOCUCNTL, it will now receive the TIOCUCNTL_{S,C}BRK commands. This allows to send BREAKS commands over a pty(4) independently of the serial terminal emulator used. Guidance and ok nicm@, ok ccardenas@, looks ok to deraadt@ --- share/man/man4/pty.4 | 16 ++++++++++++++-- sys/kern/tty_pty.c | 16 +++++++++++++++- sys/sys/ttycom.h | 6 ++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/share/man/man4/pty.4 b/share/man/man4/pty.4 index 737b9cbf36c..ca8e9d8c851 100644 --- a/share/man/man4/pty.4 +++ b/share/man/man4/pty.4 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pty.4,v 1.23 2016/06/30 15:59:30 tedu Exp $ +.\" $OpenBSD: pty.4,v 1.24 2018/01/08 11:52:14 mpi Exp $ .\" $NetBSD: pty.4,v 1.4 1998/03/21 03:14:30 fair Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)pty.4 8.2 (Berkeley) 11/30/93 .\" -.Dd $Mdocdate: June 30 2016 $ +.Dd $Mdocdate: January 8 2018 $ .Dt PTY 4 .Os .Sh NAME @@ -204,6 +204,18 @@ The .Dv UIOCCMD Ns (0) is a no-op that may be used to probe for the existence of this facility. +.Pp +While this mode is in use, any of the +.Dv TIOCSBRK +and +.Dv TIOCCBRK +ioctl requests issued on the slave part of the pseudo terminal will be +translated to a +.Dv TIOCUCNTL_SBRK +or +.Dv TIOCUCNTL_CBRK +user command on the master side. +.Pp As with .Dv TIOCPKT mode, command operations may be detected with a diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index 970cb044942..d16fb827a8c 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_pty.c,v 1.81 2018/01/02 06:38:45 guenther Exp $ */ +/* $OpenBSD: tty_pty.c,v 1.82 2018/01/08 11:52:14 mpi Exp $ */ /* $NetBSD: tty_pty.c,v 1.33.4.1 1996/06/02 09:08:11 mrg Exp $ */ /* @@ -861,6 +861,20 @@ ptyioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) if (error < 0) error = ttioctl(tp, cmd, data, flag, p); if (error < 0) { + /* + * Translate TIOCSBRK/TIOCCBRK to user mode ioctls to + * let the master interpret BREAK conditions. + */ + switch (cmd) { + case TIOCSBRK: + cmd = UIOCCMD(TIOCUCNTL_SBRK); + break; + case TIOCCBRK: + cmd = UIOCCMD(TIOCUCNTL_CBRK); + break; + default: + break; + } if (pti->pt_flags & PF_UCNTL && (cmd & ~0xff) == UIOCCMD(0)) { if (cmd & 0xff) { diff --git a/sys/sys/ttycom.h b/sys/sys/ttycom.h index cb4f9476bf1..cee568d4ec1 100644 --- a/sys/sys/ttycom.h +++ b/sys/sys/ttycom.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ttycom.h,v 1.15 2017/06/29 04:23:12 deraadt Exp $ */ +/* $OpenBSD: ttycom.h,v 1.16 2018/01/08 11:52:14 mpi Exp $ */ /* $NetBSD: ttycom.h,v 1.4 1996/05/19 17:17:53 jonathan Exp $ */ /*- @@ -116,8 +116,10 @@ struct tstamps { #define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */ #define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */ #define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */ -#define TIOCSTAT _IO('t', 101) /* generate status message */ #define UIOCCMD(n) _IO('u', n) /* usr cntl op "n" */ +#define TIOCUCNTL_SBRK (TIOCSBRK & 0xff)/* set break bit, usr ctnl */ +#define TIOCUCNTL_CBRK (TIOCCBRK & 0xff)/* clear break bit, usr ctnl */ +#define TIOCSTAT _IO('t', 101) /* generate status message */ #define TIOCGSID _IOR('t', 99, int) /* get sid of tty */ #define TIOCCONS _IOW('t', 98, int) /* become virtual console */ #define TIOCSCTTY _IO('t', 97) /* become controlling tty */ -- 2.20.1