[Libguestfs] [libnbd PATCH v2 01/23] Include sys/vsock.h if linux/vm_sockets.h is not available

Martin Kletzander mkletzan at redhat.com
Thu Jun 10 23:12:05 UTC 2021


This is the case on MacOS for example.  The issue is that AF_VSOCK is defined in
sys/socket.h, but struct sockaddr_vm is not, so the safeguard lower in the file
does not work.  Thankfully sys/vsock.h has the sockaddr_vm definition, so
including that fixes the build issue.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 configure.ac  | 2 +-
 lib/connect.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 0dce57a3f502..065ede6342b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -96,7 +96,7 @@ AC_CHECK_HEADERS([\
     stdatomic.h \
     sys/endian.h])
 
-AC_CHECK_HEADERS([linux/vm_sockets.h], [], [], [#include <sys/socket.h>])
+AC_CHECK_HEADERS([linux/vm_sockets.h sys/vsock.h], [], [], [#include <sys/socket.h>])
 
 dnl posix_fadvise helps to optimise linear reads and writes (optional).
 AC_CHECK_FUNCS([posix_fadvise])
diff --git a/lib/connect.c b/lib/connect.c
index 99781cd20dae..500806303404 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -33,6 +33,8 @@
 
 #ifdef HAVE_LINUX_VM_SOCKETS_H
 #include <linux/vm_sockets.h>
+#elif HAVE_SYS_VSOCK_H
+#include <sys/vsock.h>
 #endif
 
 #include "internal.h"
-- 
2.32.0




More information about the Libguestfs mailing list