diff mbox series

[iproute2,2/2] devlink: fix libc and kernel headers collision

Message ID 7f81026b803edcaeaca05994298118271a2f287d.1561463345.git.baruch@tkos.co.il
State Changes Requested
Delegated to: stephen hemminger
Headers show
Series [iproute2,1/2] devlink: fix format string warning for 32bit targets | expand

Commit Message

Baruch Siach June 25, 2019, 11:49 a.m. UTC
Since commit 2f1242efe9d ("devlink: Add devlink health show command") we
use the sys/sysinfo.h header for the sysinfo(2) system call. But since
iproute2 carries a local version of the kernel struct sysinfo, this
causes a collision with libc that do not rely on kernel defined sysinfo
like musl libc:

In file included from devlink.c:25:0:
.../sysroot/usr/include/sys/sysinfo.h:10:8: error: redefinition of 'struct sysinfo'
 struct sysinfo {
        ^~~~~~~
In file included from ../include/uapi/linux/kernel.h:5:0,
                 from ../include/uapi/linux/netlink.h:5,
                 from ../include/uapi/linux/genetlink.h:6,
                 from devlink.c:21:
../include/uapi/linux/sysinfo.h:8:8: note: originally defined here
 struct sysinfo {
        ^~~~~~~

Move the sys/sysinfo.h userspace header before kernel headers, and
suppress the indirect include of linux/sysinfo.h.

Cc: Aya Levin <ayal@mellanox.com>
Cc: Moshe Shemesh <moshe@mellanox.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 devlink/devlink.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Stephen Hemminger June 25, 2019, 6:59 p.m. UTC | #1
On Tue, 25 Jun 2019 14:49:05 +0300
Baruch Siach <baruch@tkos.co.il> wrote:

> +/* Suppress linux/sysinfo.h to avoid
> + * collision of struct sysinfo definition
> + * with musl libc headers
> + */

You only need a small comment for this.

#define _LINUX_SYSINFO_H /* avoid collision with musl header */
diff mbox series

Patch

diff --git a/devlink/devlink.c b/devlink/devlink.c
index b400fab17578..2ea60d3556da 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -18,11 +18,16 @@ 
 #include <limits.h>
 #include <errno.h>
 #include <inttypes.h>
+#include <sys/sysinfo.h>
+/* Suppress linux/sysinfo.h to avoid
+ * collision of struct sysinfo definition
+ * with musl libc headers
+ */
+#define _LINUX_SYSINFO_H
 #include <linux/genetlink.h>
 #include <linux/devlink.h>
 #include <libmnl/libmnl.h>
 #include <netinet/ether.h>
-#include <sys/sysinfo.h>
 #include <sys/queue.h>
 
 #include "SNAPSHOT.h"