Two df(1) tests were skipped:
no-mtab-status.sh: skipped test: failed to build mntent shared library
SKIP: tests/df/no-mtab-status.sh
skip-duplicates.sh: skipped test: failed to build mntent shared library
SKIP: tests/df/skip-duplicates.sh
The attached patch fixes that build failure.
FWIW, but those 2 tests still get skipped - at least here on my
openSUSE:Tumbleweed system:
+ test -f x
+ skip_ 'internal test failure: maybe LD_PRELOAD doesn'\''t work?'
I noticed that the open() function is not called (anymore?),
but instead it would work again when substituting fopen().
See attached 'tests-df-LD_PRELOAD-fopen-not-open.diff' file.
Do you see the same?
Have a nice day,
Berny
From 1d14835c93b94abe9870ac003e6a80994bb476fc Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email protected]>
Date: Sat, 1 Nov 2025 20:32:21 +0100
Subject: [PATCH] tests: avoid skipping by fixing build of shared libraries
Two df(1) tests were skipped (since commit ee367bd38dac), because
the build of the shared library in those tests failed.
+ gcc -Wall -shared --std=gnu99 -fPIC -O2 k.c -o k.so -ldl
k.c: In function 'open':
k.c:37:7: error: implicit declaration of function 'streq'; did you \
mean 'strsep'? [-Wimplicit-function-declaration]
37 | if (streq (path, "/proc/self/mountinfo"))
| ^~~~~
| strsep
Gnulib streq is not available in the tests.
* tests/df/no-mtab-status.sh: Replace "streq" by "0==strcmp" in the
shared library source.
* tests/df/skip-duplicates.sh: Likewise.
---
tests/df/no-mtab-status.sh | 3 ++-
tests/df/skip-duplicates.sh | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/tests/df/no-mtab-status.sh b/tests/df/no-mtab-status.sh
index 0c2e8982d..135462393 100755
--- a/tests/df/no-mtab-status.sh
+++ b/tests/df/no-mtab-status.sh
@@ -28,7 +28,8 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \
|| skip_ "getmntent is not used on this system"
# Simulate "mtab" failure.
-cat > k.c <<EOF || framework_failure_
+# Replace gnulib streq as that is not available here.
+sed 's/streq/0==str''cmp/' > k.c <<EOF || framework_failure_
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
diff --git a/tests/df/skip-duplicates.sh b/tests/df/skip-duplicates.sh
index f97f794f5..c839f4e19 100755
--- a/tests/df/skip-duplicates.sh
+++ b/tests/df/skip-duplicates.sh
@@ -38,7 +38,8 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \
|| skip_ "getmntent is not used on this system"
# Simulate an mtab file to test various cases.
-cat > k.c <<EOF || framework_failure_
+# Replace gnulib streq as that is not available here.
+sed 's/streq/0==str''cmp/' > k.c <<EOF || framework_failure_
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
--
2.51.1
diff --git a/tests/df/no-mtab-status.sh b/tests/df/no-mtab-status.sh
index 135462393..6b87b1eba 100755
--- a/tests/df/no-mtab-status.sh
+++ b/tests/df/no-mtab-status.sh
@@ -28,8 +28,8 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \
|| skip_ "getmntent is not used on this system"
# Simulate "mtab" failure.
-# Replace gnulib streq as that is not available here.
-sed 's/streq/0==str''cmp/' > k.c <<EOF || framework_failure_
+# Replace gnulib streq and C23 nullptr as that are not available here.
+sed 's/streq/0==str''cmp/; s/nullptr/NU''LL/' > k.c <<EOF || framework_failure_
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
@@ -40,39 +40,33 @@ sed 's/streq/0==str''cmp/' > k.c <<EOF || framework_failure_
#include <stdarg.h>
#include <dlfcn.h>
-int open(const char *path, int flags, ...)
+static FILE* (*fopen_func)(const char *, const char *);
+
+FILE* fopen(const char *path, const char *mode)
{
- static int (*open_func)(const char *, int, ...);
- /* get reference to original (libc provided) open */
- if (!open_func)
+ /* get reference to original (libc provided) fopen */
+ if (!fopen_func)
{
- open_func = (int(*)(const char *, int, ...))
- dlsym(RTLD_NEXT, "open");
- if (!open_func)
+ fopen_func = (FILE*(*)(const char *, const char *))
+ dlsym(RTLD_NEXT, "fopen");
+ if (!fopen_func)
{
- fprintf (stderr, "Failed to find open()\n");
+ fprintf (stderr, "Failed to find fopen()\n");
errno = ESRCH;
- return -1;
+ return nullptr;
}
}
- va_list ap;
- va_start (ap, flags);
- mode_t mode = (sizeof (mode_t) < sizeof (int)
- ? va_arg (ap, int)
- : va_arg (ap, mode_t));
- va_end (ap);
-
/* Returning ENOENT here will get read_file_system_list()
to fall back to using getmntent() below. */
if (streq (path, "/proc/self/mountinfo"))
{
errno = ENOENT;
- return -1;
+ return nullptr;
}
- else
- return open_func(path, flags, mode);
+
+ return fopen_func(path, mode);
}
struct mntent *getmntent (FILE *fp)
@@ -81,12 +75,12 @@ struct mntent *getmntent (FILE *fp)
static int done = 0;
if (!done)
{
- fclose (fopen ("x", "w"));
+ fclose (fopen_func ("x", "w"));
++done;
}
/* Now simulate the failure. */
errno = ENOENT;
- return NULL;
+ return nullptr;
}
EOF
@@ -99,7 +93,7 @@ cleanup_() { unset LD_PRELOAD; }
export LD_PRELOAD=$LD_PRELOAD:./k.so
# Test if LD_PRELOAD works:
-df 2>/dev/null
+df
test -f x || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?"
# These tests are supposed to succeed:
diff --git a/tests/df/skip-duplicates.sh b/tests/df/skip-duplicates.sh
index c839f4e19..caa8b1634 100755
--- a/tests/df/skip-duplicates.sh
+++ b/tests/df/skip-duplicates.sh
@@ -38,8 +38,8 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \
|| skip_ "getmntent is not used on this system"
# Simulate an mtab file to test various cases.
-# Replace gnulib streq as that is not available here.
-sed 's/streq/0==str''cmp/' > k.c <<EOF || framework_failure_
+# Replace gnulib streq and C23 nullptr as that are not available here.
+sed 's/streq/0==str''cmp/; s/nullptr/NU''LL/' > k.c <<EOF || framework_failure_
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
@@ -50,39 +50,33 @@ sed 's/streq/0==str''cmp/' > k.c <<EOF || framework_failure_
#include <stdarg.h>
#include <dlfcn.h>
-int open(const char *path, int flags, ...)
+static FILE* (*fopen_func)(const char *, const char *);
+
+FILE* fopen(const char *path, const char *mode)
{
- static int (*open_func)(const char *, int, ...);
- /* get reference to original (libc provided) open */
- if (!open_func)
+ /* get reference to original (libc provided) fopen */
+ if (!fopen_func)
{
- open_func = (int(*)(const char *, int, ...))
- dlsym(RTLD_NEXT, "open");
- if (!open_func)
+ fopen_func = (FILE*(*)(const char *, const char *))
+ dlsym(RTLD_NEXT, "fopen");
+ if (!fopen_func)
{
- fprintf (stderr, "Failed to find open()\n");
+ fprintf (stderr, "Failed to find fopen()\n");
errno = ESRCH;
- return -1;
+ return nullptr;
}
}
- va_list ap;
- va_start (ap, flags);
- mode_t mode = (sizeof (mode_t) < sizeof (int)
- ? va_arg (ap, int)
- : va_arg (ap, mode_t));
- va_end (ap);
-
/* Returning ENOENT here will get read_file_system_list()
to fall back to using getmntent() below. */
if (streq (path, "/proc/self/mountinfo"))
{
errno = ENOENT;
- return -1;
+ return nullptr;
}
- else
- return open_func(path, flags, mode);
+
+ return fopen_func(path, mode);
}
struct mntent *getmntent (FILE *fp)
@@ -94,7 +88,7 @@ struct mntent *getmntent (FILE *fp)
/* Prove that LD_PRELOAD works. */
if (!done)
{
- fclose (fopen ("x", "w"));
+ fclose (fopen_func ("x", "w"));
++done;
}