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.
diff --git a/configure.ac b/configure.ac
index 20fae61..bdaca46 100644
--- a/configure.ac
+++ b/configure.ac
@@ -253,7 +253,6 @@
 	elf.h
 	inttypes.h
 	ioctls.h
-	linux/bpf.h
 	linux/bsg.h
 	linux/falloc.h
 	linux/filter.h
@@ -319,6 +318,20 @@
 	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,
diff --git a/tests/bpf.c b/tests/bpf.c
index b2e019d..636fae8 100644
--- a/tests/bpf.c
+++ b/tests/bpf.c
@@ -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[] = {