Commit 84fd7bdf1266ee6228319903af7e58702745024d

Authored by Cyrill Gorcunov
Committed by Greg Kroah-Hartman
1 parent c6298038bc

tty: Add get- ioctls to fetch tty status v3

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@)

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: Alan Cox <alan@lxorguk.ukuu.org.uk>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Pavel Emelyanov <xemul@parallels.com>
CC: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 2 changed files with 26 additions and 0 deletions Side-by-side Diff

... ... @@ -171,6 +171,12 @@
171 171 return 0;
172 172 }
173 173  
  174 +static int pty_get_lock(struct tty_struct *tty, int __user *arg)
  175 +{
  176 + int locked = test_bit(TTY_PTY_LOCK, &tty->flags);
  177 + return put_user(locked, arg);
  178 +}
  179 +
174 180 /* Set the packet mode on a pty */
175 181 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg)
176 182 {
... ... @@ -193,6 +199,13 @@
193 199 return 0;
194 200 }
195 201  
  202 +/* Get the packet mode of a pty */
  203 +static int pty_get_pktmode(struct tty_struct *tty, int __user *arg)
  204 +{
  205 + int pktmode = tty->packet;
  206 + return put_user(pktmode, arg);
  207 +}
  208 +
196 209 /* Send a signal to the slave */
197 210 static int pty_signal(struct tty_struct *tty, int sig)
198 211 {
199 212  
... ... @@ -420,8 +433,12 @@
420 433 switch (cmd) {
421 434 case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
422 435 return pty_set_lock(tty, (int __user *) arg);
  436 + case TIOCGPTLCK: /* Get PT Lock status */
  437 + return pty_get_lock(tty, (int __user *)arg);
423 438 case TIOCPKT: /* Set PT packet mode */
424 439 return pty_set_pktmode(tty, (int __user *)arg);
  440 + case TIOCGPKT: /* Get PT packet mode */
  441 + return pty_get_pktmode(tty, (int __user *)arg);
425 442 case TIOCSIG: /* Send signal to other side of pty */
426 443 return pty_signal(tty, (int) arg);
427 444 }
428 445  
... ... @@ -536,8 +553,12 @@
536 553 switch (cmd) {
537 554 case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
538 555 return pty_set_lock(tty, (int __user *)arg);
  556 + case TIOCGPTLCK: /* Get PT Lock status */
  557 + return pty_get_lock(tty, (int __user *)arg);
539 558 case TIOCPKT: /* Set PT packet mode */
540 559 return pty_set_pktmode(tty, (int __user *)arg);
  560 + case TIOCGPKT: /* Get PT packet mode */
  561 + return pty_get_pktmode(tty, (int __user *)arg);
541 562 case TIOCGPTN: /* Get PT Number */
542 563 return put_user(tty->index, (unsigned int __user *)arg);
543 564 case TIOCSIG: /* Send signal to other side of pty */
drivers/tty/tty_io.c
... ... @@ -2687,6 +2687,11 @@
2687 2687 case TIOCNXCL:
2688 2688 clear_bit(TTY_EXCLUSIVE, &tty->flags);
2689 2689 return 0;
  2690 + case TIOCGEXCL:
  2691 + {
  2692 + int excl = test_bit(TTY_EXCLUSIVE, &tty->flags);
  2693 + return put_user(excl, (int __user *)p);
  2694 + }
2690 2695 case TIOCNOTTY:
2691 2696 if (current->signal->tty != tty)
2692 2697 return -ENOTTY;