Print this page
6805730 some simple changes would make 'init 5' much faster
6809492 startd shouldn't let hung subprocesses impede shutdown

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/svc/shell/smf_include.sh
          +++ new/usr/src/cmd/svc/shell/smf_include.sh
↓ open down ↓ 12 lines elided ↑ open up ↑
  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      -# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
       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 \
↓ open down ↓ 119 lines elided ↑ open up ↑
 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 +#   Note that time in this routine is tracked (after being input
      164 +#   via TIMEOUT) in 10ths of a second.  This is because we want
      165 +#   to sleep for short periods of time, and expr(1) is too dumb
      166 +#   to do non-integer math.
      167 +#
 163  168  #   Returns 1 if the contract is invalid.
 164  169  #   Returns 2 if WAIT is "1", TIMEOUT is > 0, and TIMEOUT expires.
 165  170  #   Returns 0 on success.
 166  171  #
 167  172  smf_kill_contract() {
 168  173  
 169  174          time_waited=0
 170  175          time_to_wait=$4
 171  176  
 172  177          [ -z "$time_to_wait" ] && time_to_wait=0
 173  178  
      179 +        # convert to 10ths.
      180 +        time_to_wait=`expr $time_to_wait * 10`
      181 +
 174  182          # Verify contract id is valid using pgrep
 175  183          /usr/bin/pgrep -c $1 > /dev/null 2>&1
 176  184          ret=$?
 177  185          if [ $ret -gt 1 ] ; then
 178  186                  echo "Error, invalid contract \"$1\"" >&2
 179  187                  return 1
 180  188          fi
 181  189  
 182  190          # Return if contract is already empty.
 183  191          [ $ret -eq 1 ] && return 0
↓ open down ↓ 4 lines elided ↑ open up ↑
 188  196                  echo "Error, could not kill contract \"$1\"" >&2
 189  197                  return 1
 190  198          fi
 191  199  
 192  200          # Return if WAIT is not set or is "0"
 193  201          [ -z "$3" ] && return 0
 194  202          [ "$3" -eq 0 ] && return 0
 195  203   
 196  204          # If contract does not empty, keep killing the contract to catch
 197  205          # any child processes missed because they were forking
 198      -        /usr/bin/sleep 5
 199  206          /usr/bin/pgrep -c $1 > /dev/null 2>&1
 200  207          while [ $? -eq 0 ] ; do
 201      -                
 202      -                time_waited=`/usr/bin/expr $time_waited + 5`
 203      -                
 204      -                # Return  if TIMEOUT was passed, and it has expired
      208 +                # Return 2 if TIMEOUT was passed, and it has expired
 205  209                  [ "$time_to_wait" -gt 0 -a $time_waited -ge $time_to_wait ] && \
 206  210                      return 2
 207      -                /usr/bin/pkill -$2 -c $1
 208      -                /usr/bin/sleep 5
      211 +
      212 +                #
      213 +                # At five second intervals, issue the kill again.  Note that
      214 +                # the sleep time constant (in tenths) must be a factor of 50
      215 +                # for the remainder trick to work.  i.e. sleeping 2 tenths is
      216 +                # fine, but 27 tenths is not.
      217 +                #
      218 +                remainder=`/usr/bin/expr $time_waited % 50`
      219 +                if [ $time_waited -gt 0 -a $remainder -eq 0 ]; then
      220 +                        /usr/bin/pkill -$2 -c $1
      221 +                fi
      222 +
      223 +                # Wait two tenths, and go again.
      224 +                /usr/bin/sleep 0.2
      225 +                time_waited=`/usr/bin/expr $time_waited + 2`
 209  226                  /usr/bin/pgrep -c $1 > /dev/null 2>&1
 210  227          done
 211  228  
 212  229          return 0
 213  230  }
 214  231  
 215  232  #
 216  233  # smf(5) method and monitor exit status definitions
 217  234  #   SMF_EXIT_ERR_OTHER, although not defined, encompasses all non-zero
 218  235  #   exit status values.
 219  236  #
 220  237  SMF_EXIT_OK=0
 221  238  SMF_EXIT_ERR_FATAL=95
 222  239  SMF_EXIT_ERR_CONFIG=96
 223  240  SMF_EXIT_MON_DEGRADE=97
 224  241  SMF_EXIT_MON_OFFLINE=98
 225  242  SMF_EXIT_ERR_NOSMF=99
 226  243  SMF_EXIT_ERR_PERM=100
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX