tests: avoid false failure in tail inotify test
[coreutils.git] / tests / df / no-mtab-status.sh
blob82ee8f6a20a0bf7bf5c777b821cd8f16512562ce
1 #!/bin/sh
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
21 print_ver_ df
22 require_gcc_shared_
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_
35 #define _GNU_SOURCE
36 #include <stdio.h>
37 #include <errno.h>
38 #include <mntent.h>
39 #include <string.h>
40 #include <dlfcn.h>
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 */
49 if (!fopen_func)
51 fopen_func = (FILE*(*)(char const *, char const *))
52 dlsym(RTLD_NEXT, "fopen");
53 if (!fopen_func)
55 fprintf (stderr, "Failed to find fopen()\n");
56 errno = ESRCH;
57 return NULL;
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"))
65 errno = ENOENT;
66 return NULL;
68 else
69 return fopen_func(path, mode);
72 struct mntent *getmntent (FILE *fp)
74 /* Prove that LD_PRELOAD works. */
75 static int done = 0;
76 if (!done)
78 fclose (fopen ("x", "w"));
79 ++done;
81 /* Now simulate the failure. */
82 errno = ENOENT;
83 return NULL;
85 EOF
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:
96 df 2>/dev/null
97 test -f x || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?"
99 # These tests are supposed to succeed:
100 df '.' || fail=1
101 df -i '.' || fail=1
102 df -T '.' || fail=1
103 df -Ti '.' || fail=1
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
125 Exit $fail