daandemeyer / rpms / systemd

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