0003-build-sys-Detect-whether-struct-statx-is-defined-in-.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. From ebe5606eadb1241796ba9747d8e357bd6b3e912e 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. Starting with glibc 2.27.9000-36.fc29, include file sys/stat.h will have a
  10. definition for struct statx, in which case include file linux/stat.h should be
  11. avoided, in order to prevent a duplicate definition.
  12. In file included from ../src/basic/missing.h:18,
  13. from ../src/basic/util.h:28,
  14. from ../src/basic/hashmap.h:10,
  15. from ../src/shared/bus-util.h:12,
  16. from ../src/libsystemd/sd-bus/bus-creds.c:11:
  17. /usr/include/linux/stat.h:99:8: error: redefinition of ‘struct statx’
  18. struct statx {
  19. ^~~~~
  20. In file included from /usr/include/sys/stat.h:446,
  21. from ../src/basic/util.h:19,
  22. from ../src/basic/hashmap.h:10,
  23. from ../src/shared/bus-util.h:12,
  24. from ../src/libsystemd/sd-bus/bus-creds.c:11:
  25. /usr/include/bits/statx.h:36:8: note: originally defined here
  26. struct statx
  27. ^~~~~
  28. Extend our meson.build to look for struct statx when only sys/stat.h is
  29. included and, in that case, do not include linux/stat.h anymore.
  30. Tested that systemd builds correctly when using a glibc version that includes a
  31. definition for struct statx.
  32. glibc Fedora RPM update:
  33. https://src.fedoraproject.org/rpms/glibc/c/28cb5d31fc1e5887912283c889689c47076278ae
  34. glibc upstream commit:
  35. https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=fd70af45528d59a00eb3190ef6706cb299488fcd
  36. (cherry picked from commit 75720bff62a84896e9a0654afc7cf9408cf89a38)
  37. Signed-off-by: Romain Naour <romain.naour@gmail.com>
  38. ---
  39. meson.build | 5 +++++
  40. src/basic/missing.h | 5 ++++-
  41. src/basic/xattr-util.c | 1 -
  42. 3 files changed, 9 insertions(+), 2 deletions(-)
  43. diff --git a/meson.build b/meson.build
  44. index 04331dd41..a0e724070 100644
  45. --- a/meson.build
  46. +++ b/meson.build
  47. @@ -425,6 +425,7 @@ decl_headers = '''
  48. #include <sys/stat.h>
  49. '''
  50. # FIXME: key_serial_t is only defined in keyutils.h, this is bound to fail
  51. +# FIXME: these should use -D_GNU_SOURCE, since that is defined at build time
  52. foreach decl : ['char16_t',
  53. 'char32_t',
  54. @@ -439,6 +440,10 @@ foreach decl : ['char16_t',
  55. conf.set10('HAVE_' + decl.underscorify().to_upper(), have)
  56. endforeach
  57. +conf.set10('HAVE_STRUCT_STATX_IN_SYS_STAT_H', cc.sizeof('struct statx', prefix : '''
  58. +#include <sys/stat.h>
  59. +''', args : '-D_GNU_SOURCE') > 0)
  60. +
  61. foreach decl : [['IFLA_INET6_ADDR_GEN_MODE', 'linux/if_link.h'],
  62. ['IN6_ADDR_GEN_MODE_STABLE_PRIVACY', 'linux/if_link.h'],
  63. ['IFLA_VRF_TABLE', 'linux/if_link.h'],
  64. diff --git a/src/basic/missing.h b/src/basic/missing.h
  65. index 71a07d057..14ad3d491 100644
  66. --- a/src/basic/missing.h
  67. +++ b/src/basic/missing.h
  68. @@ -15,7 +15,6 @@
  69. #include <linux/neighbour.h>
  70. #include <linux/oom.h>
  71. #include <linux/rtnetlink.h>
  72. -#include <linux/stat.h>
  73. #include <net/ethernet.h>
  74. #include <stdlib.h>
  75. #include <sys/resource.h>
  76. @@ -25,6 +24,10 @@
  77. #include <uchar.h>
  78. #include <unistd.h>
  79. +#if !HAVE_STRUCT_STATX_IN_SYS_STAT_H
  80. +#include <linux/stat.h>
  81. +#endif
  82. +
  83. #if HAVE_AUDIT
  84. #include <libaudit.h>
  85. #endif
  86. diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c
  87. index c5c55ea84..0ee097983 100644
  88. --- a/src/basic/xattr-util.c
  89. +++ b/src/basic/xattr-util.c
  90. @@ -2,7 +2,6 @@
  91. #include <errno.h>
  92. #include <fcntl.h>
  93. -#include <linux/stat.h>
  94. #include <stdint.h>
  95. #include <stdlib.h>
  96. #include <string.h>
  97. --
  98. 2.14.4