On 03/10/2011 05:03 AM, Daniel P. Berrange wrote:
> +
> + /* See if fd was transferred. */
> + cmsg = CMSG_FIRSTHDR(&msg);
> + if (cmsg && cmsg->cmsg_len == CMSG_LEN(sizeof(fd))
&&
> + cmsg->cmsg_level == SOL_SOCKET &&
> + cmsg->cmsg_type == SCM_RIGHTS) {
> + memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd));
> + }
Also might be nice to create two helper methods for this
int virFileHandleSendToSocket(int unixfd, int sendfd);
int virFileHandleRecvFromSocket(int unixfd);
which we can also use in the monitor code that does the
same thing
Actually, my plans are to import the gnulib module passfd, which defines
sendfd()/recvfd(), and use those. But I'd rather defer that to
post-0.9.0, and keep this patch doing things manually, in case someone
ever needs to backport these patches to RHEL without also pulling in a
gnulib submodule update.
Unfortunately, the monitor code probably can't use sendfd(), because it
makes assumptions that the receiver is using recvfd() but the qemu
monitor code is actually expecting to parse the fd off the 'getfd'
monitor command rather than a one-byte dummy command. But we may have
other places where sendfd/recvfd makes sense (such as if we need to
temporarily change umask while creating a socket).
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org