Print this page
7290 ZFS test suite needs to control what utilities it can run
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/test/zfs-tests/cmd/scripts/zfstest.ksh
+++ new/usr/src/test/zfs-tests/cmd/scripts/zfstest.ksh
1 1 #!/usr/bin/ksh
2 2
3 3 #
4 4 # This file and its contents are supplied under the terms of the
|
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
5 5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 6 # You may only use this file in accordance with the terms of version
7 7 # 1.0 of the CDDL.
8 8 #
9 9 # A full copy of the text of the CDDL should have accompanied this
10 10 # source. A copy of the CDDL is also available via the Internet at
11 11 # http://www.illumos.org/license/CDDL.
12 12 #
13 13
14 14 #
15 -# Copyright (c) 2012, 2015 by Delphix. All rights reserved.
15 +# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
16 16 # Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
17 17 # Copyright 2016 Nexenta Systems, Inc.
18 18 #
19 19
20 +export PATH="/usr/bin"
20 21 export NOINUSE_CHECK=1
21 22 export STF_SUITE="/opt/zfs-tests"
22 23 export STF_TOOLS="/opt/test-runner/stf"
24 +export PATHDIR=""
23 25 runner="/opt/test-runner/bin/run"
24 26 auto_detect=false
25 27
26 28 function fail
27 29 {
28 30 echo $1
29 31 exit ${2:-1}
30 32 }
31 33
32 34 function find_disks
33 35 {
34 - typeset all_disks=$(echo '' | sudo -k /usr/sbin/format | awk \
36 + typeset all_disks=$(echo '' | sudo -k format | awk \
35 37 '/c[0-9]/ {print $2}')
36 - typeset used_disks=$(/sbin/zpool status | awk \
38 + typeset used_disks=$(zpool status | awk \
37 39 '/c[0-9]*t[0-9a-f]*d[0-9]/ {print $1}' | sed 's/s[0-9]//g')
38 40
39 41 typeset disk used avail_disks
40 42 for disk in $all_disks; do
41 43 for used in $used_disks; do
42 44 [[ "$disk" = "$used" ]] && continue 2
43 45 done
44 46 [[ -n $avail_disks ]] && avail_disks="$avail_disks $disk"
45 47 [[ -z $avail_disks ]] && avail_disks="$disk"
46 48 done
47 49
48 50 echo $avail_disks
49 51 }
50 52
51 53 function find_rpool
52 54 {
53 - typeset ds=$(/usr/sbin/mount | awk '/^\/ / {print $3}')
55 + typeset ds=$(mount | awk '/^\/ / {print $3}')
54 56 echo ${ds%%/*}
55 57 }
56 58
57 59 function find_runfile
58 60 {
59 61 typeset distro=
60 62 if [[ -d /opt/delphix && -h /etc/delphix/version ]]; then
61 63 distro=delphix
62 64 elif [[ 0 -ne $(grep -c OpenIndiana /etc/release 2>/dev/null) ]]; then
63 65 distro=openindiana
64 66 elif [[ 0 -ne $(grep -c OmniOS /etc/release 2>/dev/null) ]]; then
65 67 distro=omnios
66 68 fi
67 69
68 70 [[ -n $distro ]] && echo $STF_SUITE/runfiles/$distro.run
69 71 }
70 72
71 73 function verify_id
72 74 {
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
73 75 [[ $(id -u) = "0" ]] && fail "This script must not be run as root."
74 76
75 77 sudo -k -n id >/dev/null 2>&1
76 78 [[ $? -eq 0 ]] || fail "User must be able to sudo without a password."
77 79 }
78 80
79 81 function verify_disks
80 82 {
81 83 typeset disk
82 84 for disk in $DISKS; do
83 - sudo -k /usr/sbin/prtvtoc /dev/rdsk/${disk}s0 >/dev/null 2>&1
85 + sudo -k prtvtoc /dev/rdsk/${disk}s0 >/dev/null 2>&1
84 86 [[ $? -eq 0 ]] || return 1
85 87 done
86 88 return 0
87 89 }
88 90
89 -verify_id
91 +function create_links
92 +{
93 + typeset dir=$1
94 + typeset file_list=$2
90 95
96 + [[ -n $PATHDIR ]] || fail "PATHDIR wasn't correctly set"
97 +
98 + for i in $file_list; do
99 + [[ ! -e $PATHDIR/$i ]] || fail "$i already exists"
100 + ln -s $dir/$i $PATHDIR/$i || fail "Couldn't link $i"
101 + done
102 +
103 +}
104 +
105 +function constrain_path
106 +{
107 + . $STF_SUITE/include/commands.cfg
108 +
109 + PATHDIR=$(/usr/bin/mktemp -d /var/tmp/constrained_path.XXXX)
110 + chmod 755 $PATHDIR || fail "Couldn't chmod $PATHDIR"
111 +
112 + create_links "/usr/bin" "$USR_BIN_FILES"
113 + create_links "/usr/sbin" "$USR_SBIN_FILES"
114 + create_links "/sbin" "$SBIN_FILES"
115 + create_links "/opt/zfs-tests/bin" "$ZFSTEST_FILES"
116 +
117 + # Special case links
118 + ln -s /usr/gnu/bin/dd $PATHDIR/gnu_dd
119 +}
120 +
121 +constrain_path
122 +export PATH=$PATHDIR
123 +
124 +verify_id
91 125 while getopts ac:q c; do
92 126 case $c in
93 127 'a')
94 128 auto_detect=true
95 129 ;;
96 130 'c')
97 131 runfile=$OPTARG
98 132 [[ -f $runfile ]] || fail "Cannot read file: $runfile"
99 133 ;;
100 134 'q')
101 135 quiet='-q'
102 136 ;;
103 137 esac
104 138 done
105 139 shift $((OPTIND - 1))
106 140
107 141 # If the user specified -a, then use free disks, otherwise use those in $DISKS.
108 142 if $auto_detect; then
109 143 export DISKS=$(find_disks)
110 144 elif [[ -z $DISKS ]]; then
111 145 fail "\$DISKS not set in env, and -a not specified."
112 146 else
113 147 verify_disks || fail "Couldn't verify all the disks in \$DISKS"
114 148 fi
115 149
116 150 # Add the root pool to $KEEP according to its contents.
117 151 # It's ok to list it twice.
118 152 if [[ -z $KEEP ]]; then
119 153 KEEP="$(find_rpool)"
120 154 else
121 155 KEEP+=" $(find_rpool)"
122 156 fi
123 157
124 158 export __ZFS_POOL_EXCLUDE="$KEEP"
125 159 export KEEP="^$(echo $KEEP | sed 's/ /$|^/g')\$"
|
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
126 160
127 161 [[ -z $runfile ]] && runfile=$(find_runfile)
128 162 [[ -z $runfile ]] && fail "Couldn't determine distro"
129 163
130 164 . $STF_SUITE/include/default.cfg
131 165
132 166 num_disks=$(echo $DISKS | awk '{print NF}')
133 167 [[ $num_disks -lt 3 ]] && fail "Not enough disks to run ZFS Test Suite"
134 168
135 169 # Ensure user has only basic privileges.
136 -/usr/bin/ppriv -s EIP=basic -e $runner $quiet -c $runfile
170 +ppriv -s EIP=basic -e $runner $quiet -c $runfile
171 +ret=$?
137 172
138 -exit $?
173 +rm -rf $PATHDIR || fail "Couldn't remove $PATHDIR"
174 +
175 +exit $ret
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX