Re: [PATCH 03/14] Add API for duplicating a socket/client file descriptor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/07/2011 08:17 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
> 
> * src/rpc/virnetsocket.c, src/rpc/virnetsocket.h: Add
>   virNetSocketDupFD()
> * src/rpc/virnetclient.c, src/rpc/virnetclient.h: Add
>   virNetClientDupFD() and virNetClientGetFD()
> ---
>  src/rpc/virnetclient.c |   20 ++++++++++++++++++++
>  src/rpc/virnetclient.h |    3 +++
>  src/rpc/virnetsocket.c |   12 ++++++++++++
>  src/rpc/virnetsocket.h |    2 ++
>  4 files changed, 37 insertions(+), 0 deletions(-)

In the interest of using atomic FD_CLOEXEC in more places, I would
suggest making a change to this API:

> +
> +int virNetClientDupFD(virNetClientPtr client)

This should be virNetClientDupFD(virNetClientPtr client, bool cloexec)

>  
> +int virNetSocketDupFD(virNetSocketPtr sock)
> +{
> +    int fd;
> +    if ((fd = dup(sock->fd)) < 0) {

And this should be:

int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec)
{
    int fd;
    if (cloexec)
        fd = fcntl(F_DUPFD_CLOEXEC, sock->fd);
    else
        fd = dup(sock->fd);
    if (fd < 0) {
...

and rely on gnulib's guarantee that fcntl(F_DUPFD_CLOEXEC) works.  (Oh,
that means we need to import the fcntl module in bootstrap.conf).

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]