build: improved handling of <execinfo.h>, BSD <net/if.h>

FreeBSD and OpenBSD have a <net/if.h> that is not self-contained;
and mingw lacks the header altogether.  But gnulib has just taken
care of that for us, so we might as well simplify our code.  In
the process, I got a syntax-check failure if we don't also take
the gnulib execinfo module.

* .gnulib: Update to latest, for execinfo and net_if.
* bootstrap.conf (gnulib_modules): Add execinfo and net_if modules.
* configure.ac: Let gnulib check for headers.  Simplify check for
'struct ifreq', while also including enough prereq headers.
* src/internal.h (IF_NAMESIZE): Drop, now that gnulib guarantees it.
* src/nwfilter/nwfilter_learnipaddr.h: Use correct header for
IF_NAMESIZE.
* src/util/virnetdev.c (includes): Assume <net/if.h> exists.
* src/util/virnetdevbridge.c (includes): Likewise.
* src/util/virnetdevtap.c (includes): Likewise.
* src/util/logging.c (includes): Assume <execinfo.h> exists.
(virLogStackTraceToFd): Handle gnulib's fallback implementation.
This commit is contained in:
Eric Blake 2012-09-05 16:27:42 -06:00
parent b6a14aec5f
commit ccaf0beec8
9 changed files with 25 additions and 44 deletions

@ -1 +1 @@
Subproject commit 271dd74fdf54ec2a03e73a5173b0b5697f6088f1
Subproject commit 440a1dbe523e37f206252cb034c3a62f26867e42

View File

@ -38,6 +38,7 @@ count-one-bits
crypto/md5
dirname-lgpl
environ
execinfo
fclose
fcntl
fcntl-h
@ -70,6 +71,7 @@ manywarnings
mkstemp
mkstemps
mktempd
net_if
netdb
nonblocking
openpty

View File

@ -186,8 +186,7 @@ LIBS=$old_libs
dnl Availability of various common headers (non-fatal if missing).
AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/un.h \
sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h \
sys/un.h sys/syscall.h netinet/tcp.h ifaddrs.h libtasn1.h \
net/if.h execinfo.h])
sys/un.h sys/syscall.h netinet/tcp.h ifaddrs.h libtasn1.h])
dnl We need to decide at configure time if libvirt will use real atomic
dnl operations ("lock free") or emulated ones with a mutex.
@ -245,20 +244,12 @@ AM_CONDITIONAL([WITH_ATOMIC_OPS_PTHREAD],[test "$atomic_ops" = "pthread"])
AC_MSG_RESULT([$atomic_ops])
AC_MSG_CHECKING([for struct ifreq in net/if.h])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[
#include <net/if.h>
]],
[[
struct ifreq ifr;
]])],[
AC_DEFINE([HAVE_STRUCT_IFREQ],[],[Defined if struct ifreq existsin net/if.h])
AC_MSG_RESULT([yes])
],[
AC_MSG_RESULT([yes])
])
AC_CHECK_TYPE([struct ifreq],
[AC_DEFINE([HAVE_STRUCT_IFREQ],[1],
[Defined if struct ifreq exists in net/if.h])],
[], [[#include <sys/socket.h>
#include <net/if.h>
]])
dnl Our only use of libtasn1.h is in the testsuite, and can be skipped
dnl if the header is not present. Assume -ltasn1 is present if the

View File

@ -58,10 +58,6 @@
# define HOST_NAME_MAX 256
# endif
# ifndef IF_NAMESIZE
# define IF_NAMESIZE 16
# endif
# ifndef INET_ADDRSTRLEN
# define INET_ADDRSTRLEN 16
# endif

View File

@ -2,6 +2,7 @@
* nwfilter_learnipaddr.h: support for learning IP address used by a VM
* on an interface
*
* Copyright (C) 2012 Red Hat, Inc.
* Copyright (C) 2010 IBM Corp.
* Copyright (C) 2010 Stefan Berger
*
@ -26,6 +27,7 @@
# define __NWFILTER_LEARNIPADDR_H
# include "conf/nwfilter_params.h"
# include <net/if.h>
enum howDetect {
DETECT_DHCP = 1,

View File

@ -31,12 +31,10 @@
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <execinfo.h>
#if HAVE_SYSLOG_H
# include <syslog.h>
#endif
#ifdef HAVE_EXECINFO_H
# include <execinfo.h>
#endif
#include "virterror_internal.h"
#include "logging.h"
@ -792,23 +790,21 @@ cleanup:
static void virLogStackTraceToFd(int fd)
{
#ifdef HAVE_EXECINFO_H
void *array[100];
int size;
# define STRIP_DEPTH 3
size = backtrace(array, ARRAY_CARDINALITY(array));
backtrace_symbols_fd(array + STRIP_DEPTH, size - STRIP_DEPTH, fd);
ignore_value(safewrite(fd, "\n", 1));
#else
static bool doneWarning = false;
const char *msg = "Stack trace not available on this platform\n";
if (!doneWarning) {
#define STRIP_DEPTH 3
size = backtrace(array, ARRAY_CARDINALITY(array));
if (size) {
backtrace_symbols_fd(array + STRIP_DEPTH, size - STRIP_DEPTH, fd);
ignore_value(safewrite(fd, "\n", 1));
} else if (!doneWarning) {
ignore_value(safewrite(fd, msg, strlen(msg)));
doneWarning = true;
}
#endif
#undef STRIP_DEPTH
}
static int virLogOutputToFd(const char *category ATTRIBUTE_UNUSED,

View File

@ -32,9 +32,7 @@
#include "logging.h"
#include <sys/ioctl.h>
#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif
#include <net/if.h>
#include <fcntl.h>
#ifdef __linux__

View File

@ -31,10 +31,8 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif
#ifdef __linux__
# include <linux/sockios.h>
# include <linux/param.h> /* HZ */
@ -47,7 +45,7 @@
#define VIR_FROM_THIS VIR_FROM_NONE
#if defined(HAVE_NET_IF_H) && defined(SIOCBRADDBR)
#ifdef SIOCBRADDBR
static int virNetDevSetupControlFull(const char *ifname,
struct ifreq *ifr,
int domain,

View File

@ -35,9 +35,7 @@
#include "util.h"
#include <sys/ioctl.h>
#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif
#include <net/if.h>
#include <fcntl.h>
#ifdef __linux__
# include <linux/if_tun.h> /* IFF_TUN, IFF_NO_PI */