Skip to contentSkip to conversation

net: show protocol type in sockprotoname of fdinfo

PATCH In review Masatake YAMATO 2 participants 2 messages Dec 16, 2013 – Dec 17, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: show protocol type in sockprotoname of fdinfo

In 600e177920df936d03b807780ca92c662af98990 "system.sockprotoname" xattrs is added to sockets enumerated under /proc/$PID/fd. It is intended mainly to be used from lsof.

The patch was accepted. However, I think using xattrs under procfs is special hack for lsof. Normally the user of procfs may want to use cat command(or write syscall) to retrieve informations from the fs.

This patch introduces "sockprotoname" field to /proc/PID/fdinfo of socket. So the user can use cat command to retrieve the protocol information.

---
 net/socket.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
net/socket.c +20 -0
index 879933a..5e27715 100644
@@ -132,6 +132,9 @@ static ssize_t sock_sendpage(struct file *file, struct page *page,
 static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
 				struct pipe_inode_info *pipe, size_t len,
 				unsigned int flags);
+#ifdef CONFIG_PROC_FS
+static int sock_show_fdinfo(struct seq_file *m, struct file *file);
+#endif
 
 /*
  *	Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
@@ -155,6 +158,9 @@ static const struct file_operations socket_file_ops = {
 	.sendpage =	sock_sendpage,
 	.splice_write = generic_splice_sendpage,
 	.splice_read =	sock_splice_read,
+#ifdef CONFIG_PROC_FS
+	.show_fdinfo = sock_show_fdinfo,
+#endif
 };
 
 /*
@@ -882,6 +888,20 @@ static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
 	return sock->ops->splice_read(sock, ppos, pipe, len, flags);
 }
 
+#ifdef CONFIG_PROC_FS
+static int sock_show_fdinfo(struct seq_file *m, struct file *file)
+{
+	struct socket *sock;
+	int ret;
+
+	sock = file->private_data;
+	ret = seq_printf(m, "%s: %s\n",
+			 XATTR_SOCKPROTONAME_SUFFIX,
+			 sock->sk ? sock->sk->sk_prot_creator->name : "-");
+	return ret;
+}
+#endif
+
 static struct sock_iocb *alloc_sock_iocb(struct kiocb *iocb,
 					 struct sock_iocb *siocb)
 {
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw

From: Masatake YAMATO <[email protected]>
Date: Mon, 16 Dec 2013 16:19:41 +0900

Quoted 4 lines

In 600e177920df936d03b807780ca92c662af98990 "system.sockprotoname" xattrs is added to sockets enumerated under /proc/$PID/fd. It is intended mainly to be used from lsof.

Quoted 8 lines

The patch was accepted. However, I think using xattrs under procfs is special hack for lsof. Normally the user of procfs may want to use cat command(or write syscall) to retrieve informations from the fs.

This patch introduces "sockprotoname" field to /proc/PID/fdinfo of socket. So the user can use cat command to retrieve the protocol information.

We're not providing multiple ways of doing the same thing, people should have considered things more completely when the original patch was proposed.

Sorry.