[libvirt PATCH 11/32] src: implement APIs for passing FDs over UNIX sockets

Pavel Hrdina phrdina at redhat.com
Mon Jan 27 13:01:54 UTC 2020


On Thu, Jan 23, 2020 at 11:43:04AM +0000, Daniel P. Berrangé wrote:
> This is a simplified variant of gnulib's passfd module
> without the portability code that we do not require.
> 
> Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
> ---
>  src/libvirt_private.syms  |   5 ++
>  src/qemu/qemu_interface.c |   4 +-
>  src/rpc/virnetsocket.c    |   5 +-
>  src/util/virfile.c        |   5 +-
>  src/util/virsocket.c      | 142 +++++++++++++++++++++++++++++++++++++-
>  src/util/virsocket.h      |   3 +
>  6 files changed, 154 insertions(+), 10 deletions(-)

[...]

> diff --git a/src/util/virsocket.c b/src/util/virsocket.c
> index 96b9ece2b7..0e3775ac44 100644
> --- a/src/util/virsocket.c
> +++ b/src/util/virsocket.c
> @@ -19,10 +19,12 @@
>  #include <config.h>
>  
>  #include "virsocket.h"
> +#include "virutil.h"
> +#include "virfile.h"
>  
> -#ifdef WIN32
> +#include <fcntl.h>
>  
> -# include <fcntl.h>
> +#ifdef WIN32
>  
>  # define FD2SK(fd) _get_osfhandle(fd)
>  # define SK2FD(sk) (_open_osfhandle((intptr_t) (sk), O_RDWR | O_BINARY))
> @@ -365,3 +367,139 @@ vir_socket(int domain, int type, int protocol)
>  }
>  
>  #endif /* WIN32 */
> +
> +/* The code that uses CMSG_FIRSTHDR is enabled on
> +   Linux, Mac OS X, FreeBSD, OpenBSD, NetBSD, AIX, OSF/1, Cygwin.
> +   The code that uses HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS is enabled on
> +   HP-UX, IRIX, Solaris.  */
> +
> +/* MSG_CMSG_CLOEXEC is defined only on Linux, as of 2011.  */
> +#ifndef MSG_CMSG_CLOEXEC
> +# define MSG_CMSG_CLOEXEC 0
> +#endif
> +
> +#ifndef WIN32
> +/* virSocketSendFD sends the file descriptor fd along the socket
> +   to a process calling recvfd on the other end.

s/recvfd/virSocketRecvFD/

Otherwise looks good compared to passfd GNULIB module.

Reviewed-by: Pavel Hrdina <phrdina at redhat.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200127/c0df5c11/attachment-0001.sig>


More information about the libvir-list mailing list