diff options
author | Masatake YAMATO <yamato@redhat.com> | 2017-07-17 17:27:59 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-08-28 14:51:23 -0400 |
commit | d01c3289e7d68162e32bc08c2b65dd1a216a7ef8 (patch) | |
tree | 34177b1e85f857b838fa75b08153d091472eb775 | |
parent | 199e717f252be0e31c97b9c7861dd6e2abfaa936 (diff) |
pty: show associative slave of ptmx in fdinfo
This patch adds "tty-index" field to /proc/PID/fdinfo/N if N
specifies /dev/ptmx. The field shows the index of associative
slave pts.
Though a minor number is given for each pts instance, ptmx is not.
It means there is no way in user-space to know the association between
file descriptors for pts/n and ptmx. (n = 0, 1, ...)
This is different from pipe. About pipe such association can be solved
by inode of pipefs.
Providing the way to know the association between pts/n and ptmx helps
users understand the status of running system. lsof can utilize this field.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/pty.c | 8 | ||||
-rw-r--r-- | drivers/tty/tty_io.c | 9 | ||||
-rw-r--r-- | include/linux/tty_driver.h | 2 |
3 files changed, 18 insertions, 1 deletions
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 284749fb0f6b..bb672ace562f 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c | |||
@@ -741,6 +741,11 @@ static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) | |||
741 | } | 741 | } |
742 | } | 742 | } |
743 | 743 | ||
744 | static void pty_show_fdinfo(struct tty_struct *tty, struct seq_file *m) | ||
745 | { | ||
746 | seq_printf(m, "tty-index:\t%d\n", tty->index); | ||
747 | } | ||
748 | |||
744 | static const struct tty_operations ptm_unix98_ops = { | 749 | static const struct tty_operations ptm_unix98_ops = { |
745 | .lookup = ptm_unix98_lookup, | 750 | .lookup = ptm_unix98_lookup, |
746 | .install = pty_unix98_install, | 751 | .install = pty_unix98_install, |
@@ -755,7 +760,8 @@ static const struct tty_operations ptm_unix98_ops = { | |||
755 | .ioctl = pty_unix98_ioctl, | 760 | .ioctl = pty_unix98_ioctl, |
756 | .compat_ioctl = pty_unix98_compat_ioctl, | 761 | .compat_ioctl = pty_unix98_compat_ioctl, |
757 | .resize = pty_resize, | 762 | .resize = pty_resize, |
758 | .cleanup = pty_cleanup | 763 | .cleanup = pty_cleanup, |
764 | .show_fdinfo = pty_show_fdinfo, | ||
759 | }; | 765 | }; |
760 | 766 | ||
761 | static const struct tty_operations pty_unix98_ops = { | 767 | static const struct tty_operations pty_unix98_ops = { |
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 974b13d24401..c3c8fd0ed535 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c | |||
@@ -462,6 +462,14 @@ static int hung_up_tty_fasync(int fd, struct file *file, int on) | |||
462 | return -ENOTTY; | 462 | return -ENOTTY; |
463 | } | 463 | } |
464 | 464 | ||
465 | static void tty_show_fdinfo(struct seq_file *m, struct file *file) | ||
466 | { | ||
467 | struct tty_struct *tty = file_tty(file); | ||
468 | |||
469 | if (tty && tty->ops && tty->ops->show_fdinfo) | ||
470 | tty->ops->show_fdinfo(tty, m); | ||
471 | } | ||
472 | |||
465 | static const struct file_operations tty_fops = { | 473 | static const struct file_operations tty_fops = { |
466 | .llseek = no_llseek, | 474 | .llseek = no_llseek, |
467 | .read = tty_read, | 475 | .read = tty_read, |
@@ -472,6 +480,7 @@ static const struct file_operations tty_fops = { | |||
472 | .open = tty_open, | 480 | .open = tty_open, |
473 | .release = tty_release, | 481 | .release = tty_release, |
474 | .fasync = tty_fasync, | 482 | .fasync = tty_fasync, |
483 | .show_fdinfo = tty_show_fdinfo, | ||
475 | }; | 484 | }; |
476 | 485 | ||
477 | static const struct file_operations console_fops = { | 486 | static const struct file_operations console_fops = { |
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h index 00b2213f6a35..fcdc0f5d9098 100644 --- a/include/linux/tty_driver.h +++ b/include/linux/tty_driver.h | |||
@@ -243,6 +243,7 @@ | |||
243 | #include <linux/list.h> | 243 | #include <linux/list.h> |
244 | #include <linux/cdev.h> | 244 | #include <linux/cdev.h> |
245 | #include <linux/termios.h> | 245 | #include <linux/termios.h> |
246 | #include <linux/seq_file.h> | ||
246 | 247 | ||
247 | struct tty_struct; | 248 | struct tty_struct; |
248 | struct tty_driver; | 249 | struct tty_driver; |
@@ -285,6 +286,7 @@ struct tty_operations { | |||
285 | int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew); | 286 | int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew); |
286 | int (*get_icount)(struct tty_struct *tty, | 287 | int (*get_icount)(struct tty_struct *tty, |
287 | struct serial_icounter_struct *icount); | 288 | struct serial_icounter_struct *icount); |
289 | void (*show_fdinfo)(struct tty_struct *tty, struct seq_file *m); | ||
288 | #ifdef CONFIG_CONSOLE_POLL | 290 | #ifdef CONFIG_CONSOLE_POLL |
289 | int (*poll_init)(struct tty_driver *driver, int line, char *options); | 291 | int (*poll_init)(struct tty_driver *driver, int line, char *options); |
290 | int (*poll_get_char)(struct tty_driver *driver, int line); | 292 | int (*poll_get_char)(struct tty_driver *driver, int line); |