Skip to contentSkip to conversation

ttys flags, updated

PATCH In review Cyrill Gorcunov 3 participants 10 messages Sep 27, 2012 – Oct 24, 2012

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

cover ttys flags, updated

Hi guys, here is updated series which should address all concerns. Please review, thanks!

Cyrill

#1 lore raw

PATCH 1/3 tty: pty - Move TIOCPKT handling into pty.c

Since this ioctl is for pty devices only move it to pty.c.

v2:
- drop PTY_TYPE_MASTER test since it's master peer ioctl anyway (by jslaby@)

CC "H. Peter Anvin" <[email protected]>
CC Greg Kroah-Hartman <[email protected]>
CC Pavel Emelyanov <[email protected]>
CC Jiri Slaby <[email protected]>
---
 drivers/tty/pty.c       |   26 ++++++++++++++++++++++++++
 drivers/tty/tty_ioctl.c |   20 --------------------
 2 files changed, 26 insertions(+), 20 deletions(-)
drivers/tty/pty.c +26 -0
Index: tty.git/drivers/tty/pty.c
===================================================================
@@ -174,6 +174,28 @@ static int pty_set_lock(struct tty_struc
 	return 0;
 }
 
+/* Set the packet mode on a pty */
+static int pty_set_pktmode(struct tty_struct *tty, int __user *arg)
+{
+	unsigned long flags;
+	int pktmode;
+
+	if (get_user(pktmode, arg))
+		return -EFAULT;
+
+	spin_lock_irqsave(&tty->ctrl_lock, flags);
+	if (pktmode) {
+		if (!tty->packet) {
+			tty->packet = 1;
+			tty->link->ctrl_status = 0;
+		}
+	} else
+		tty->packet = 0;
+	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+
+	return 0;
+}
+
 /* Send a signal to the slave */
 static int pty_signal(struct tty_struct *tty, int sig)
 {
@@ -393,6 +415,8 @@ static int pty_bsd_ioctl(struct tty_stru
 	switch (cmd) {
 	case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
 		return pty_set_lock(tty, (int __user *) arg);
+	case TIOCPKT: /* Set PT packet mode */
+		return pty_set_pktmode(tty, (int __user *)arg);
 	case TIOCSIG:    /* Send signal to other side of pty */
 		return pty_signal(tty, (int) arg);
 	}
@@ -507,6 +531,8 @@ static int pty_unix98_ioctl(struct tty_s
 	switch (cmd) {
 	case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
 		return pty_set_lock(tty, (int __user *)arg);
+	case TIOCPKT: /* Set PT packet mode */
+		return pty_set_pktmode(tty, (int __user *)arg);
 	case TIOCGPTN: /* Get PT Number */
 		return put_user(tty->index, (unsigned int __user *)arg);
 	case TIOCSIG:    /* Send signal to other side of pty */
drivers/tty/tty_ioctl.c +0 -20
Index: tty.git/drivers/tty/tty_ioctl.c
===================================================================
@@ -1153,26 +1153,6 @@ int n_tty_ioctl_helper(struct tty_struct
 		return 0;
 	case TCFLSH:
 		return tty_perform_flush(tty, arg);
-	case TIOCPKT:
-	{
-		int pktmode;
-
-		if (tty->driver->type != TTY_DRIVER_TYPE_PTY ||
-		    tty->driver->subtype != PTY_TYPE_MASTER)
-			return -ENOTTY;
-		if (get_user(pktmode, (int __user *) arg))
-			return -EFAULT;
-		spin_lock_irqsave(&tty->ctrl_lock, flags);
-		if (pktmode) {
-			if (!tty->packet) {
-				tty->packet = 1;
-				tty->link->ctrl_status = 0;
-			}
-		} else
-			tty->packet = 0;
-		spin_unlock_irqrestore(&tty->ctrl_lock, flags);
-		return 0;
-	}
 	default:
 		/* Try the mode commands */
 		return tty_mode_ioctl(tty, file, cmd, arg);
#2 lore raw

Re: [patch 1/3] tty: pty - Move TIOCPKT handling into pty.c

Quoted 6 lines · Cyrill Gorcunov

Since this ioctl is for pty devices only move it to pty.c.

v2:
- drop PTY_TYPE_MASTER test since it's master peer ioctl anyway (by jslaby@)

Quoted 6 lines
CC "H. Peter Anvin" <[email protected]>
CC Greg Kroah-Hartman <[email protected]>
CC Pavel Emelyanov <[email protected]>
CC Jiri Slaby <[email protected]>

Greg, Alan, what about this series? Is there anything else I should do?

#3 lore raw

Re: [patch 1/3] tty: pty - Move TIOCPKT handling into pty.c

Quoted 1 line

Greg, Alan, what about this series? Is there anything else I should do?

Other than resending it now the merge window is closed - I can't think of anything.

Alan

#4 lore raw

Re: [patch 1/3] tty: pty - Move TIOCPKT handling into pty.c

Quoted 4 lines · Alan Cox
Quoted 1 line

Greg, Alan, what about this series? Is there anything else I should do?

Other than resending it now the merge window is closed - I can't think of anything.

OK, thanks, I'll resend.

maintainer
#5 lore raw

Re: [patch 1/3] tty: pty - Move TIOCPKT handling into pty.c

In reply to Cyrill Gorcunov
Quoted 5 lines · Cyrill Gorcunov

Since this ioctl is for pty devices only move it to pty.c.

v2:
- drop PTY_TYPE_MASTER test since it's master peer ioctl anyway (by jslaby@)

This patch adds the compiler warning:
drivers/tty/tty_ioctl.c: In function ‘n_tty_ioctl_helper’:
drivers/tty/tty_ioctl.c:1121:16: warning: unused variable ‘flags’ [-Wunused-variable]

Care to fix it up and resend?

thanks,

greg k-h

#6 lore raw

PATCH 2/3 tty, ioctls -- Add new ioctl definitions for tty flags fetching

In reply to Cyrill Gorcunov

This patch defines new ioctl codes TIOCGPKT, TIOCGPTLCK, TIOCGEXCL for fetching pty's packet mode and locking state, and exclusive mode of tty.

[ No real handlers for the codes though, this will be
addressed in another patch for easier review and bisectability ]

CC Alan Cox <[email protected]>
CC "H. Peter Anvin" <[email protected]>
CC Greg Kroah-Hartman <[email protected]>
CC Pavel Emelyanov <[email protected]>
CC Jiri Slaby <[email protected]>
---
 arch/alpha/include/asm/ioctls.h   |    3 +++
 arch/mips/include/asm/ioctls.h    |    3 +++
 arch/parisc/include/asm/ioctls.h  |    3 +++
 arch/powerpc/include/asm/ioctls.h |    3 +++
 arch/sh/include/asm/ioctls.h      |    3 +++
 arch/sparc/include/asm/ioctls.h   |    3 +++
 arch/xtensa/include/asm/ioctls.h  |    3 +++
 fs/compat_ioctl.c                 |    3 +++
 include/asm-generic/ioctls.h      |    3 +++
 9 files changed, 27 insertions(+)
arch/alpha/include/asm/ioctls.h +3 -0
Index: tty.git/arch/alpha/include/asm/ioctls.h
===================================================================
@@ -95,6 +95,9 @@
 #define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get primary device node of /dev/console */
 #define TIOCSIG		_IOW('T',0x36, int)  /* Generate signal on Pty slave */
 #define TIOCVHANGUP	0x5437
+#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
+#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
+#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
 
 #define TIOCSERCONFIG	0x5453
 #define TIOCSERGWILD	0x5454
arch/mips/include/asm/ioctls.h +3 -0
Index: tty.git/arch/mips/include/asm/ioctls.h
===================================================================
@@ -86,6 +86,9 @@
 #define TIOCGDEV	_IOR('T', 0x32, unsigned int) /* Get primary device node of /dev/console */
 #define TIOCSIG		_IOW('T', 0x36, int)  /* Generate signal on Pty slave */
 #define TIOCVHANGUP	0x5437
+#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
+#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
+#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
 
 /* I hope the range from 0x5480 on is free ... */
 #define TIOCSCTTY	0x5480		/* become controlling tty */
arch/parisc/include/asm/ioctls.h +3 -0
Index: tty.git/arch/parisc/include/asm/ioctls.h
===================================================================
@@ -55,6 +55,9 @@
 #define TIOCGDEV	_IOR('T',0x32, int)  /* Get primary device node of /dev/console */
 #define TIOCSIG		_IOW('T',0x36, int)  /* Generate signal on Pty slave */
 #define TIOCVHANGUP	0x5437
+#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
+#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
+#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
 
 #define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX		0x5451
arch/powerpc/include/asm/ioctls.h +3 -0
Index: tty.git/arch/powerpc/include/asm/ioctls.h
===================================================================
@@ -97,6 +97,9 @@
 #define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get primary device node of /dev/console */
 #define TIOCSIG		_IOW('T',0x36, int)  /* Generate signal on Pty slave */
 #define TIOCVHANGUP	0x5437
+#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
+#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
+#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
 
 #define TIOCSERCONFIG	0x5453
 #define TIOCSERGWILD	0x5454
arch/sh/include/asm/ioctls.h +3 -0
Index: tty.git/arch/sh/include/asm/ioctls.h
===================================================================
@@ -88,6 +88,9 @@
 #define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get primary device node of /dev/console */
 #define TIOCSIG		_IOW('T',0x36, int)  /* Generate signal on Pty slave */
 #define TIOCVHANGUP	_IO('T', 0x37)
+#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
+#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
+#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
 
 #define TIOCSERCONFIG	_IO('T', 83) /* 0x5453 */
 #define TIOCSERGWILD	_IOR('T', 84,  int) /* 0x5454 */
arch/sparc/include/asm/ioctls.h +3 -0
Index: tty.git/arch/sparc/include/asm/ioctls.h
===================================================================
@@ -21,6 +21,9 @@
 #define TCSETSF2	_IOW('T', 15, struct termios2)
 #define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get primary device node of /dev/console */
 #define TIOCVHANGUP	_IO('T', 0x37)
+#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
+#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
+#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
 
 /* Note that all the ioctls that are not available in Linux have a 
  * double underscore on the front to: a) avoid some programs to
arch/xtensa/include/asm/ioctls.h +3 -0
Index: tty.git/arch/xtensa/include/asm/ioctls.h
===================================================================
@@ -101,6 +101,9 @@
 #define TIOCGDEV	_IOR('T',0x32, unsigned int) /* Get primary device node of /dev/console */
 #define TIOCSIG		_IOW('T',0x36, int)  /* Generate signal on Pty slave */
 #define TIOCVHANGUP	_IO('T', 0x37)
+#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
+#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
+#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
 
 #define TIOCSERCONFIG	_IO('T', 83)
 #define TIOCSERGWILD	_IOR('T', 84,  int)
fs/compat_ioctl.c +3 -0
Index: tty.git/fs/compat_ioctl.c
===================================================================
@@ -842,6 +842,9 @@ COMPATIBLE_IOCTL(TIOCGDEV)
 COMPATIBLE_IOCTL(TIOCCBRK)
 COMPATIBLE_IOCTL(TIOCGSID)
 COMPATIBLE_IOCTL(TIOCGICOUNT)
+COMPATIBLE_IOCTL(TIOCGPKT)
+COMPATIBLE_IOCTL(TIOCGPTLCK)
+COMPATIBLE_IOCTL(TIOCGEXCL)
 /* Little t */
 COMPATIBLE_IOCTL(TIOCGETD)
 COMPATIBLE_IOCTL(TIOCSETD)
include/asm-generic/ioctls.h +3 -0
Index: tty.git/include/asm-generic/ioctls.h
===================================================================
@@ -74,6 +74,9 @@
 #define TCSETXW		0x5435
 #define TIOCSIG		_IOW('T', 0x36, int)  /* pty: generate signal */
 #define TIOCVHANGUP	0x5437
+#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
+#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
+#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
 
 #define FIONCLEX	0x5450
 #define FIOCLEX		0x5451
maintainer
#7 lore raw

Re: [patch 2/3] tty, ioctls -- Add new ioctl definitions for tty flags fetching

Quoted 13 lines · Cyrill Gorcunov

This patch defines new ioctl codes TIOCGPKT, TIOCGPTLCK, TIOCGEXCL for fetching pty's packet mode and locking state, and exclusive mode of tty.

[ No real handlers for the codes though, this will be
addressed in another patch for easier review and bisectability ]

CC Alan Cox <[email protected]>
CC "H. Peter Anvin" <[email protected]>
CC Pavel Emelyanov <[email protected]>
CC Jiri Slaby <[email protected]>
Quoted 11 lines
---
 arch/alpha/include/asm/ioctls.h   |    3 +++
 arch/mips/include/asm/ioctls.h    |    3 +++
 arch/parisc/include/asm/ioctls.h  |    3 +++
 arch/powerpc/include/asm/ioctls.h |    3 +++
 arch/sh/include/asm/ioctls.h      |    3 +++
 arch/sparc/include/asm/ioctls.h   |    3 +++
 arch/xtensa/include/asm/ioctls.h  |    3 +++
 fs/compat_ioctl.c                 |    3 +++
 include/asm-generic/ioctls.h      |    3 +++
 9 files changed, 27 insertions(+)

Most of these files are no longer in the tree. Can you redo this against the latest linux-next release and resend the whole series?

thanks,

greg k-h

#8 lore raw

Re: [patch 2/3] tty, ioctls -- Add new ioctl definitions for tty flags fetching

Quoted 3 lines · Greg KH

Most of these files are no longer in the tree. Can you redo this against the latest linux-next release and resend the whole series?

Sure, thanks!

#9 lore raw

PATCH 3/3 tty: Add get- ioctls to fetch tty status v3

In reply to Cyrill Gorcunov

For checkpoint/restore we need to know if tty has exclusive or packet mode set, as well as if pty is currently locked. Just to be able to restore this characteristics.

For this sake the following ioctl codes are introduced

- TIOCGPKT to get packet mode state
- TIOCGPTLCK to get Pty locked state
- TIOCGEXCL to get Exclusive mode state

Note this ioctls are a bit unsafe in terms of data obtained consistency. The tty characteristics might be changed right after ioctl complete. Keep it in mind and use this ioctl carefully.

v2:
- Use TIOC prefix for ioctl codes (by jslaby@)

CC Alan Cox <[email protected]>
CC "H. Peter Anvin" <[email protected]>
CC Greg Kroah-Hartman <[email protected]>
CC Pavel Emelyanov <[email protected]>
CC Jiri Slaby <[email protected]>
---
 drivers/tty/pty.c    |   21 +++++++++++++++++++++
 drivers/tty/tty_io.c |    5 +++++
 2 files changed, 26 insertions(+)
drivers/tty/pty.c +21 -0
Index: tty.git/drivers/tty/pty.c
===================================================================
@@ -174,6 +174,12 @@ static int pty_set_lock(struct tty_struc
 	return 0;
 }
 
+static int pty_get_lock(struct tty_struct *tty, int __user *arg)
+{
+	int locked = test_bit(TTY_PTY_LOCK, &tty->flags);
+	return put_user(locked, arg);
+}
+
 /* Set the packet mode on a pty */
 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg)
 {
@@ -196,6 +202,13 @@ static int pty_set_pktmode(struct tty_st
 	return 0;
 }
 
+/* Get the packet mode of a pty */
+static int pty_get_pktmode(struct tty_struct *tty, int __user *arg)
+{
+	int pktmode = tty->packet;
+	return put_user(pktmode, arg);
+}
+
 /* Send a signal to the slave */
 static int pty_signal(struct tty_struct *tty, int sig)
 {
@@ -415,8 +428,12 @@ static int pty_bsd_ioctl(struct tty_stru
 	switch (cmd) {
 	case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
 		return pty_set_lock(tty, (int __user *) arg);
+	case TIOCGPTLCK: /* Get PT Lock status */
+		return pty_get_lock(tty, (int __user *)arg);
 	case TIOCPKT: /* Set PT packet mode */
 		return pty_set_pktmode(tty, (int __user *)arg);
+	case TIOCGPKT: /* Get PT packet mode */
+		return pty_get_pktmode(tty, (int __user *)arg);
 	case TIOCSIG:    /* Send signal to other side of pty */
 		return pty_signal(tty, (int) arg);
 	}
@@ -531,8 +548,12 @@ static int pty_unix98_ioctl(struct tty_s
 	switch (cmd) {
 	case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
 		return pty_set_lock(tty, (int __user *)arg);
+	case TIOCGPTLCK: /* Get PT Lock status */
+		return pty_get_lock(tty, (int __user *)arg);
 	case TIOCPKT: /* Set PT packet mode */
 		return pty_set_pktmode(tty, (int __user *)arg);
+	case TIOCGPKT: /* Get PT packet mode */
+		return pty_get_pktmode(tty, (int __user *)arg);
 	case TIOCGPTN: /* Get PT Number */
 		return put_user(tty->index, (unsigned int __user *)arg);
 	case TIOCSIG:    /* Send signal to other side of pty */
drivers/tty/tty_io.c +5 -0
Index: tty.git/drivers/tty/tty_io.c
===================================================================
@@ -2693,6 +2693,11 @@ long tty_ioctl(struct file *file, unsign
 	case TIOCNXCL:
 		clear_bit(TTY_EXCLUSIVE, &tty->flags);
 		return 0;
+	case TIOCGEXCL:
+	{
+		int excl = test_bit(TTY_EXCLUSIVE, &tty->flags);
+		return put_user(excl, (int __user *)p);
+	}
 	case TIOCNOTTY:
 		if (current->signal->tty != tty)
 			return -ENOTTY;