tty: add TIOCVHANGUP to allow clean tty shutdown of all ttys
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 17 Feb 2011 17:39:28 +0000 (18:39 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 17 Feb 2011 22:16:30 +0000 (14:16 -0800)
This is useful for system management software so that it can kick
off things like gettys and everything that's started from a tty,
before we reuse it from/for something else or shut it down.

Without this ioctl it would have to temporarily become the owner of
the tty, then call vhangup() and then give it up again.

Cc: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
arch/alpha/include/asm/ioctls.h
arch/mips/include/asm/ioctls.h
arch/parisc/include/asm/ioctls.h
arch/powerpc/include/asm/ioctls.h
arch/sh/include/asm/ioctls.h
arch/sparc/include/asm/ioctls.h
arch/xtensa/include/asm/ioctls.h
drivers/tty/tty_io.c
include/asm-generic/ioctls.h

index 034b6cf..80e1cee 100644 (file)
@@ -94,6 +94,7 @@
 #define TIOCSPTLCK     _IOW('T',0x31, int)  /* Lock/unlock Pty */
 #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 TIOCSERCONFIG  0x5453
 #define TIOCSERGWILD   0x5454
index d967b89..92403c3 100644 (file)
@@ -85,6 +85,7 @@
 #define TIOCSPTLCK     _IOW('T', 0x31, int)  /* Lock/unlock Pty */
 #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
 
 /* I hope the range from 0x5480 on is free ... */
 #define TIOCSCTTY      0x5480          /* become controlling tty */
index 6ba80d0..054ec06 100644 (file)
@@ -54,6 +54,7 @@
 #define TIOCSPTLCK     _IOW('T',0x31, int)  /* Lock/unlock Pty */
 #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 FIONCLEX       0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX                0x5451
index c7dc17c..e9b7887 100644 (file)
@@ -96,6 +96,7 @@
 #define TIOCSPTLCK     _IOW('T',0x31, int)  /* Lock/unlock Pty */
 #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 TIOCSERCONFIG  0x5453
 #define TIOCSERGWILD   0x5454
index 84e85a7..a6769f3 100644 (file)
@@ -87,6 +87,7 @@
 #define TIOCSPTLCK     _IOW('T',0x31, int)  /* Lock/unlock Pty */
 #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 TIOCSERCONFIG  _IO('T', 83) /* 0x5453 */
 #define TIOCSERGWILD   _IOR('T', 84,  int) /* 0x5454 */
index ed3807b..28d0c8b 100644 (file)
@@ -20,6 +20,7 @@
 #define TCSETSW2       _IOW('T', 14, struct termios2)
 #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)
 
 /* Note that all the ioctls that are not available in Linux have a 
  * double underscore on the front to: a) avoid some programs to
index ccf1800..fd1d136 100644 (file)
 #define TIOCSPTLCK     _IOW('T',0x31, int)  /* Lock/unlock Pty */
 #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 TIOCSERCONFIG  _IO('T', 83)
 #define TIOCSERGWILD   _IOR('T', 84,  int)
index 20a862a..8ef2d69 100644 (file)
@@ -2626,6 +2626,11 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                return put_user(tty->ldisc->ops->num, (int __user *)p);
        case TIOCSETD:
                return tiocsetd(tty, p);
+       case TIOCVHANGUP:
+               if (!capable(CAP_SYS_ADMIN))
+                       return -EPERM;
+               tty_vhangup(tty);
+               return 0;
        case TIOCGDEV:
        {
                unsigned int ret = new_encode_dev(tty_devnum(real_tty));
index 3f3f2d1..199975f 100644 (file)
@@ -73,6 +73,7 @@
 #define TCSETXF                0x5434
 #define TCSETXW                0x5435
 #define TIOCSIG                _IOW('T', 0x36, int)  /* pty: generate signal */
+#define TIOCVHANGUP    0x5437
 
 #define FIONCLEX       0x5450
 #define FIOCLEX                0x5451