tests/bpf: fix build with incompatibly old linux/bpf.h and/or gcc

* configure.ac: Check how union bpf_attr.log_buf initialization works.
* tests/bpf.c: Check for HAVE_UNION_BPF_ATTR_LOG_BUF.
This commit is contained in:
Дмитрий Левин 2015-07-29 16:27:16 +00:00
parent 3456bcca67
commit 4e3ded36ef
2 changed files with 15 additions and 2 deletions

View File

@ -253,7 +253,6 @@ AC_CHECK_HEADERS(m4_normalize([
elf.h
inttypes.h
ioctls.h
linux/bpf.h
linux/bsg.h
linux/falloc.h
linux/filter.h
@ -319,6 +318,20 @@ AC_CHECK_HEADERS([linux/input.h], [
AC_CHECK_MEMBERS([struct input_absinfo.resolution],,, [#include <linux/input.h>])
])
AC_CHECK_HEADERS([linux/bpf.h], [
AC_CACHE_CHECK([whether union bpf_attr.log_buf initialization works],
[st_cv_have_union_bpf_attr_log_buf],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <linux/bpf.h>]],
[[union bpf_attr a = { .log_buf = 0 };]])],
[st_cv_have_union_bpf_attr_log_buf=yes],
[st_cv_have_union_bpf_attr_log_buf=no])])
if test $st_cv_have_union_bpf_attr_log_buf = yes; then
AC_DEFINE(HAVE_UNION_BPF_ATTR_LOG_BUF, [1],
[Define to 1 if union bpf_attr.log_buf initialization works])
fi
])
AC_CHECK_DECLS([sys_errlist])
AC_CHECK_DECLS(m4_normalize([
PTRACE_PEEKUSER,

View File

@ -7,7 +7,7 @@
#include <unistd.h>
#include <sys/syscall.h>
#if defined HAVE_LINUX_BPF_H && defined __NR_bpf
#if defined HAVE_UNION_BPF_ATTR_LOG_BUF && defined __NR_bpf
# include <linux/bpf.h>
static const struct bpf_insn insns[] = {