e2ec8a
From 79df4db3fd122f5040bdf2225c3047375de3b0d2 Mon Sep 17 00:00:00 2001
e2ec8a
From: Filipe Brandenburger <filbranden@google.com>
e2ec8a
Date: Sun, 15 Jul 2018 22:43:35 -0700
e2ec8a
Subject: [PATCH] build-sys: Detect whether struct statx is defined in
e2ec8a
 sys/stat.h
e2ec8a
MIME-Version: 1.0
e2ec8a
Content-Type: text/plain; charset=UTF-8
e2ec8a
Content-Transfer-Encoding: 8bit
e2ec8a
e2ec8a
Starting with glibc 2.27.9000-36.fc29, include file sys/stat.h will have a
e2ec8a
definition for struct statx, in which case include file linux/stat.h should be
e2ec8a
avoided, in order to prevent a duplicate definition.
e2ec8a
e2ec8a
    In file included from ../src/basic/missing.h:18,
e2ec8a
		     from ../src/basic/util.h:28,
e2ec8a
		     from ../src/basic/hashmap.h:10,
e2ec8a
		     from ../src/shared/bus-util.h:12,
e2ec8a
		     from ../src/libsystemd/sd-bus/bus-creds.c:11:
e2ec8a
    /usr/include/linux/stat.h:99:8: error: redefinition of ‘struct statx’
e2ec8a
     struct statx {
e2ec8a
	    ^~~~~
e2ec8a
    In file included from /usr/include/sys/stat.h:446,
e2ec8a
		     from ../src/basic/util.h:19,
e2ec8a
		     from ../src/basic/hashmap.h:10,
e2ec8a
		     from ../src/shared/bus-util.h:12,
e2ec8a
		     from ../src/libsystemd/sd-bus/bus-creds.c:11:
e2ec8a
    /usr/include/bits/statx.h:36:8: note: originally defined here
e2ec8a
     struct statx
e2ec8a
	    ^~~~~
e2ec8a
e2ec8a
Extend our meson.build to look for struct statx when only sys/stat.h is
e2ec8a
included and, in that case, do not include linux/stat.h anymore.
e2ec8a
e2ec8a
Tested that systemd builds correctly when using a glibc version that includes a
e2ec8a
definition for struct statx.
e2ec8a
e2ec8a
glibc Fedora RPM update:
e2ec8a
https://src.fedoraproject.org/rpms/glibc/c/28cb5d31fc1e5887912283c889689c47076278ae
e2ec8a
e2ec8a
glibc upstream commit:
e2ec8a
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=fd70af45528d59a00eb3190ef6706cb299488fcd
e2ec8a
---
e2ec8a
 meson.build            | 5 +++++
e2ec8a
 src/basic/missing.h    | 5 ++++-
e2ec8a
 src/basic/xattr-util.c | 1 -
e2ec8a
 3 files changed, 9 insertions(+), 2 deletions(-)
e2ec8a
e2ec8a
diff --git a/meson.build b/meson.build
e2ec8a
index 04331dd41a..a0e7240708 100644
e2ec8a
--- a/meson.build
e2ec8a
+++ b/meson.build
e2ec8a
@@ -425,6 +425,7 @@ decl_headers = '''
e2ec8a
 #include <sys/stat.h>
e2ec8a
 '''
e2ec8a
 # FIXME: key_serial_t is only defined in keyutils.h, this is bound to fail
e2ec8a
+# FIXME: these should use -D_GNU_SOURCE, since that is defined at build time
e2ec8a
 
e2ec8a
 foreach decl : ['char16_t',
e2ec8a
                 'char32_t',
e2ec8a
@@ -439,6 +440,10 @@ foreach decl : ['char16_t',
e2ec8a
         conf.set10('HAVE_' + decl.underscorify().to_upper(), have)
e2ec8a
 endforeach
e2ec8a
 
e2ec8a
+conf.set10('HAVE_STRUCT_STATX_IN_SYS_STAT_H', cc.sizeof('struct statx', prefix : '''
e2ec8a
+#include <sys/stat.h>
e2ec8a
+''', args : '-D_GNU_SOURCE') > 0)
e2ec8a
+
e2ec8a
 foreach decl : [['IFLA_INET6_ADDR_GEN_MODE',         'linux/if_link.h'],
e2ec8a
                 ['IN6_ADDR_GEN_MODE_STABLE_PRIVACY', 'linux/if_link.h'],
e2ec8a
                 ['IFLA_VRF_TABLE',                   'linux/if_link.h'],
e2ec8a
diff --git a/src/basic/missing.h b/src/basic/missing.h
e2ec8a
index 71a07d0574..14ad3d4914 100644
e2ec8a
--- a/src/basic/missing.h
e2ec8a
+++ b/src/basic/missing.h
e2ec8a
@@ -15,7 +15,6 @@
e2ec8a
 #include <linux/neighbour.h>
e2ec8a
 #include <linux/oom.h>
e2ec8a
 #include <linux/rtnetlink.h>
e2ec8a
-#include <linux/stat.h>
e2ec8a
 #include <net/ethernet.h>
e2ec8a
 #include <stdlib.h>
e2ec8a
 #include <sys/resource.h>
e2ec8a
@@ -25,6 +24,10 @@
e2ec8a
 #include <uchar.h>
e2ec8a
 #include <unistd.h>
e2ec8a
 
e2ec8a
+#if !HAVE_STRUCT_STATX_IN_SYS_STAT_H
e2ec8a
+#include <linux/stat.h>
e2ec8a
+#endif
e2ec8a
+
e2ec8a
 #if HAVE_AUDIT
e2ec8a
 #include <libaudit.h>
e2ec8a
 #endif
e2ec8a
diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c
e2ec8a
index c5c55ea846..0ee0979837 100644
e2ec8a
--- a/src/basic/xattr-util.c
e2ec8a
+++ b/src/basic/xattr-util.c
e2ec8a
@@ -2,7 +2,6 @@
e2ec8a
 
e2ec8a
 #include <errno.h>
e2ec8a
 #include <fcntl.h>
e2ec8a
-#include <linux/stat.h>
e2ec8a
 #include <stdint.h>
e2ec8a
 #include <stdlib.h>
e2ec8a
 #include <string.h>