render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c401cc
From 1e9f3547e22f52605796bc21ccdec05a881fb209 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <1e9f3547e22f52605796bc21ccdec05a881fb209.1390394207.git.jdenemar@redhat.com>
c401cc
From: Eric Blake <eblake@redhat.com>
c401cc
Date: Mon, 20 Jan 2014 09:03:25 -0700
c401cc
Subject: [PATCH] build: fix build with latest rawhide kernel headers
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1042937
c401cc
c401cc
Bother those kernel developers.  In the latest rawhide, kernel
c401cc
and glibc have now been unified so that <netinet/in.h> and
c401cc
<linux/in6.h> no longer clash; but <linux/if_bridge.h> is still
c401cc
not self-contained.  Because of the latest header change, the
c401cc
build is failing with:
c401cc
c401cc
checking for linux/param.h... no
c401cc
configure: error: You must install kernel-headers in order to compile libvirt with QEMU or LXC support
c401cc
c401cc
with details:
c401cc
c401cc
In file included from conftest.c:561:0:
c401cc
/usr/include/linux/in6.h:71:18: error: field 'flr_dst' has incomplete type
c401cc
  struct in6_addr flr_dst;
c401cc
c401cc
We need a workaround to avoid our workaround :)
c401cc
c401cc
* configure.ac (NETINET_LINUX_WORKAROUND): New test.
c401cc
* src/util/virnetdevbridge.c (includes): Use it.
c401cc
c401cc
Signed-off-by: Eric Blake <eblake@redhat.com>
c401cc
(cherry picked from commit e62e0094dcd0ca1484491a9cc62919473b647f11)
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 configure.ac               | 39 +++++++++++++++++++++++++++++----------
c401cc
 src/util/virnetdevbridge.c | 24 ++++++++++++++----------
c401cc
 2 files changed, 43 insertions(+), 20 deletions(-)
c401cc
c401cc
diff --git a/configure.ac b/configure.ac
c401cc
index a000dcb..eb20f1c 100644
c401cc
--- a/configure.ac
c401cc
+++ b/configure.ac
c401cc
@@ -996,18 +996,37 @@ dnl check for kernel headers required by src/bridge.c
c401cc
 dnl
c401cc
 if test "$with_linux" = "yes"; then
c401cc
   if test "$with_qemu" = "yes" || test "$with_lxc" = "yes" ; then
c401cc
+    # Various kernel versions have headers that are not self-standing, but
c401cc
+    # yet are incompatible with the corresponding glibc headers.  In order
c401cc
+    # to guarantee compilation across a wide range of versions (from RHEL 5
c401cc
+    # to rawhide), we first have to probe whether glibc and kernel can be
c401cc
+    # used in tandem; and if not, provide workarounds that ensure that
c401cc
+    # ABI-compatible IPv6 types are present for use by the kernel headers.
c401cc
+    # These probes mirror the usage in virnetdevbridge.c
c401cc
+    AC_CACHE_CHECK(
c401cc
+      [whether <linux/*.h> and <netinet/*.h> headers are compatible],
c401cc
+      [lv_cv_netinet_linux_compatible],
c401cc
+      [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
c401cc
+        #include <netinet/in.h>
c401cc
+        #include <linux/in6.h>
c401cc
+      ]])],
c401cc
+      [lv_cv_netinet_linux_compatible=yes],
c401cc
+      [lv_cv_netinet_linux_compatible=no])])
c401cc
+    if test "x$lv_cv_netinet_linux_compatible" != xyes; then
c401cc
+      AC_DEFINE([NETINET_LINUX_WORKAROUND], [1],
c401cc
+        [define to 1 if Linux kernel headers require a workaround to avoid
c401cc
+        compilation errors when mixed with glibc netinet headers])
c401cc
+    fi
c401cc
     AC_CHECK_HEADERS([linux/param.h linux/sockios.h linux/if_bridge.h linux/if_tun.h],,
c401cc
       [AC_MSG_ERROR([You must install kernel-headers in order to compile libvirt with QEMU or LXC support])],
c401cc
-      [[/* The kernel folks broke their headers when used with particular
c401cc
-         * glibc versions; although the structs are ABI compatible, the
c401cc
-         * C type system doesn't like struct redefinitions.  We work around
c401cc
-         * the problem here in the same manner as in virnetdevbridge.c.  */
c401cc
-        #include <netinet/in.h>
c401cc
-        #define in6_addr in6_addr_
c401cc
-        #define sockaddr_in6 sockaddr_in6_
c401cc
-        #define ipv6_mreq ipv6_mreq_
c401cc
-        #define in6addr_any in6addr_any_
c401cc
-        #define in6addr_loopback in6addr_loopback_
c401cc
+      [[#include <netinet/in.h>
c401cc
+        #if NETINET_LINUX_WORKAROUND
c401cc
+        # define in6_addr in6_addr_
c401cc
+        # define sockaddr_in6 sockaddr_in6_
c401cc
+        # define ipv6_mreq ipv6_mreq_
c401cc
+        # define in6addr_any in6addr_any_
c401cc
+        # define in6addr_loopback in6addr_loopback_
c401cc
+        #endif
c401cc
         #include <linux/in6.h>
c401cc
       ]])
c401cc
   fi
c401cc
diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c
c401cc
index e4daa27..1a3740a 100644
c401cc
--- a/src/util/virnetdevbridge.c
c401cc
+++ b/src/util/virnetdevbridge.c
c401cc
@@ -39,22 +39,26 @@
c401cc
 #ifdef __linux__
c401cc
 # include <linux/sockios.h>
c401cc
 # include <linux/param.h>     /* HZ                 */
c401cc
+# if NETINET_LINUX_WORKAROUND
c401cc
 /* Depending on the version of kernel vs. glibc, there may be a collision
c401cc
  * between <net/in.h> and kernel IPv6 structures.  The different types
c401cc
  * are ABI compatible, but choke the C type system; work around it by
c401cc
  * using temporary redefinitions.  */
c401cc
-# define in6_addr in6_addr_
c401cc
-# define sockaddr_in6 sockaddr_in6_
c401cc
-# define ipv6_mreq ipv6_mreq_
c401cc
-# define in6addr_any in6addr_any_
c401cc
-# define in6addr_loopback in6addr_loopback_
c401cc
+#  define in6_addr in6_addr_
c401cc
+#  define sockaddr_in6 sockaddr_in6_
c401cc
+#  define ipv6_mreq ipv6_mreq_
c401cc
+#  define in6addr_any in6addr_any_
c401cc
+#  define in6addr_loopback in6addr_loopback_
c401cc
+# endif
c401cc
 # include <linux/in6.h>
c401cc
 # include <linux/if_bridge.h> /* SYSFS_BRIDGE_ATTR  */
c401cc
-# undef in6_addr
c401cc
-# undef sockaddr_in6
c401cc
-# undef ipv6_mreq
c401cc
-# undef in6addr_any
c401cc
-# undef in6addr_loopback
c401cc
+# if NETINET_LINUX_WORKAROUND
c401cc
+#  undef in6_addr
c401cc
+#  undef sockaddr_in6
c401cc
+#  undef ipv6_mreq
c401cc
+#  undef in6addr_any
c401cc
+#  undef in6addr_loopback
c401cc
+# endif
c401cc
 
c401cc
 # define JIFFIES_TO_MS(j) (((j)*1000)/HZ)
c401cc
 # define MS_TO_JIFFIES(ms) (((ms)*HZ)/1000)
c401cc
-- 
c401cc
1.8.5.3
c401cc