]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: don't skip df tests with /proc/self/mountinfo
authorPádraig Brady <P@draigBrady.com>
Thu, 30 Apr 2015 10:33:38 +0000 (11:33 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 30 Apr 2015 17:24:47 +0000 (18:24 +0100)
* 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
tests/df/skip-duplicates.sh

index 49d12558dab0afbb5ad8c16a8bc8f43a7e5dcfe7..58a1852a2440e10692467d0b8b3bc6d7e3b25947 100755 (executable)
@@ -32,20 +32,42 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \
 
 # Simulate "mtab" failure.
 cat > k.c <<EOF || framework_failure_
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <errno.h>
 #include <mntent.h>
-#include "$CONFIG_HEADER"
+#include <string.h>
+#include <dlfcn.h>
 
-#ifdef MOUNTED_PROC_MOUNTINFO
-# include <libmount/libmount.h>
-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)
 {
index 256070849693d4545786a76d70509cff2e1b7b36..c13787665c4309055a9066743f426a101da3e23c 100755 (executable)
@@ -41,21 +41,43 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \
 
 # Simulate an mtab file to test various cases.
 cat > k.c <<EOF || framework_failure_
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <errno.h>
 #include <mntent.h>
-#include "$CONFIG_HEADER"
+#include <string.h>
+#include <dlfcn.h>
+
+#define STREQ(a, b) (strcmp (a, b) == 0)
 
-#ifdef MOUNTED_PROC_MOUNTINFO
-# include <libmount/libmount.h>
-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)