2 # Test df's behaviour when the mount list cannot be read.
3 # This test is skipped on systems that lack LD_PRELOAD support; that's fine.
5 # Copyright (C) 2012-2016 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
24 # Protect against inaccessible remote mounts etc.
25 timeout
10 df || skip_
"df fails"
27 grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev
/null \
28 || skip_
"no mntent.h available to confirm the interface"
30 grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev
/null \
31 || skip_
"getmntent is not used on this system"
33 # Simulate "mtab" failure.
34 cat > k.c
<<EOF || framework_failure_
42 #define STREQ(a, b) (strcmp (a, b) == 0)
44 FILE* fopen(const char *path, const char *mode)
46 static FILE* (*fopen_func)(char const *, char const *);
48 /* get reference to original (libc provided) fopen */
51 fopen_func = (FILE*(*)(char const *, char const *))
52 dlsym(RTLD_NEXT, "fopen");
55 fprintf (stderr, "Failed to find fopen()\n");
61 /* Returning ENOENT here will get read_file_system_list()
62 to fall back to using getmntent() below. */
63 if (STREQ (path, "/proc/self/mountinfo"))
69 return fopen_func(path, mode);
72 struct mntent *getmntent (FILE *fp)
74 /* Prove that LD_PRELOAD works. */
78 fclose (fopen ("x", "w"));
81 /* Now simulate the failure. */
87 # Then compile/link it:
88 gcc_shared_ k.c k.so \
89 || framework_failure_
'failed to build shared library'
91 cleanup_
() { unset LD_PRELOAD
; }
93 export LD_PRELOAD
=$LD_PRELOAD:.
/k.so
95 # Test if LD_PRELOAD works:
97 test -f x || skip_
"internal test failure: maybe LD_PRELOAD doesn't work?"
99 # These tests are supposed to succeed:
104 df
--total '.' || fail
=1
106 # These tests are supposed to fail:
107 returns_
1 df || fail
=1
108 returns_
1 df
-i || fail
=1
109 returns_
1 df
-T || fail
=1
110 returns_
1 df
-Ti || fail
=1
111 returns_
1 df
--total || fail
=1
113 returns_
1 df
-a || fail
=1
114 returns_
1 df
-a '.' || fail
=1
116 returns_
1 df
-l || fail
=1
117 returns_
1 df
-l '.' || fail
=1
119 returns_
1 df
-t hello || fail
=1
120 returns_
1 df
-t hello
'.' || fail
=1
122 returns_
1 df
-x hello || fail
=1
123 returns_
1 df
-x hello
'.' || fail
=1