[Q] find matching unix socket pairs?

Ph. Marek (marek@bmlv.gv.at)
Tue, 07 May 2002 10:33:20 +0200


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->
identifier?
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?
Help?
Finished patches :-) ???

Regards,

Phil

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/