virmockstathelpers: Adapt to musl-1.2.4

With musl-1.2.3: I get the following macros defined (from
$builddir/meson-config.h):

  #define WITH_LSTAT 1
  #define WITH_LSTAT64 1
  #define WITH_LSTAT_DECL 1
  #define WITH_STAT 1
  #define WITH_STAT64 1
  #define WITH_STAT_DECL 1
  #define WITH___LXSTAT 1
  #define WITH___LXSTAT64 1
  #define WITH___XSTAT 1
  #define WITH___XSTAT64 1

which in turn means the virmockstathelpers.c ends up defining:

  MOCK_STAT64
  MOCK_LSTAT64

But with  musl-1.2.4 everything changes and the set of defined
macros gets simplified to:

  #define WITH_LSTAT 1
  #define WITH_LSTAT_DECL 1
  #define WITH_STAT 1
  #define WITH_STAT_DECL 1
  #define WITH___LXSTAT 1
  #define WITH___XSTAT 1

which results in no MOCK_* macros defined in
virmockstathelpers.c, i.e. no stat() mocking, nada. The reason
for this simplification are these musl commits [1][2] which
removed all 64 bit aliases. And that's not what our logic for
deciding what flavor of stat() to mock counted with.

Nevertheless, we do build with Alpine Linux in our CI, so how
come we don't see this problem there? Well, simply because Alpine
Linux maintainers decided to revert the commits [3][4]. But on
distributions that use vanilla musl, this problem can be seen
easily.

1: https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4
2: https://git.musl-libc.org/cgit/musl/commit/?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc
3: https://git.alpinelinux.org/aports/commit/main/musl?id=6a5563fbb45b3d9d60678d7bbf60dbb312a2d481
4: https://git.alpinelinux.org/aports/commit/main/musl?id=a089bd852f8983623fa85e0f5755a3e25bf53c72

Resolves: https://bugs.gentoo.org/906167
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Michal Privoznik 2023-05-15 11:56:51 +02:00
parent 4a681995bc
commit a091edf9db

View File

@ -125,6 +125,16 @@
# endif
#endif
#if !defined(MOCK_STAT) && !defined(MOCK_STAT64) && \
!defined(MOCK___XSTAT) && !defined(MOCK___XSTAT64)
# define MOCK_STAT
#endif
#if !defined(MOCK_LSTAT) && !defined(MOCK_LSTAT64) && \
!defined(MOCK___LXSTAT) && !defined(MOCK___LXSTAT64)
# define MOCK_LSTAT
#endif
#ifdef MOCK_STAT
static int (*real_stat)(const char *path, struct stat *sb);
#endif