Skip to contentSkip to conversation

include: undefine _LINUX_TYPES_H if including old sys/capability.h

PATCH Superseded Li Wang 2 participants 3 messages Oct 16, 2019 – Oct 17, 2019

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v2 1/1 include: undefine _LINUX_TYPES_H if including old sys/capability.h

In some of the libcap-devel(1.96~2.16) versions, it defines the _LINUX_TYPES_H macro that makes ltp-lib can not include linux/types.h essentially.

    # cat -n /usr/include/sys/capability.h
    ...
    25  /*
    26   * Make sure we can be included from userland by preventing
    27   * capability.h from including other kernel headers
    28   */
    29  #define _LINUX_TYPES_H

To get rid of this compiling errors on rhel6(libcap-devel-2.16) series platform, here undefine _LINUX_TYPES_H if test included that old sys/capability.h.

== Error log ==
In file included from ../include/tst_netlink.h:26,

                 from tst_crypto.c:13:

/usr/include/linux/netlink.h:45: error: expected specifier-qualifier-list before ?__u16? /usr/include/linux/netlink.h:135: error: expected specifier-qualifier-list before ?__u16? tst_crypto.c: In function ?tst_crypto_recv_ack?:
tst_crypto.c:46: error: ?struct nlmsghdr? has no member named ?nlmsg_seq? tst_crypto.c:47: error: ?struct nlmsghdr? has no member named ?nlmsg_type? tst_crypto.c:47: error: ?struct nlmsghdr? has no member named ?nlmsg_seq? tst_crypto.c:55: error: ?struct nlmsghdr? has no member named ?nlmsg_type? tst_crypto.c:58: error: ?struct nlmsghdr? has no member named ?nlmsg_type? tst_crypto.c:58: error: ?struct nlmsghdr? has no member named ?nlmsg_seq? tst_crypto.c: In function ?tst_crypto_add_alg?:
...
make: *** [tst_crypto.o] Error 1

---
 include/lapi/capability.h |  8 ++++++++
 m4/ltp-cap.m4             | 17 ++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
include/lapi/capability.h +8 -0
index dac233d84..8833f0605 100644
@@ -10,6 +10,14 @@
 
 #ifdef HAVE_SYS_CAPABILITY_H
 # include <sys/capability.h>
+/**
+ * Some old libcap-devel(1.96~2.16) define _LINUX_TYPES_H in
+ * sys/capability.h that makes ltp-lib cann't include linux/types.h
+ * essentially. Here undefine it if include such old header-file.
+ */
+# ifndef HAVE_NEWER_LIBCAP
+#  undef _LINUX_TYPES_H
+# endif
 #endif
 
 #ifndef CAP_NET_RAW
m4/ltp-cap.m4 +16 -1
index 02d3cac8c..4981e843d 100644
@@ -1,6 +1,6 @@
 dnl SPDX-License-Identifier: GPL-2.0-or-later
 dnl Copyright (c) Cisco Systems Inc., 2009
-dnl Copyright (c) Linux Test Project, 2010
+dnl Copyright (c) Linux Test Project, 2019
 dnl Author: Ngie Cooper <[email protected]>
 
 AC_DEFUN([LTP_CHECK_CAPABILITY_SUPPORT],[
@@ -14,4 +14,19 @@ if test "x$cap_libs" != x; then
 	AC_DEFINE(HAVE_LIBCAP)
 fi
 AC_SUBST(CAP_LIBS,$cap_libs)
+
+AH_TEMPLATE(HAVE_NEWER_LIBCAP,
+[Define to 1 if you have newer libcap-2 installed.])
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([
+#include <sys/capability.h>
+#include <linux/types.h>
+int main(void) {
+	__u16 a;
+	__u32 b;
+	return 0;
+}])],[has_newer_libcap="yes"])
+
+if test "x$has_newer_libcap" = xyes; then
+	AC_DEFINE(HAVE_NEWER_LIBCAP)
+fi
 ])
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/1 include: undefine _LINUX_TYPES_H if including old sys/capability.h

Hello,

Quoted 81 lines · Li Wang

