1 #! /usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   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.
   8 #
   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.
  13 #
  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]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 # 
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 # 
  29 # A script to clean up any stray instances of the test service app, if
  30 # any are found still running after a round of svc.startd tests.  We
  31 # note that finding orphaned instances of the the test service app is
  32 # a bug; they should all have been killed by the proper execution of 
  33 # the service's stop method.  Thus, if any such orphaned service app 
  34 # instances are found, we flag an error and return UNRESOLVED.
  35 
  36 # Load the STF library
  37 . ${STF_TOOLS}/include/stf.kshlib
  38 # for find_nontransient_pids
  39 . ${STF_SUITE}/include/gltest.kshlib
  40 
  41 # This is our test service app name
  42 typeset SERVICE_APP=${STF_SUITE}/tests/bin/${STF_EXECUTE_MODE}/service_app
  43 
  44 typeset -i result=0
  45 
  46 # Verify that no instance of ${SERVICE_APP} is currently running
  47 SVC_APP=${SERVICE_APP##*/}
  48 typeset pids=$(find_nontransient_pids ${SVC_APP})
  49 typeset -i num_apps=$?
  50 if [[ $num_apps -eq 0 ]]; then
  51         echo "--INFO: Success
  52         No instance of ${SVC_APP} was found running on the system"
  53         
  54         echo "--RSLT: ${STF_RESULT_NAMES[$STF_PASS]}"
  55         exit $STF_PASS
  56 fi
  57 
  58 # At least one instance of ${SVC_APP} was found
  59 # We consider this an error and set our exit status to UNRESOLVED
  60 result=$STF_UNRESOLVED
  61 echo "--DIAG: error detected
  62         EXPECTED: No instance of ${SVC_APP} is running
  63         RETURNED: $num_apps instance(s) found on system"
  64 
  65 echo "--INFO: logging pargs information about the running processes"
  66 for pid in $pids; do
  67         pargs $pid
  68 done
  69 echo "--INFO: Attempting to kill all ${SVC_APP} processes"
  70 pkill -z $(zonename) ${SVC_APP} >/dev/null 2>&1
  71 
  72 num_apps=$(pgrep -z $(zonename) $SVC_APP 2>/dev/null | wc -l)
  73 [[ $num_apps -ne 0 ]] && {
  74         echo "--DIAG: Fatal error: pkill failed
  75         EXPECTED: All instances of ${SVC_APP} were killed
  76         RETURNED: $num_apps instances are still running"
  77 
  78         # Make one last attempt to kill $SVC_APP.  We don't
  79         # care whether this succeeded or not.
  80         pkill -9 -z $(zonename) $SVC_APP >/dev/null 2>&1
  81 }
  82 
  83 echo "--RSLT: ${STF_RESULT_NAMES[$result]}"
  84 exit $result