include: undefine _LINUX_TYPES_H if including sys/capability.h
PATCH 1/1 include: undefine _LINUX_TYPES_H if including sys/capability.h
In some of the libcap-devel(1.96~2.16) versions, it defines the _LINUX_TYPES_H macro to make ltp-lib cann't 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_HTo get rid of this compiling errors on rhel6(libcap-devel-2.16) series platform, here undefine _LINUX_TYPES_H if included that 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 | 1 + 1 file changed, 1 insertion(+)
include/lapi/capability.h +1 -0
@@ -10,6 +10,7 @@#ifdef HAVE_SYS_CAPABILITY_H # include <sys/capability.h> +# undef _LINUX_TYPES_H#endif #ifndef CAP_NET_RAW
Signature · 1 line
2.20.1
PATCH 1/1 include: undefine _LINUX_TYPES_H if including sys/capability.h
Hello,
Quoted 43 lines · Li Wang
In some of the libcap-devel(1.96~2.16) versions, it defines the
_LINUX_TYPES_Hmacro to make ltp-lib cann't includelinux/types.hessentially.# 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_HTo get rid of this compiling errors on rhel6(libcap-devel-2.16) series platform, here undefine
_LINUX_TYPES_Hif included thatsys/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 1Reported-by Ping Fang <[email protected]>Signed-off-by Li Wang <[email protected]>Cc Ping Fang <[email protected]>Cc Richard Palethorpe <[email protected]>--- include/lapi/capability.h | 1 + 1 file changed, 1 insertion(+)include/lapi/capability.h +0
-0
include/lapi/capability.h line 13
Quoted 4 lines
include/lapi/capability.h +1
-0@@ -10,6 +10,7 @@#ifdef HAVE_SYS_CAPABILITY_H # include <sys/capability.h> +# undef _LINUX_TYPES_H
My concern here is if linux/types.h has already been included. Then this could cause a redefinition error if it is included again.
Quoted 3 lines
include/lapi/capability.h +0
-0#endif #ifndef CAP_NET_RAW
Signature · 2 lines
Thank you, Richard.
PATCH 1/1 include: undefine _LINUX_TYPES_H if including sys/capability.h
Richard Palethorpe <[email protected]> wrote:
...
Quoted 7 lines
Quoted 3 lines
#ifdef
HAVE_SYS_CAPABILITY_H# include <sys/capability.h> +# undef _LINUX_TYPES_HMy concern here is if
linux/types.hhas already been included. Then this could cause a redefinition error if it is included again.
Hmm, it looks tricky to solve this, because I didn't find a macro to show version in libcap files.
Another method I can think of is to build a small program to check if that libcap version is newer or not during the configure phase. If yes, then export a new macro HAVE_NEWER_LIBCAP to be used in /lapi/capability.h.
The following patch has been verified on both rhel6 and rhel8, any comments? [I'm not familiar with m4 syntax, just copy from other places]
include/lapi/capability.h +3 -1
@@ -10,7 +10,9 @@#ifdef HAVE_SYS_CAPABILITY_H # include <sys/capability.h> -# undef _LINUX_TYPES_H +# ifndef HAVE_NEWER_LIBCAP +# undef _LINUX_TYPES_H +# endif #endif #ifndef CAP_NET_RAW
m4/ltp-cap.m4 +15 -0
@@ -14,4 +14,20 @@ 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 · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20191016/906d80d0/attachment.htm>
PATCH 1/1 include: undefine _LINUX_TYPES_H if including sys/capability.h
Hello,
Quoted 11 lines · Li Wang
Richard Palethorpe <[email protected]> wrote:
...
Quoted 7 lines
Quoted 3 lines
#ifdef
HAVE_SYS_CAPABILITY_H# include <sys/capability.h> +# undef _LINUX_TYPES_HMy concern here is if
linux/types.hhas already been included. Then this could cause a redefinition error if it is included again.
Quoted 6 lines
Hmm, it looks tricky to solve this, because I didn't find a macro to show version in libcap files.
Another method I can think of is to build a small program to check if that libcap version is newer or not during the configure phase. If yes, then export a new macro
HAVE_NEWER_LIBCAPto be used in /lapi/capability.h.
Yes, this could work.
Quoted 3 lines
The following patch has been verified on both rhel6 and rhel8, any comments? [I'm not familiar with m4 syntax, just copy from other places]
m4 all looks ugly to me ;-)
Quoted 6 lines
include/lapi/capability.h +0
-0
include/lapi/capability.h line 16
Quoted 8 lines
include/lapi/capability.h +3
-1@@ -10,7 +10,9 @@#ifdef HAVE_SYS_CAPABILITY_H # include <sys/capability.h> -# undef _LINUX_TYPES_H +# ifndef HAVE_NEWER_LIBCAP +# undef _LINUX_TYPES_H +# endif #endif
This is so wierd it maybe deserves a comment. Otherwise, this looks good to me.
Quoted 26 lines
include/lapi/capability.h +0
-0#ifndef CAP_NET_RAW m4/ltp-cap.m4 +15
-0@@ -14,4 +14,20 @@ 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 · 2 lines
Thank you, Richard.