On Wed, May 14, 2014 at 4:58 AM, Jérémie Courrèges-Anglas
<[email protected]> wrote:
>                         if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)) &&
>                             cmsg->cmsg_level == SOL_SOCKET &&
>                             cmsg->cmsg_type == SCM_RIGHTS) {
>                                 passed_fd = *(int *)CMSG_DATA(cmsg);

In your test program you only ever send one FD, so this is fine; but
in general multiple FDs can be sent at a time, and you'll receive a
single SOL_SOCKET/SCM_RIGHTS control message with an array of N ints.

E.g., see 
https://code.google.com/p/chromium/codesearch#chromium/src/base/posix/unix_domain_socket_linux.cc&l=130.

> So the two issues show up when you want to call sendmsg and recvmsg
> with no data at all, but only control messages.  sendmsg allocates an
> empty mbuf for data (m_len == 0), this mbuf is not discarded and freed
> by soreceive for SOCK_STREAM sockets, and stays in the socket buffer.
>
> I understand that this API was probably not designed to pass only
> control messages, and no data at all.  But it is easily fixable, and the
> manpage could provide portability information.

Blah, I'm not really a fan of allowing sending zero-length data
messages.  It makes it tricky for receivers to tell if they actually
received an EOF or not.

But if we're going to allow it (which we do currently it seems), then
your diff seems like a reasonable fix to me.  mbufs aren't my
specialty though. =/

Reply via email to