[libvirt] [Qemu-devel] [PATCH v4 3/7] qapi: Add pass-fd QMP command

Eric Blake eblake at redhat.com
Fri Jun 22 20:24:40 UTC 2012


On 06/22/2012 12:36 PM, Corey Bryant wrote:
> This patch adds the pass-fd QMP command using the QAPI framework.
> Like the getfd command, it is used to pass a file descriptor via
> SCM_RIGHTS and associate it with a name.  However, the pass-fd
> command also returns the received file descriptor, which is a
> difference in behavior from the getfd command, which returns
> nothing.  pass-fd also supports a boolean "force" argument that
> can be used to specify that an existing file descriptor is
> associated with the specified name, and that it should become a
> copy of the newly passed file descriptor.

> +        if (replace) {
> +            /* the existing fd is replaced with the new fd */
> +            close(monfd->fd);
> +            monfd->fd = fd;
> +            return fd;
> +        }
> +
> +        if (copy) {

Since 'replace' and 'copy' are never both true, should this instead be a
tri-state enum argument instead of two independent bool arguments?

> +            /* the existing fd becomes a copy of the new fd */
> +            if (dup2(fd, monfd->fd) == -1) {

Broken - you want to use dup3(fd, monfd->fd, O_CLOEXEC) (and fall back
to dup2()+fcntl(F_GETFD/F_SETFD) on platforms where dup3 is not
available; it has been proposed for the next revision of POSIX but right
now is pretty much limited to Linux and Cygwin).  Otherwise, you are
undoing the fact that patch 1/7 just changed the 'getfd' list to always
keep all its fds marked cloexec.

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120622/194f6560/attachment-0001.sig>


More information about the libvir-list mailing list