netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH] af_unix: Add peer inode to /proc/net/unix
@ 2010-03-01  4:52 Kenan Kalajdzic
  2010-03-01  7:05 ` Changli Gao
  0 siblings, 1 reply; 3+ messages in thread
From: Kenan Kalajdzic @ 2010-03-01  4:52 UTC (permalink / raw)
  To: netdev

Recently, I had a problem identifying local X-clients on a desktop system from 
within a userspace application.  So, I thought it may be a good idea to add the 
peer inode field to /proc/net/unix.

Instead of adding a new column to /proc/net/unix (which breaks important 
userspace programs, including 'netstat' and 'lsof'), we can make use of the 
fact that most client sockets (including these of X-clients) and anonymous 
sockets have an empty path field in /proc/net/unix, which can be used for 
specifying the peer inode.  In order to differentiate between a regular path 
and an entry which contains the inode number of the peer socket, I chose to 
simply add the 'peer=' prefix to the peer inode number.

Signed-off-by: Kenan Kalajdzic <kenan@unix.ba>
---
 net/unix/af_unix.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index f255119..e778428 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2157,7 +2157,7 @@ static int unix_seq_show(struct seq_file *seq, void *v)
 		seq_puts(seq, "Num       RefCount Protocol Flags    Type St "
 			 "Inode Path\n");
 	else {
-		struct sock *s = v;
+		struct sock *s = v, *peer;
 		struct unix_sock *u = unix_sk(s);
 		unix_state_lock(s);
 
@@ -2186,6 +2186,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
 			}
 			for ( ; i < len; i++)
 				seq_putc(seq, u->addr->name->sun_path[i]);
+		} else {
+			peer = unix_peer(s);
+			if (peer) {
+				unix_state_lock(peer);
+				seq_printf(seq, " peer=%lu", sock_i_ino(peer));
+				unix_state_unlock(peer);
+			}
 		}
 		unix_state_unlock(s);
 		seq_putc(seq, '\n');
-- 
1.6.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-01 15:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-01  4:52 [RFC][PATCH] af_unix: Add peer inode to /proc/net/unix Kenan Kalajdzic
2010-03-01  7:05 ` Changli Gao
2010-03-01 15:09   ` Kenan Kalajdzic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).