[libvirt] [PATCH 6/8] Add client side support for FD passing

Eric Blake eblake at redhat.com
Thu Oct 27 23:20:19 UTC 2011


On 10/25/2011 10:03 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange"<berrange at redhat.com>
>
> Extend the RPC client code to allow file descriptors to be sent
> to the server with calls, and received back with replies.
>
> * src/remote/remote_driver.c: Stub extra args
> * src/libvirt_private.syms, src/rpc/virnetclient.c,
>    src/rpc/virnetclient.h, src/rpc/virnetclientprogram.c,
>    src/rpc/virnetclientprogram.h: Extend APIs to allow
>    FD passing
> ---
>   src/libvirt_private.syms      |    4 +++
>   src/remote/remote_driver.c    |    1 +
>   src/rpc/virnetclient.c        |   25 +++++++++++++++++
>   src/rpc/virnetclient.h        |    2 +
>   src/rpc/virnetclientprogram.c |   58 +++++++++++++++++++++++++++++++++++++++-
>   src/rpc/virnetclientprogram.h |    4 +++
>   6 files changed, 92 insertions(+), 2 deletions(-)
>
>       msg->header.serial = serial;
>       msg->header.proc = proc;
> +    msg->nfds = noutfds;
> +    if (VIR_ALLOC_N(msg->fds, msg->nfds)<  0) {
> +        virReportOOMError();
> +        goto error;
> +    }
> +    for (i = 0 ; i<  msg->nfds ; i++) {
> +        if ((msg->fds[i] = dup(outfds[i]))<  0) {
> +            virReportSystemError(errno,
> +                                 _("Cannot duplicate FD %d"),
> +                                 outfds[i]);
> +            goto error;
> +        }
> +        if (virSetInherit(msg->fds[i], false)<  0) {
> +            virReportSystemError(errno,
> +                                 _("Cannot set close-on-exec %d"),
> +                                 msg->fds[i]);

That works, but has a slight race window when compared with gnulib's 
dup_cloexec (in "cloexec.h"), or fcntl(fd, F_DUPFD_CLOEXEC, 0).  But it 
goes back to my comment earlier in the series that auditing the code for 
atomic cloexec support is a much bigger task for later, so I'm okay with 
this as-is for now.

ACK.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org




More information about the libvir-list mailing list