[lkml]   [2002]   [May]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subject[Q] find matching unix socket pairs?
Hello everybody!

I have a process tree which talks using (unix) socket pairs. Now I wrote a
perl script which read /proc/*/fd/* and displays the communications channels.

I have one problem left: the association of socket pairs.

Sometimes it happens that the pair has an even and an odd inode (say, 50
and 51), but sometimes they are more than 1 from each other.

Looking in the sources I think I found out why. The sys_socketpair call calls
->create() two times; the create-call uses kalloc, which can block.
So if there are some processes trying to get pairs it can happen that the
->create calls are interleaving.

The unix sockets are paired by unix_peer(), which is a #define to ->pair.
But as this is a pointer to another skb it doesn't make much sense to
export that as-is to userspace.

In /proc/net/unix there is a "num"-field exported, which is just a pointer
to the "struct sock"-structure (?).
Maybe this num-field could be substituted (if adding another field then
this should be done before path, as for socketpairs the path is empty and
adding behind that would make parsing more difficult) by some ->pair->
I'd suggest the ->i_ino value, as this is already visible in user space,
but I'm lost how to get the dentry from the ->pair pointer.

Any suggestions?
Finished patches :-) ???



To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:25    [W:0.045 / U:4.632 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site