Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | From 75720bff62a84896e9a0654afc7cf9408cf89a38 Mon Sep 17 00:00:00 2001 |
| 2 | From: Filipe Brandenburger <filbranden@google.com> |
| 3 | Date: Sun, 15 Jul 2018 22:43:35 -0700 |
| 4 | Subject: [PATCH] build-sys: Detect whether struct statx is defined in |
| 5 | sys/stat.h |
| 6 | MIME-Version: 1.0 |
| 7 | Content-Type: text/plain; charset=UTF-8 |
| 8 | Content-Transfer-Encoding: 8bit |
| 9 | |
| 10 | Starting with glibc 2.27.9000-36.fc29, include file sys/stat.h will have a |
| 11 | definition for struct statx, in which case include file linux/stat.h should be |
| 12 | avoided, in order to prevent a duplicate definition. |
| 13 | |
| 14 | In file included from ../src/basic/missing.h:18, |
| 15 | from ../src/basic/util.h:28, |
| 16 | from ../src/basic/hashmap.h:10, |
| 17 | from ../src/shared/bus-util.h:12, |
| 18 | from ../src/libsystemd/sd-bus/bus-creds.c:11: |
| 19 | /usr/include/linux/stat.h:99:8: error: redefinition of ‘struct statx’ |
| 20 | struct statx { |
| 21 | ^~~~~ |
| 22 | In file included from /usr/include/sys/stat.h:446, |
| 23 | from ../src/basic/util.h:19, |
| 24 | from ../src/basic/hashmap.h:10, |
| 25 | from ../src/shared/bus-util.h:12, |
| 26 | from ../src/libsystemd/sd-bus/bus-creds.c:11: |
| 27 | /usr/include/bits/statx.h:36:8: note: originally defined here |
| 28 | struct statx |
| 29 | ^~~~~ |
| 30 | |
| 31 | Extend our meson.build to look for struct statx when only sys/stat.h is |
| 32 | included and, in that case, do not include linux/stat.h anymore. |
| 33 | |
| 34 | Tested that systemd builds correctly when using a glibc version that includes a |
| 35 | definition for struct statx. |
| 36 | |
| 37 | glibc Fedora RPM update: |
| 38 | https://src.fedoraproject.org/rpms/glibc/c/28cb5d31fc1e5887912283c889689c47076278ae |
| 39 | |
| 40 | glibc upstream commit: |
| 41 | https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=fd70af45528d59a00eb3190ef6706cb299488fcd |
| 42 | --- |
| 43 | |
| 44 | Upstream-Status: Pending |
| 45 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 46 | |
| 47 | meson.build | 5 +++++ |
| 48 | src/basic/missing.h | 5 ++++- |
| 49 | src/basic/xattr-util.c | 1 - |
| 50 | 3 files changed, 9 insertions(+), 2 deletions(-) |
| 51 | |
| 52 | Index: git/meson.build |
| 53 | =================================================================== |
| 54 | --- git.orig/meson.build |
| 55 | +++ git/meson.build |
| 56 | @@ -432,6 +432,7 @@ decl_headers = ''' |
| 57 | #include <sys/stat.h> |
| 58 | ''' |
| 59 | # FIXME: key_serial_t is only defined in keyutils.h, this is bound to fail |
| 60 | +# FIXME: these should use -D_GNU_SOURCE, since that is defined at build time |
| 61 | |
| 62 | foreach decl : ['char16_t', |
| 63 | 'char32_t', |
| 64 | @@ -446,6 +447,10 @@ foreach decl : ['char16_t', |
| 65 | conf.set10('HAVE_' + decl.underscorify().to_upper(), have) |
| 66 | endforeach |
| 67 | |
| 68 | +conf.set10('HAVE_STRUCT_STATX_IN_SYS_STAT_H', cc.sizeof('struct statx', prefix : ''' |
| 69 | +#include <sys/stat.h> |
| 70 | +''', args : '-D_GNU_SOURCE') > 0) |
| 71 | + |
| 72 | foreach decl : [['IFLA_INET6_ADDR_GEN_MODE', 'linux/if_link.h'], |
| 73 | ['IN6_ADDR_GEN_MODE_STABLE_PRIVACY', 'linux/if_link.h'], |
| 74 | ['IFLA_VRF_TABLE', 'linux/if_link.h'], |
| 75 | Index: git/src/basic/missing.h |
| 76 | =================================================================== |
| 77 | --- git.orig/src/basic/missing.h |
| 78 | +++ git/src/basic/missing.h |
| 79 | @@ -15,7 +15,6 @@ |
| 80 | #include <linux/neighbour.h> |
| 81 | #include <linux/oom.h> |
| 82 | #include <linux/rtnetlink.h> |
| 83 | -#include <linux/stat.h> |
| 84 | #include <net/ethernet.h> |
| 85 | #include <stdlib.h> |
| 86 | #include <sys/resource.h> |
| 87 | @@ -25,6 +24,10 @@ |
| 88 | #include <uchar.h> |
| 89 | #include <unistd.h> |
| 90 | |
| 91 | +#if !HAVE_STRUCT_STATX_IN_SYS_STAT_H |
| 92 | +#include <linux/stat.h> |
| 93 | +#endif |
| 94 | + |
| 95 | #if HAVE_AUDIT |
| 96 | #include <libaudit.h> |
| 97 | #endif |
| 98 | Index: git/src/basic/xattr-util.c |
| 99 | =================================================================== |
| 100 | --- git.orig/src/basic/xattr-util.c |
| 101 | +++ git/src/basic/xattr-util.c |
| 102 | @@ -2,7 +2,6 @@ |
| 103 | |
| 104 | #include <errno.h> |
| 105 | #include <fcntl.h> |
| 106 | -#include <linux/stat.h> |
| 107 | #include <stdint.h> |
| 108 | #include <stdlib.h> |
| 109 | #include <string.h> |