5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 # Copyright 2015 Nexenta Systems, Inc. All rights reserved.
29 [ -r /etc
/svc
/volatile
/repository_door
] && \
30 [ ! -f /etc
/svc
/volatile
/repository_door
]
43 # Use as "echo message 2>&1 | smf_console". If SMF_MSGLOG_REDIRECT is
44 # unset, message will be displayed to console. SMF_MSGLOG_REDIRECT is
45 # reserved for future use.
48 /usr
/bin
/tee ${SMF_MSGLOG_REDIRECT:-/dev/msglog}
53 # Prints the name of this zone.
56 echo "${SMF_ZONENAME:=`/sbin/zonename`}"
61 # Returns zero (success) if this is the global zone. 1 otherwise.
64 [ "${SMF_ZONENAME:=`/sbin/zonename`}" = "global" ] && return 0
68 # smf_is_nonglobalzone
70 # Returns zero (success) if this is not the global zone. 1 otherwise.
72 smf_is_nonglobalzone
() {
73 [ "${SMF_ZONENAME:=`/sbin/zonename`}" != "global" ] && return 0
79 # Returns zero (success) if this zone needs IP to be configured i.e.
80 # the global zone or has an exclusive stack. 1 otherwise.
83 [ "${SMF_ZONENAME:=`/sbin/zonename`}" = "global" -o \
84 `/sbin/zonename -t` = exclusive
] && return 0
88 # smf_dont_configure_ip
90 # Inverse of smf_configure_ip
92 smf_dont_configure_ip
() {
93 [ "${SMF_ZONENAME:=`/sbin/zonename`}" != "global" -a \
94 `/sbin/zonename -t` = shared
] && return 0
98 # smf_dont_configure_vt
100 # Returns zero (success) if vt functionality is not to be configured,
103 smf_dont_configure_vt
() {
104 [ "${SMF_ZONENAME:=`/sbin/zonename`}" != "global" ] && return 0
105 /usr
/lib
/vtinfo
> /dev
/null
2>&1
109 # smf_is_system_labeled
111 # Returns zero (success) if system is labeled (aka Trusted Extensions).
114 smf_is_system_labeled
() {
115 [ ! -x /bin
/plabel
] && return 1
116 /bin
/plabel
> /dev
/null
2>&1
121 # -> (_INIT_NET_IF, _INIT_NET_STRATEGY)
123 # Sets _INIT_NET_IF to the name for the network-booted
124 # interface if we are booting from the network. _INIT_NET_STRATEGY is
125 # assigned the value of the current network configuration strategy.
126 # Valid values for _INIT_NET_STRATEGY are "none", "dhcp", and "rarp".
128 # The network boot strategy for a zone is always "none".
131 if smf_is_nonglobalzone
; then
132 _INIT_NET_STRATEGY
="none" export _INIT_NET_STRATEGY
136 set -- `/sbin/netstrategy`
137 if [ $?
-eq 0 ]; then
138 [ "$1" = "nfs" ] && \
139 _INIT_NET_IF
="$2" export _INIT_NET_IF
140 _INIT_NET_STRATEGY
="$3" export _INIT_NET_STRATEGY
147 # smf_kill_contract CONTRACT SIGNAL WAIT TIMEOUT
149 # To be called from stop methods of non-transient services.
150 # Sends SIGNAL to the service contract CONTRACT. If the
151 # WAIT argument is non-zero, smf_kill_contract will wait
152 # until the contract is empty before returning, or until
155 # Example, send SIGTERM to contract 200:
157 # smf_kill_contract 200 TERM
159 # Since killing a contract with pkill(1) is not atomic,
160 # smf_kill_contract will continue to send SIGNAL to CONTRACT
161 # every second until the contract is empty. This will catch
162 # races between fork(2) and pkill(1).
164 # Note that time in this routine is tracked (after being input
165 # via TIMEOUT) in 10ths of a second. This is because we want
166 # to sleep for short periods of time, and expr(1) is too dumb
167 # to do non-integer math.
169 # Returns 1 if the contract is invalid.
170 # Returns 2 if WAIT is "1", TIMEOUT is > 0, and TIMEOUT expires.
171 # Returns 0 on success.
173 smf_kill_contract
() {
178 [ -z "$time_to_wait" ] && time_to_wait
=0
181 time_to_wait
=`/usr/bin/expr $time_to_wait '*' 10`
183 # Verify contract id is valid using pgrep
184 /usr
/bin
/pgrep
-c $1 > /dev
/null
2>&1
186 if [ $ret -gt 1 ] ; then
187 echo "Error, invalid contract \"$1\"" >&2
191 # Return if contract is already empty.
192 [ $ret -eq 1 ] && return 0
195 /usr
/bin
/pkill
-$2 -c $1
196 if [ $?
-gt 1 ] ; then
197 echo "Error, could not kill contract \"$1\"" >&2
201 # Return if WAIT is not set or is "0"
202 [ -z "$3" ] && return 0
203 [ "$3" -eq 0 ] && return 0
205 # If contract does not empty, keep killing the contract to catch
206 # any child processes missed because they were forking
207 /usr
/bin
/pgrep
-c $1 > /dev
/null
2>&1
208 while [ $?
-eq 0 ] ; do
209 # Return 2 if TIMEOUT was passed, and it has expired
210 [ "$time_to_wait" -gt 0 -a $time_waited -ge $time_to_wait ] && \
214 # At five second intervals, issue the kill again. Note that
215 # the sleep time constant (in tenths) must be a factor of 50
216 # for the remainder trick to work. i.e. sleeping 2 tenths is
217 # fine, but 27 tenths is not.
219 remainder
=`/usr/bin/expr $time_waited % 50`
220 if [ $time_waited -gt 0 -a $remainder -eq 0 ]; then
221 /usr
/bin
/pkill
-$2 -c $1
224 # Wait two tenths, and go again.
226 time_waited
=`/usr/bin/expr $time_waited + 2`
227 /usr
/bin
/pgrep
-c $1 > /dev
/null
2>&1
234 # smf(5) method and monitor exit status definitions
235 # SMF_EXIT_ERR_OTHER, although not defined, encompasses all non-zero
236 # exit status values.
239 SMF_EXIT_ERR_FATAL
=95
240 SMF_EXIT_ERR_CONFIG
=96
241 SMF_EXIT_MON_DEGRADE
=97
242 SMF_EXIT_MON_OFFLINE
=98
243 SMF_EXIT_ERR_NOSMF
=99
244 SMF_EXIT_ERR_PERM
=100