misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 093
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
4 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
5 #
6 # FS QA Test No. 093
7 #
8 # Test clearing of capabilities on write.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # FAILure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 # get standard environment, filters and checks
19 . ./common/rc
20 . ./common/filter
21 . ./common/attr
22
23 _cleanup()
24 {
25     [ -n "$TEST_DIR" ] && rm -f $file
26 }
27
28 filefilter()
29 {
30     sed -e "s#$file#file#"
31 }
32
33 # real QA test starts here
34 _supported_fs generic
35
36 _require_test
37 _require_attrs security
38 _require_user
39 _require_test_program "writemod"
40 _require_command "$SETCAP_PROG" "setcap"
41 _require_command "$GETCAP_PROG" "getcap"
42
43 rm -f $seqres.full
44
45 echo "QA output created by $seq"
46 echo ""
47 file=$TEST_DIR/$seq.file
48
49 rm -f $file
50 touch $file
51
52 echo "**** Verifying that appending to file clears capabilities ****"
53 $SETCAP_PROG cap_chown+ep $file
54 _getcap $file | filefilter
55 echo data1 >> $file
56 cat $file
57 _getcap $file | filefilter
58 echo
59
60 echo "**** Verifying that appending to file doesn't clear other xattrs ****"
61 $SETCAP_PROG cap_chown+ep $file
62 $SETFATTR_PROG -n trusted.name -v value $file
63 echo data2 >> $file
64 cat $file
65 _getfattr -m '^trusted\.*' --absolute-names $file | filefilter
66
67 echo "**** Verifying that chmod doesn't affect open file descriptors ****"
68 rm -f $file
69 touch $file
70 chown $qa_user $file
71 chmod ugo+w $TEST_DIR
72 # don't use $here/src/writemod, as we're running it as a regular user, and
73 # $here may contain path component that a regular user doesn't have search
74 # permission
75 su $qa_user -c "src/writemod $file" | filefilter
76 cat $file
77
78 # success, all done
79 status=0
80 exit