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/smf_include.sh
+++ new/usr/src/cmd/svc/shell/smf_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 #
20 20 # CDDL HEADER END
21 21 #
22 22 #
23 23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 # Use is subject to license terms.
25 25 #
26 26
27 27 smf_present () {
28 28 [ -r /etc/svc/volatile/repository_door ] && \
29 29 [ ! -f /etc/svc/volatile/repository_door ]
30 30 }
31 31
32 32 smf_clear_env () {
33 33 unset \
34 34 SMF_FMRI \
35 35 SMF_METHOD \
36 36 SMF_RESTARTER \
37 37 SMF_ZONENAME
38 38 }
39 39
40 40 # smf_console
41 41 #
42 42 # Use as "echo message 2>&1 | smf_console". If SMF_MSGLOG_REDIRECT is
43 43 # unset, message will be displayed to console. SMF_MSGLOG_REDIRECT is
44 44 # reserved for future use.
45 45 #
46 46 smf_console () {
47 47 /usr/bin/tee ${SMF_MSGLOG_REDIRECT:-/dev/msglog}
48 48 }
49 49
50 50 # smf_zonename
51 51 #
52 52 # Prints the name of this zone.
53 53
54 54 smf_zonename() {
55 55 echo "${SMF_ZONENAME:=`/sbin/zonename`}"
56 56 }
57 57
58 58 # smf_is_globalzone
59 59 #
60 60 # Returns zero (success) if this is the global zone. 1 otherwise.
61 61 #
62 62 smf_is_globalzone() {
63 63 [ "${SMF_ZONENAME:=`/sbin/zonename`}" = "global" ] && return 0
64 64 return 1
65 65 }
66 66
67 67 # smf_is_nonglobalzone
68 68 #
69 69 # Returns zero (success) if this is not the global zone. 1 otherwise.
70 70 #
71 71 smf_is_nonglobalzone() {
72 72 [ "${SMF_ZONENAME:=`/sbin/zonename`}" != "global" ] && return 0
73 73 return 1
74 74 }
75 75
76 76 # smf_configure_ip
77 77 #
78 78 # Returns zero (success) if this zone needs IP to be configured i.e.
79 79 # the global zone or has an exclusive stack. 1 otherwise.
80 80 #
81 81 smf_configure_ip() {
82 82 [ "${SMF_ZONENAME:=`/sbin/zonename`}" = "global" -o \
83 83 `/sbin/zonename -t` = exclusive ] && return 0
84 84 return 1
85 85 }
86 86
87 87 # smf_dont_configure_ip
88 88 #
89 89 # Inverse of smf_configure_ip
90 90 #
91 91 smf_dont_configure_ip() {
92 92 [ "${SMF_ZONENAME:=`/sbin/zonename`}" != "global" -a \
93 93 `/sbin/zonename -t` = shared ] && return 0
94 94 return 1
95 95 }
96 96
97 97 # smf_dont_configure_vt
98 98 #
99 99 # Returns zero (success) if vt functionality is not to be configured,
100 100 # 1 otherwise.
101 101 #
102 102 smf_dont_configure_vt() {
103 103 [ "${SMF_ZONENAME:=`/sbin/zonename`}" != "global" ] && return 0
104 104 /usr/lib/vtinfo > /dev/null 2>&1
105 105 return $?
106 106 }
107 107
108 108 # smf_is_system_labeled
109 109 #
110 110 # Returns zero (success) if system is labeled (aka Trusted Extensions).
111 111 # 1 otherwise.
112 112 #
113 113 smf_is_system_labeled() {
114 114 [ ! -x /bin/plabel ] && return 1
115 115 /bin/plabel > /dev/null 2>&1
116 116 return $?
117 117 }
118 118
119 119 # smf_netstrategy
120 120 # -> (_INIT_NET_IF, _INIT_NET_STRATEGY)
121 121 #
122 122 # Sets _INIT_NET_IF to the name for the network-booted
123 123 # interface if we are booting from the network. _INIT_NET_STRATEGY is
124 124 # assigned the value of the current network configuration strategy.
125 125 # Valid values for _INIT_NET_STRATEGY are "none", "dhcp", and "rarp".
126 126 #
127 127 # The network boot strategy for a zone is always "none".
128 128 #
129 129 smf_netstrategy () {
130 130 if smf_is_nonglobalzone; then
131 131 _INIT_NET_STRATEGY="none" export _INIT_NET_STRATEGY
132 132 return 0
133 133 fi
134 134
135 135 set -- `/sbin/netstrategy`
136 136 if [ $? -eq 0 ]; then
137 137 [ "$1" = "nfs" -o "$1" = "cachefs" ] && \
138 138 _INIT_NET_IF="$2" export _INIT_NET_IF
139 139 _INIT_NET_STRATEGY="$3" export _INIT_NET_STRATEGY
140 140 else
141 141 return 1
142 142 fi
143 143 }
144 144
145 145 #
146 146 # smf_kill_contract CONTRACT SIGNAL WAIT TIMEOUT
147 147 #
148 148 # To be called from stop methods of non-transient services.
149 149 # Sends SIGNAL to the service contract CONTRACT. If the
150 150 # WAIT argument is non-zero, smf_kill_contract will wait
151 151 # until the contract is empty before returning, or until
152 152 # TIMEOUT expires.
153 153 #
154 154 # Example, send SIGTERM to contract 200:
155 155 #
156 156 # smf_kill_contract 200 TERM
157 157 #
158 158 # Since killing a contract with pkill(1) is not atomic,
159 159 # smf_kill_contract will continue to send SIGNAL to CONTRACT
160 160 # every second until the contract is empty. This will catch
161 161 # races between fork(2) and pkill(1).
162 162 #
163 163 # Note that time in this routine is tracked (after being input
164 164 # via TIMEOUT) in 10ths of a second. This is because we want
165 165 # to sleep for short periods of time, and expr(1) is too dumb
166 166 # to do non-integer math.
167 167 #
168 168 # Returns 1 if the contract is invalid.
169 169 # Returns 2 if WAIT is "1", TIMEOUT is > 0, and TIMEOUT expires.
170 170 # Returns 0 on success.
171 171 #
172 172 smf_kill_contract() {
173 173
174 174 time_waited=0
175 175 time_to_wait=$4
176 176
177 177 [ -z "$time_to_wait" ] && time_to_wait=0
178 178
179 179 # convert to 10ths.
180 180 time_to_wait=`/usr/bin/expr $time_to_wait '*' 10`
181 181
182 182 # Verify contract id is valid using pgrep
183 183 /usr/bin/pgrep -c $1 > /dev/null 2>&1
184 184 ret=$?
185 185 if [ $ret -gt 1 ] ; then
186 186 echo "Error, invalid contract \"$1\"" >&2
187 187 return 1
188 188 fi
189 189
190 190 # Return if contract is already empty.
191 191 [ $ret -eq 1 ] && return 0
192 192
193 193 # Kill contract.
194 194 /usr/bin/pkill -$2 -c $1
195 195 if [ $? -gt 1 ] ; then
196 196 echo "Error, could not kill contract \"$1\"" >&2
197 197 return 1
198 198 fi
199 199
200 200 # Return if WAIT is not set or is "0"
201 201 [ -z "$3" ] && return 0
202 202 [ "$3" -eq 0 ] && return 0
203 203
204 204 # If contract does not empty, keep killing the contract to catch
205 205 # any child processes missed because they were forking
206 206 /usr/bin/pgrep -c $1 > /dev/null 2>&1
207 207 while [ $? -eq 0 ] ; do
208 208 # Return 2 if TIMEOUT was passed, and it has expired
209 209 [ "$time_to_wait" -gt 0 -a $time_waited -ge $time_to_wait ] && \
210 210 return 2
211 211
212 212 #
213 213 # At five second intervals, issue the kill again. Note that
214 214 # the sleep time constant (in tenths) must be a factor of 50
215 215 # for the remainder trick to work. i.e. sleeping 2 tenths is
216 216 # fine, but 27 tenths is not.
217 217 #
218 218 remainder=`/usr/bin/expr $time_waited % 50`
219 219 if [ $time_waited -gt 0 -a $remainder -eq 0 ]; then
220 220 /usr/bin/pkill -$2 -c $1
221 221 fi
222 222
223 223 # Wait two tenths, and go again.
224 224 /usr/bin/sleep 0.2
225 225 time_waited=`/usr/bin/expr $time_waited + 2`
226 226 /usr/bin/pgrep -c $1 > /dev/null 2>&1
227 227 done
228 228
229 229 return 0
230 230 }
231 231
232 232 #
233 233 # smf(5) method and monitor exit status definitions
234 234 # SMF_EXIT_ERR_OTHER, although not defined, encompasses all non-zero
235 235 # exit status values.
236 236 #
237 237 SMF_EXIT_OK=0
238 238 SMF_EXIT_ERR_FATAL=95
239 239 SMF_EXIT_ERR_CONFIG=96
240 240 SMF_EXIT_MON_DEGRADE=97
241 241 SMF_EXIT_MON_OFFLINE=98
242 242 SMF_EXIT_ERR_NOSMF=99
243 243 SMF_EXIT_ERR_PERM=100
↓ open down ↓ |
232 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX