Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d01c3289 authored by Masatake YAMATO's avatar Masatake YAMATO Committed by Greg Kroah-Hartman
Browse files

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: default avatarMasatake YAMATO <yamato@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 199e717f
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -741,6 +741,11 @@ static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
	}
	}
}
}


static void pty_show_fdinfo(struct tty_struct *tty, struct seq_file *m)
{
	seq_printf(m, "tty-index:\t%d\n", tty->index);
}

static const struct tty_operations ptm_unix98_ops = {
static const struct tty_operations ptm_unix98_ops = {
	.lookup = ptm_unix98_lookup,
	.lookup = ptm_unix98_lookup,
	.install = pty_unix98_install,
	.install = pty_unix98_install,
@@ -755,7 +760,8 @@ static const struct tty_operations ptm_unix98_ops = {
	.ioctl = pty_unix98_ioctl,
	.ioctl = pty_unix98_ioctl,
	.compat_ioctl = pty_unix98_compat_ioctl,
	.compat_ioctl = pty_unix98_compat_ioctl,
	.resize = pty_resize,
	.resize = pty_resize,
	.cleanup = pty_cleanup
	.cleanup = pty_cleanup,
	.show_fdinfo = pty_show_fdinfo,
};
};


static const struct tty_operations pty_unix98_ops = {
static const struct tty_operations pty_unix98_ops = {
+9 −0
Original line number Original line Diff line number Diff line
@@ -462,6 +462,14 @@ static int hung_up_tty_fasync(int fd, struct file *file, int on)
	return -ENOTTY;
	return -ENOTTY;
}
}


static void tty_show_fdinfo(struct seq_file *m, struct file *file)
{
	struct tty_struct *tty = file_tty(file);

	if (tty && tty->ops && tty->ops->show_fdinfo)
		tty->ops->show_fdinfo(tty, m);
}

static const struct file_operations tty_fops = {
static const struct file_operations tty_fops = {
	.llseek		= no_llseek,
	.llseek		= no_llseek,
	.read		= tty_read,
	.read		= tty_read,
@@ -472,6 +480,7 @@ static const struct file_operations tty_fops = {
	.open		= tty_open,
	.open		= tty_open,
	.release	= tty_release,
	.release	= tty_release,
	.fasync		= tty_fasync,
	.fasync		= tty_fasync,
	.show_fdinfo	= tty_show_fdinfo,
};
};


static const struct file_operations console_fops = {
static const struct file_operations console_fops = {
+2 −0
Original line number Original line Diff line number Diff line
@@ -243,6 +243,7 @@
#include <linux/list.h>
#include <linux/list.h>
#include <linux/cdev.h>
#include <linux/cdev.h>
#include <linux/termios.h>
#include <linux/termios.h>
#include <linux/seq_file.h>


struct tty_struct;
struct tty_struct;
struct tty_driver;
struct tty_driver;
@@ -285,6 +286,7 @@ struct tty_operations {
	int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
	int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
	int (*get_icount)(struct tty_struct *tty,
	int (*get_icount)(struct tty_struct *tty,
				struct serial_icounter_struct *icount);
				struct serial_icounter_struct *icount);
	void (*show_fdinfo)(struct tty_struct *tty, struct seq_file *m);
#ifdef CONFIG_CONSOLE_POLL
#ifdef CONFIG_CONSOLE_POLL
	int (*poll_init)(struct tty_driver *driver, int line, char *options);
	int (*poll_init)(struct tty_driver *driver, int line, char *options);
	int (*poll_get_char)(struct tty_driver *driver, int line);
	int (*poll_get_char)(struct tty_driver *driver, int line);