2 # Test df's behavior 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-2024 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 <https://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_GETMNTENT 1' $CONFIG_HEADER > /dev
/null \
28 || skip_
"getmntent is not used on this system"
30 # Simulate "mtab" failure.
31 cat > k.c
<<EOF || framework_failure_
42 #define STREQ(a, b) (strcmp (a, b) == 0)
44 int open(const char *path, int flags, ...)
46 static int (*open_func)(const char *, int, ...);
48 /* get reference to original (libc provided) open */
51 open_func = (int(*)(const char *, int, ...))
52 dlsym(RTLD_NEXT, "open");
55 fprintf (stderr, "Failed to find open()\n");
63 mode_t mode = (sizeof (mode_t) < sizeof (int)
65 : va_arg (ap, mode_t));
68 /* Returning ENOENT here will get read_file_system_list()
69 to fall back to using getmntent() below. */
70 if (STREQ (path, "/proc/self/mountinfo"))
76 return open_func(path, flags, mode);
79 struct mntent *getmntent (FILE *fp)
81 /* Prove that LD_PRELOAD works. */
85 fclose (fopen ("x", "w"));
88 /* Now simulate the failure. */
94 # Then compile/link it:
95 gcc_shared_ k.c k.so \
96 || framework_failure_
'failed to build shared library'
98 cleanup_
() { unset LD_PRELOAD
; }
100 export LD_PRELOAD
=$LD_PRELOAD:.
/k.so
102 # Test if LD_PRELOAD works:
104 test -f x || skip_
"internal test failure: maybe LD_PRELOAD doesn't work?"
106 # These tests are supposed to succeed:
111 df
--total '.' || fail
=1
113 # These tests are supposed to fail:
114 returns_
1 df || fail
=1
115 returns_
1 df
-i || fail
=1
116 returns_
1 df
-T || fail
=1
117 returns_
1 df
-Ti || fail
=1
118 returns_
1 df
--total || fail
=1
120 returns_
1 df
-a || fail
=1
121 returns_
1 df
-a '.' || fail
=1
123 returns_
1 df
-l || fail
=1
124 returns_
1 df
-l '.' || fail
=1
126 returns_
1 df
-t hello || fail
=1
127 returns_
1 df
-t hello
'.' || fail
=1
129 returns_
1 df
-x hello || fail
=1
130 returns_
1 df
-x hello
'.' || fail
=1