bdaeb732a64748ba691b7a29ff334fe4a67a1c8f
[platform/upstream/coreutils.git] / tests / chmod / no-x
1 #!/bin/sh
2 # Make sure chmod gives the right diagnostic for a readable,
3 # but inaccessible directory.
4
5 if test "$VERBOSE" = yes; then
6   set -x
7   chmod --version
8 fi
9
10 . $srcdir/../lang-default
11 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
12
13 pwd=`pwd`
14 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
15 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
16 trap '(exit $?); exit $?' 1 2 13 15
17
18 framework_failure=0
19 mkdir -p $tmp || framework_failure=1
20 cd $tmp || framework_failure=1
21 mkdir -p d/no-x/y || framework_failure=1
22 chmod u=rw d/no-x || framework_failure=1
23
24 if test $framework_failure = 1; then
25   echo "$0: failure in testing framework" 1>&2
26   (exit 1); exit 1
27 fi
28
29 fail=0
30
31 # This must exit nonzero.
32 chmod -R o=r d >/dev/null 2>out && fail=1
33
34 cat <<\EOF > exp
35 chmod: `d/no-x': Permission denied
36 EOF
37
38 # With native fdopendir, du uses a different code path.
39 cat <<\EOF > exp-native-fdopendir
40 chmod: cannot access `d/no-x/y': Permission denied
41 chmod: fts_read failed: Permission denied
42 EOF
43
44 if cmp out exp >/dev/null 2>&1; then
45   :
46 else
47   if cmp out exp-native-fdopendir; then
48     :
49   else
50     fail=1
51   fi
52 fi
53
54 test $fail = 1 && diff out exp 2> /dev/null
55
56 mkdir -p a/b
57 cd a
58 # This will fail with ``chmod: fts_read failed: Permission denied''
59 chmod a-x . b 2> /dev/null && fail=1
60 # chmod must exit with status 1.
61 # Due to a bug in coreutils-5.93's fts.c, chmod would provoke
62 # an abort (exit with status 134) on recent glibc-based systems.
63 test $? = 1 || fail=1
64
65 (exit $fail); exit $fail