[PATCH 2/3] Support unix sockets in -yy option
Masatake YAMATO
yamato at redhat.com
Tue Dec 9 01:39:41 UTC 2014
Thank you for reviewing.
>> This patch extends -yy option; the peer address of a unix socket can be
>> printed like an inet socket.
>>
>> About a listening socket, its socket path and socket inode are printed.
>> About an accepted socket, its socket path, socket inode and peer inode
>> are printed.
>> About a client socket, its socket inode and peer inode are printed.
>>
>> An example of server side with netcat:
>>
>> $ ./strace -yy -e network nc -l -U /tmp/example.sock
>> socket(PF_LOCAL, SOCK_STREAM, 0) = 3
>> setsockopt(3<UNIX:[12592606]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
>> bind(3<UNIX:[12592606]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.sock"}, 19) = 0
>> listen(3</tmp/example.sock,12592606>, 10) = 0
>> accept(3</tmp/example.sock,12592606>, {sa_family=AF_LOCAL, NULL}, [2]) = 4</tmp/example.sock,12593212->12591974>
>> recvfrom(4</tmp/example.sock,12593212->12591974>, "INPUT\n", 8192, 0, NULL, NULL) = 6
>
> I see potential source of confusion in this output format: socket path
> looks very similar to a regular file path. Lets change it somehow to
> avoid ambiguity. For example, we could add "UNIX:" prefix:
>
> 3<UNIX:/tmp/example.sock,12592606>
>
> For the same reason, maybe the inode information is better to be added
> before the path rather than after the path, e.g.
>
> 4<UNIX:12593212->12591974:/tmp/example.sock>
How about following format:
FD "<UNIX:[" SELF_INODE [ "->" PEER_INODE ] [ ":" PATH ] "]>"
(I used double quotes here because "[" and "]" are used as literal and meta characters.)
e.g.
% ./strace -yy -e network nc -l -U /tmp/example.socket
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
setsockopt(3<UNIX:[14672314]>, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3<UNIX:[14672314]>, {sa_family=AF_LOCAL, sun_path="/tmp/example.socket"}, 21) = 0
listen(3<UNIX:[14672314:/tmp/example.socket]>, 10) = 0
accept(3<UNIX:[14672314:/tmp/example.socket]>, {sa_family=AF_LOCAL, NULL}, [2]) = 4<UNIX:[14672333->14672331:/tmp/example.socket]>
recvfrom(4<UNIX:[14672333->14672331:/tmp/example.socket]>, "a\n", 8192, 0, NULL, NULL) = 2
Using "[" and "]" as literal characters is verbose but the output
format is uniformed well in listening, accepted sockets and other protocol
of sockets like netlink.
Masatake YAMATO
More information about the Strace-devel
mailing list