From: Kenan Kalajdzic <kenan@unix.ba>
To: netdev@vger.kernel.org
Subject: [RFC][PATCH] af_unix: Add peer inode to /proc/net/unix
Date: Mon, 1 Mar 2010 05:52:07 +0100 [thread overview]
Message-ID: <20100301045206.GB496@home.unix.ba> (raw)
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
next reply other threads:[~2010-03-01 5:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-01 4:52 Kenan Kalajdzic [this message]
2010-03-01 7:05 ` [RFC][PATCH] af_unix: Add peer inode to /proc/net/unix Changli Gao
2010-03-01 15:09 ` Kenan Kalajdzic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100301045206.GB496@home.unix.ba \
--to=kenan@unix.ba \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).