From 88a03548248cac37662f5044df5c35152c5eb937 Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Thu, 30 Apr 2015 11:33:38 +0100 Subject: [PATCH] tests: don't skip df tests with /proc/self/mountinfo * tests/df/no-mtab-status.sh: getmntent is no longer called when /proc/self/mountinfo is present, thus causing the test to be skipped. Therefore wrap fopen() to ignore mountinfo, and use the test genmntent table instead. * tests/df/skip-duplicates.sh: Likewise. --- tests/df/no-mtab-status.sh | 36 ++++++++++++++++++++++++++++------- tests/df/skip-duplicates.sh | 38 +++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/tests/df/no-mtab-status.sh b/tests/df/no-mtab-status.sh index 49d12558da..58a1852a24 100755 --- a/tests/df/no-mtab-status.sh +++ b/tests/df/no-mtab-status.sh @@ -32,20 +32,42 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \ # Simulate "mtab" failure. cat > k.c < #include #include -#include "$CONFIG_HEADER" +#include +#include -#ifdef MOUNTED_PROC_MOUNTINFO -# include -struct libmnt_table *mnt_new_table_from_file(const char *filename) +#define STREQ(a, b) (strcmp (a, b) == 0) + +FILE* fopen(const char *path, const char *mode) { - /* Returning NULL here will get read_file_system_list() + static FILE* (*fopen_func)(char const *, char const *); + + /* get reference to original (libc provided) fopen */ + if (!fopen_func) + { + fopen_func = (FILE*(*)(char const *, char const *)) + dlsym(RTLD_NEXT, "fopen"); + if (!fopen_func) + { + fprintf (stderr, "Failed to find fopen()\n"); + errno = ESRCH; + return NULL; + } + } + + /* Returning ENOENT here will get read_file_system_list() to fall back to using getmntent() below. */ - return NULL; + if (STREQ (path, "/proc/self/mountinfo")) + { + errno = ENOENT; + return NULL; + } + else + return fopen_func(path, mode); } -#endif struct mntent *getmntent (FILE *fp) { diff --git a/tests/df/skip-duplicates.sh b/tests/df/skip-duplicates.sh index 2560708496..c13787665c 100755 --- a/tests/df/skip-duplicates.sh +++ b/tests/df/skip-duplicates.sh @@ -41,21 +41,43 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \ # Simulate an mtab file to test various cases. cat > k.c < #include -#include +#include #include -#include "$CONFIG_HEADER" +#include +#include + +#define STREQ(a, b) (strcmp (a, b) == 0) -#ifdef MOUNTED_PROC_MOUNTINFO -# include -struct libmnt_table *mnt_new_table_from_file(const char *filename) +FILE* fopen(const char *path, const char *mode) { - /* Returning NULL here will get read_file_system_list() + static FILE* (*fopen_func)(char const *, char const *); + + /* get reference to original (libc provided) fopen */ + if (!fopen_func) + { + fopen_func = (FILE*(*)(char const *, char const *)) + dlsym(RTLD_NEXT, "fopen"); + if (!fopen_func) + { + fprintf (stderr, "Failed to find fopen()\n"); + errno = ESRCH; + return NULL; + } + } + + /* Returning ENOENT here will get read_file_system_list() to fall back to using getmntent() below. */ - return NULL; + if (STREQ (path, "/proc/self/mountinfo")) + { + errno = ENOENT; + return NULL; + } + else + return fopen_func(path, mode); } -#endif #define STREQ(a, b) (strcmp (a, b) == 0) -- 2.47.2