Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933276AbdC3HuC (ORCPT ); Thu, 30 Mar 2017 03:50:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48400 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932781AbdC3HuB (ORCPT ); Thu, 30 Mar 2017 03:50:01 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EE51467EBD Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=yamato@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EE51467EBD From: Masatake YAMATO To: linux-kernel@vger.kernel.org Cc: yamato@redhat.com Subject: [RESEND PATCH] pty: show associative slave of ptmx in fdinfo Date: Thu, 30 Mar 2017 16:49:52 +0900 Message-Id: <20170330074952.2048-1-yamato@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 30 Mar 2017 07:50:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3540 Lines: 115 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 --- drivers/tty/pty.c | 12 +++++++++++- drivers/tty/tty_io.c | 14 ++++++++++++++ include/linux/tty_driver.h | 5 +++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 66b59a1..4c8cf03 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c @@ -674,6 +674,13 @@ static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) } } +#ifdef CONFIG_PROC_FS +static void pty_show_fdinfo(struct tty_struct *tty, struct seq_file *m) +{ + seq_printf(m, "tty-index:\t%d\n", tty->index); +} +#endif + static const struct tty_operations ptm_unix98_ops = { .lookup = ptm_unix98_lookup, .install = pty_unix98_install, @@ -687,7 +694,10 @@ static const struct tty_operations ptm_unix98_ops = { .unthrottle = pty_unthrottle, .ioctl = pty_unix98_ioctl, .resize = pty_resize, - .cleanup = pty_cleanup + .cleanup = pty_cleanup, +#ifdef CONFIG_PROC_FS + .show_fdinfo = pty_show_fdinfo, +#endif }; static const struct tty_operations pty_unix98_ops = { diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index e6d1a65..24a999d 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -106,6 +106,8 @@ #include #include +#include + #undef TTY_DEBUG_HANGUP #ifdef TTY_DEBUG_HANGUP # define tty_debug_hangup(tty, f, args...) tty_debug(tty, f, ##args) @@ -471,6 +473,15 @@ static int hung_up_tty_fasync(int fd, struct file *file, int on) return -ENOTTY; } +#ifdef CONFIG_PROC_FS +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); +} +#endif + static const struct file_operations tty_fops = { .llseek = no_llseek, .read = tty_read, @@ -481,6 +492,9 @@ static const struct file_operations tty_fops = { .open = tty_open, .release = tty_release, .fasync = tty_fasync, +#ifdef CONFIG_PROC_FS + .show_fdinfo = tty_show_fdinfo, +#endif }; static const struct file_operations console_fops = { diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h index b742b5e..499823d 100644 --- a/include/linux/tty_driver.h +++ b/include/linux/tty_driver.h @@ -243,6 +243,7 @@ #include #include #include +#include struct tty_struct; struct tty_driver; @@ -285,6 +286,10 @@ struct tty_operations { int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew); int (*get_icount)(struct tty_struct *tty, struct serial_icounter_struct *icount); +#ifdef CONFIG_PROC_FS + void (*show_fdinfo)(struct tty_struct *tty, struct seq_file *m); +#endif + #ifdef CONFIG_CONSOLE_POLL int (*poll_init)(struct tty_driver *driver, int line, char *options); int (*poll_get_char)(struct tty_driver *driver, int line); -- 2.9.3