In some of the libcap-devel(1.96~2.16) versions, it defines the _LINUX_TYPES_H macro that makes ltp-lib can not include linux/types.h essentially.

    # cat -n /usr/include/sys/capability.h
    ...
    25  /*
    26   * Make sure we can be included from userland by preventing
    27   * capability.h from including other kernel headers
    28   */
    29  #define _LINUX_TYPES_H

To get rid of this compiling errors on rhel6(libcap-devel-2.16) series platform, here undefine _LINUX_TYPES_H if test included that old sys/capability.h.

== Error log ==
In file included from ../include/tst_netlink.h:26,

                 from tst_crypto.c:13:

/usr/include/linux/netlink.h:45: error: expected specifier-qualifier-list before ?__u16? /usr/include/linux/netlink.h:135: error: expected specifier-qualifier-list before ?__u16? tst_crypto.c: In function ?tst_crypto_recv_ack?:
tst_crypto.c:46: error: ?struct nlmsghdr? has no member named ?nlmsg_seq? tst_crypto.c:47: error: ?struct nlmsghdr? has no member named ?nlmsg_type? tst_crypto.c:47: error: ?struct nlmsghdr? has no member named ?nlmsg_seq? tst_crypto.c:55: error: ?struct nlmsghdr? has no member named ?nlmsg_type? tst_crypto.c:58: error: ?struct nlmsghdr? has no member named ?nlmsg_type? tst_crypto.c:58: error: ?struct nlmsghdr? has no member named ?nlmsg_seq? tst_crypto.c: In function ?tst_crypto_add_alg?:
...
make: *** [tst_crypto.o] Error 1

---
 include/lapi/capability.h |  8 ++++++++
 m4/ltp-cap.m4             | 17 ++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
include/lapi/capability.h +8 -0
index dac233d84..8833f0605 100644
@@ -10,6 +10,14 @@
 
 #ifdef HAVE_SYS_CAPABILITY_H
 # include <sys/capability.h>
+/**
+ * Some old libcap-devel(1.96~2.16) define _LINUX_TYPES_H in
+ * sys/capability.h that makes ltp-lib cann't include linux/types.h
+ * essentially. Here undefine it if include such old header-file.
+ */
+# ifndef HAVE_NEWER_LIBCAP
+#  undef _LINUX_TYPES_H
+# endif
 #endif
 
 #ifndef CAP_NET_RAW
m4/ltp-cap.m4 +7 -1
index 02d3cac8c..4981e843d 100644
@@ -1,6 +1,6 @@
 dnl SPDX-License-Identifier: GPL-2.0-or-later
 dnl Copyright (c) Cisco Systems Inc., 2009
-dnl Copyright (c) Linux Test Project, 2010
+dnl Copyright (c) Linux Test Project, 2019
 dnl Author: Ngie Cooper <[email protected]>
 
 AC_DEFUN([LTP_CHECK_CAPABILITY_SUPPORT],[
@@ -14,4 +14,19 @@ if test "x$cap_libs" != x; then
 	AC_DEFINE(HAVE_LIBCAP)
 fi
 AC_SUBST(CAP_LIBS,$cap_libs)
+
+AH_TEMPLATE(HAVE_NEWER_LIBCAP,
+[Define to 1 if you have newer libcap-2 installed.])
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([
+#include <sys/capability.h>
+#include <linux/types.h>

m4/ltp-cap.m4 if test "x$cap_libs" != x; then · line 32

Quoted 10 lines
m4/ltp-cap.m4 +9 -0
+int main(void) {
+	__u16 a;
+	__u32 b;
+	return 0;
+}])],[has_newer_libcap="yes"])
+
+if test "x$has_newer_libcap" = xyes; then
+	AC_DEFINE(HAVE_NEWER_LIBCAP)
+fi
 ])

Ack.

Signature · 2 lines
Thank you,
Richard.
author
#2 lore raw

PATCH v2 1/1 include: undefine _LINUX_TYPES_H if including old sys/capability.h

Quoted 2 lines

Ack.

Pushed. Thanks for review.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191017/69555cef/attachment.htm>