Print this page
4360 Fix SMF methods and other scripts which rely on the system shell to use /sbin/sh
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/svc/shell/fs_include.sh
+++ new/usr/src/cmd/svc/shell/fs_include.sh
1 -#!/bin/sh
1 +#!/sbin/sh
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
20 20 # CDDL HEADER END
21 21 #
22 22 #
23 23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 # Use is subject to license terms.
25 25 #
26 26 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
27 27 # All rights reserved.
28 28 #
29 29 #
30 -#ident "%Z%%M% %I% %E% SMI"
31 30
32 31 vfstab=${vfstab:=/etc/vfstab}
33 32
34 33 #
35 34 # readvfstab mount_point
36 35 # -> (special, fsckdev, mountp, fstype, fsckpass, automnt, mntopts)
37 36 #
38 37 # A vfstab-like input stream is scanned for the mount point specified
39 38 # as $1. Returns the fields of vfstab in the following shell
40 39 # variables:
41 40 #
42 41 # special block device
43 42 # fsckdev raw device
44 43 # mountp mount point (must match $1, if found)
45 44 # fstype file system type
46 45 # fsckpass fsck(1M) pass number
47 46 # automnt automount flag (yes or no)
48 47 # mntopts file system-specific mount options.
49 48 #
50 49 # If the mount point can not be found in the standard input stream,
51 50 # then all fields are set to empty values. This function assumes that
52 51 # stdin is already set /etc/vfstab (or other appropriate input
53 52 # stream).
54 53 #
55 54 readvfstab() {
56 55 while read special fsckdev mountp fstype fsckpass automnt mntopts; do
57 56 case "$special" in
58 57 '' ) # Ignore empty lines.
59 58 continue
60 59 ;;
61 60
62 61 '#'* ) # Ignore comment lines.
63 62 continue
64 63 ;;
65 64
66 65 '-') # Ignore "no-action" lines.
67 66 continue
68 67 ;;
69 68 esac
70 69
71 70 [ "x$mountp" = "x$1" ] && break
72 71 done
73 72 }
74 73
75 74 readswapdev() {
76 75 while read special fsckdev mountp fstype fsckpass automnt mntopts; do
77 76 # Ignore comments, empty lines, and no-action lines
78 77 case "$special" in
79 78 '#'* | '' | '-') continue;;
80 79 esac
81 80
82 81 [ "$fstype" != swap ] && continue
83 82
84 83 [ "x$special" = "x$1" ] && break
85 84 done
86 85 }
87 86
88 87 #
89 88 # readmnttab mount_point
90 89 # -> (special, mountp, fstype, mntopts, mnttime)
91 90 #
92 91 # A mnttab-like input stream is scanned for the mount point specified
93 92 # as $1. Returns the fields of mnttab in the following shell
94 93 # variables:
95 94 #
96 95 # special block device
97 96 # mountp mount point (must match $1, if found)
98 97 # fstype file system type
99 98 # mntopts file system-specific mount options.
100 99 # mnttime time at which file system was mounted
101 100 #
102 101 # If the mount point can not be found in the standard input stream,
103 102 # then all fields are set to empty values. This function assumes that
104 103 # stdin is already set to /etc/mnttab (or other appropriate input
105 104 # stream).
106 105 #
107 106 readmnttab() {
108 107 while read special mountp fstype mntopts mnttime; do
109 108 [ "x$mountp" = "x$1" ] && break
110 109 done
111 110 }
112 111
113 112 cecho() {
114 113 echo $*
115 114 echo $* >/dev/msglog
116 115 }
117 116
118 117 #
119 118 # checkmessage raw_device fstype mountpoint
120 119 # checkmessage2 raw_device fstype mountpoint
121 120 #
122 121 # Two simple auxilary routines to the shell function checkfs. Both
123 122 # display instructions for a manual file system check.
124 123 #
125 124 checkmessage() {
126 125 cecho ""
127 126 cecho "WARNING - Unable to repair the $3 filesystem. Run fsck"
128 127 cecho "manually (fsck -F $2 $1)."
129 128 cecho ""
130 129 }
131 130
132 131 checkmessage2() {
133 132 cecho ""
134 133 cecho "WARNING - fatal error from fsck - error $4"
135 134 cecho "Unable to repair the $3 filesystem. Run fsck manually"
136 135 cecho "(fsck -F $2 $1)."
137 136 cecho ""
138 137 }
139 138
140 139 #
141 140 # checkfs raw_device fstype mountpoint
142 141 #
143 142 # Check the file system specified. The return codes from fsck have the
144 143 # following meanings.
145 144 #
146 145 # 0 file system is unmounted and okay
147 146 # 32 file system is unmounted and needs checking (fsck -m only)
148 147 # 33 file system is already mounted
149 148 # 34 cannot stat device
150 149 # 35 modified root or something equally dangerous
151 150 # 36 uncorrectable errors detected - terminate normally (4.1 code 8)
152 151 # 37 a signal was caught during processing (4.1 exit 12)
153 152 # 39 uncorrectable errors detected - terminate rightaway (4.1 code 8)
154 153 # 40 for root, same as 0 (used here to remount root)
155 154 #
156 155 checkfs() {
157 156 # skip checking if the fsckdev is "-"
158 157 [ "x$1" = x- ] && return
159 158
160 159 # if fsck isn't present, it is probably because either the mount of
161 160 # /usr failed or the /usr filesystem is badly damanged. In either
162 161 # case, there is not much to be done automatically. Fail with
163 162 # a message to the user.
164 163 if [ ! -x /usr/sbin/fsck ]; then
165 164 cecho ""
166 165 cecho "WARNING - /usr/sbin/fsck not found. Most likely the"
167 166 cecho "mount of /usr failed or the /usr filesystem is badly"
168 167 cecho "damaged."
169 168 cecho ""
170 169 return 1
171 170 fi
172 171
173 172 # If a filesystem-specific fsck binary is unavailable, then no
174 173 # fsck pass is required.
175 174 [ ! -x /usr/lib/fs/$2/fsck ] && [ ! -x /etc/fs/$2/fsck ] && return
176 175
177 176 /usr/sbin/fsck -F $2 -m $1 >/dev/null 2>&1
178 177
179 178 if [ $? -ne 0 ]; then
180 179 # Determine fsck options by file system type
181 180 case $2 in
182 181 ufs) foptions="-o p"
183 182 ;;
184 183 *) foptions="-y"
185 184 ;;
186 185 esac
187 186
188 187 cecho "The $3 file system ($1) is being checked."
189 188 /usr/sbin/fsck -F $2 $foptions $1
190 189
191 190 case $? in
192 191 0|40) # File system OK
193 192 ;;
194 193
195 194 1|34|36|37|39) # couldn't fix the file system - fail
196 195 checkmessage "$1" "$2" "$3"
197 196 return 1
198 197 ;;
199 198 33) # already mounted
200 199 return 0
201 200 ;;
202 201
203 202 *) # fsck child process killed (+ error code 35)
204 203 checkmessage2 "$1" "$2" "$3" "$?"
205 204 return 1
206 205 ;;
207 206 esac
208 207 fi
209 208
210 209 return 0
211 210 }
212 211
213 212 #
214 213 # checkopt option option-string
215 214 # -> ($option, $otherops)
216 215 #
217 216 # Check to see if a given mount option is present in the comma
218 217 # separated list gotten from vfstab.
219 218 #
220 219 # Returns:
221 220 # ${option} : the option if found the empty string if not found
222 221 # ${otherops} : the option string with the found option deleted
223 222 #
224 223 checkopt() {
225 224 option=
226 225 otherops=
227 226
228 227 [ "x$2" = x- ] && return
229 228
230 229 searchop="$1"
231 230 set -- `IFS=, ; echo $2`
232 231
233 232 while [ $# -gt 0 ]; do
234 233 if [ "x$1" = "x$searchop" ]; then
235 234 option="$1"
236 235 else
237 236 if [ -z "$otherops" ]; then
238 237 otherops="$1"
239 238 else
240 239 otherops="${otherops},$1"
241 240 fi
242 241 fi
243 242 shift
244 243 done
245 244 }
246 245
247 246 #
248 247 # hasopts $opts $allopts
249 248 #
250 249 # Check if all options from the list $opts are present in $allopts.
251 250 # Both $opts and $allopts should be in comma separated format.
252 251 #
253 252 # Return 0 on success, and 1 otherwise.
254 253 #
255 254 hasopts() {
256 255 opts="$1"
257 256 allopts="$2"
258 257
259 258 set -- `IFS=, ; echo $opts`
260 259 while [ $# -gt 0 ]; do
261 260 if [ "$1" != "remount" ]; then
262 261 checkopt $1 $allopts
263 262 #
264 263 # Don't report errors if the filesystem is already
265 264 # read-write when mounting it as read-only.
266 265 #
267 266 [ -z "$option" ] && [ "$1" = "ro" ] && \
268 267 checkopt rw $allopts
269 268 [ -z "$option" ] && return 1
270 269 fi
271 270 shift
272 271 done
273 272 return 0
274 273 }
275 274
276 275 #
277 276 # mounted $path $fsopts $fstype
278 277 #
279 278 # Check whether the specified file system of the given type is currently
280 279 # mounted with all required filesystem options by going through /etc/mnttab
281 280 # in our standard input.
282 281 #
283 282 # Return values:
284 283 # 0 Success.
285 284 # 1 The filesystem is not currently mounted, or mounted without required
286 285 # options, or a filesystem of a different type is mounted instead.
287 286 #
288 287 mounted() {
289 288 path="$1"
290 289 fsopts="$2"
291 290 fstype="$3"
292 291
293 292 while read mntspec mntpath mnttype mntopts on; do
294 293 [ "$mntpath" = "$path" ] || continue
295 294 [ "$fstype" != "-" ] && [ "$mnttype" != "$fstype" ] && return 1
296 295 [ "$fsopts" = "-" ] && return 0
297 296 hasopts $fsopts $mntopts && return 0
298 297 done
299 298 return 1
300 299 }
301 300
302 301 #
303 302 # mountfs $opts $path $type $fsopts $special
304 303 #
305 304 # Try to mount a filesystem. If failed, display our standard error
306 305 # message on the console and print more details about what happened
307 306 # to our service log.
308 307 #
309 308 # Arguments:
310 309 # $opts - options for mount(1M) [optional]
311 310 # $path - mount point
312 311 # $type - file system type [optional]
313 312 # $fsopts - file system specific options (-o) [optional]
314 313 # $special - device on which the file system resides [optional]
315 314 #
316 315 # Return codes:
317 316 # 0 - success.
318 317 # otherwise - error code returned by mount(1M).
319 318 #
320 319 mountfs() {
321 320 opts="$1"
322 321 path="$2"
323 322 special="$5"
324 323
325 324 #
326 325 # Take care of optional arguments
327 326 #
328 327 [ "$opts" = "-" ] && opts=""
329 328 [ "$special" = "-" ] && special=""
330 329 [ "$3" = "-" ] && type=""
331 330 [ "$3" != "-" ] && type="-F $3"
332 331 [ "$4" = "-" ] && fsopts=""
333 332 [ "$4" != "-" ] && fsopts="-o $4"
334 333
335 334 cmd="/sbin/mount $opts $type $fsopts $special $path"
336 335 msg=`$cmd 2>&1`
337 336 err=$?
338 337
339 338 [ $err = 0 ] && return 0
340 339
341 340 #
342 341 # If the specified file system is already mounted with all
343 342 # required options, and has the same filesystem type
344 343 # then ignore errors and return success
345 344 #
346 345 mounted $path $4 $3 < /etc/mnttab && return 0
347 346
348 347 echo "ERROR: $SMF_FMRI failed to mount $path "\
349 348 "(see 'svcs -x' for details)" > /dev/msglog
350 349 echo "ERROR: $cmd failed, err=$err"
351 350 echo $msg
352 351 return $err
353 352 }
↓ open down ↓ |
313 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX