2 # SPDX-License-Identifier: GPL-2.0
3 # description: Test file and directory ownership changes for eventfs
4 # requires: "[gid=<gid>]":README
6 original_group
=`stat -c "%g" .`
7 original_owner
=`stat -c "%u" .`
9 local mount_point
=$
(get_mount_point
)
11 mount_options
=$
(get_mnt_options
"$mount_point")
13 # find another owner and group that is not the original
14 other_group
=`tac /etc/group | grep -v ":$original_group:" | head -1 | cut -d: -f3`
15 other_owner
=`tac /etc/passwd | grep -v ":$original_owner:" | head -1 | cut -d: -f3`
17 # Remove any group ownership already
18 new_options
=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"`
20 if [ "$new_options" = "$mount_options" ]; then
21 new_options
="$mount_options,gid=$other_group"
22 mount_options
="$mount_options,gid=$original_group"
25 canary
="events/timer events/timer/timer_cancel events/timer/timer_cancel/format"
31 owner
=`stat -c "%u" $file`
32 group
=`stat -c "%g" $file`
34 echo "testing $file $owner=$original_owner and $group=$test_group"
35 if [ $owner -ne $original_owner ]; then
38 if [ $group -ne $test_group ]; then
42 # Note, the remount does not update ownership so test going to and from owner
43 echo "test owner $file to $other_owner"
44 chown
$other_owner $file
45 owner
=`stat -c "%u" $file`
46 if [ $owner -ne $other_owner ]; then
50 chown
$original_owner $file
51 owner
=`stat -c "%u" $file`
52 if [ $owner -ne $original_owner ]; then
59 for d
in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
60 test "$d" $other_group
63 chgrp
$original_group events
64 test "events" $original_group
65 for d
in "." "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
66 test "$d" $other_group
69 chgrp
$original_group events
/sched
70 test "events/sched" $original_group
71 for d
in "." "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
72 test "$d" $other_group
75 chgrp
$original_group events
/sched
/sched_switch
76 test "events/sched/sched_switch" $original_group
77 for d
in "." "events/sched/sched_switch/enable" $canary; do
78 test "$d" $other_group
81 chgrp
$original_group events
/sched
/sched_switch
/enable
82 test "events/sched/sched_switch/enable" $original_group
83 for d
in "." $canary; do
84 test "$d" $other_group
88 # Run the tests twice as leftovers can cause issues
91 echo "Running iteration $loop"
93 mount
-o remount
,"$new_options" .
97 mount
-o remount
,"$mount_options" .
99 for d
in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
100 test "$d" $original_group
103 # check instances as well
105 chgrp
$other_group instances
107 instance
="$(mktemp -u test-XXXXXX)"
109 mkdir instances
/$instance
111 cd instances
/$instance
117 rmdir instances
/$instance
119 chgrp
$original_group instances