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 # start __stf_assertion__
  30 #
  31 # ASSERTION: methods_016
  32 # DESCRIPTION:
  33 #  Service with multiple child processes.
  34 #  If a service instance in the online state dumps core than svc.startd
  35 #  should attempt to restart the service.
  36 #
  37 # end __stf_assertion__
  38 #
  39 
  40 . ${STF_TOOLS}/include/stf.kshlib
  41 . ${STF_SUITE}/include/gltest.kshlib
  42 . ${STF_SUITE}/include/svc.startd_config.kshlib
  43 . ${STF_SUITE}/tests/include/svc.startd_fileops.kshlib
  44 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
  45 
  46 typeset service_setup=0
  47 function cleanup {
  48         [[ "$pps" = "disabled" ]] && coreadm -d proc-setid 2>/dev/null
  49         common_cleanup
  50 }
  51 
  52 trap cleanup 0 1 2 15
  53 
  54 readonly ME=$(whence -p ${0})
  55 readonly MYLOC=$(dirname ${ME})
  56 
  57 DATA=$MYLOC
  58 
  59 registration_template=$DATA/service_016.xml
  60 
  61 extract_assertion_info $ME
  62 
  63 # make sure that the svc.startd is running
  64 verify_daemon
  65 if [ $? -ne 0 ]; then
  66         print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
  67         print -- "  continue"
  68         exit $STF_UNRESOLVED
  69 fi
  70 
  71 # Make sure the environment is clean - the test service isn't running
  72 print -- "--INFO: Cleanup any old $test_FMRI state"
  73 service_cleanup $test_service
  74 rm -f $service_state
  75 if [ $? -ne 0 ]; then
  76         print -- "--DIAG: $assertion: unable to clean up any pre-existing state"
  77         exit $STF_UNRESOLVED
  78 fi
  79 
  80 pps=$(env LC_ALL=C coreadm | grep 'per-process setid' | awk '{print $NF }')
  81 
  82 if [ -z "$pps" ]; then
  83         print -- "--DIAG: could not get state from coreadm"
  84         exit $STF_UNRESOLVED
  85 fi
  86 
  87 if [ "$pps" = "disabled" ]; then
  88         print -- "--INFO: Enabling per-process setid coredumps"
  89         coreadm -e proc-setid
  90         if [ $? -ne 0 ]; then
  91                 print -- "--DIAG: Could not enable per-process setid coredumps"
  92                 exit $STF_UNRESOLVED
  93         fi
  94 fi
  95 
  96 print -- "--INFO: generating manifest for importation into repository"
  97 manifest_generate $registration_template \
  98         TEST_SERVICE=$test_service \
  99         TEST_INSTANCE=$test_instance \
 100         SERVICE_APP=$service_app \
 101         LOGFILE=$service_log \
 102         STATEFILE=$service_state \
 103         > $registration_file
 104 
 105 print -- "--INFO: Importing service into repository"
 106 manifest_purgemd5 $registration_file
 107 svccfg -v import $registration_file >$svccfg_errfile 2>&1
 108 if [ $? -ne 0 ]; then
 109         print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
 110         print -- "  error messages from svccfg: \"$(cat $svccfg_errfile)\""
 111         exit $STF_UNRESOLVED
 112 fi
 113 service_setup=1
 114 
 115 print -- "--INFO: enabling $test_FMRI"
 116 svcadm enable $test_FMRI
 117 if [ $? -ne 0 ]; then
 118         print -- "--DIAG: $assertion: enable command of $test_FMRI failed"
 119         exit $STF_FAIL
 120 fi
 121 
 122 print -- "--INFO: waiting for execution of start method"
 123 service_wait_method $test_FMRI start
 124 if [ $? -ne 0 ]; then
 125         print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
 126         exit $STF_UNRESOLVED
 127 fi
 128 
 129 print -- "--INFO: Validating service reaches online mode"
 130 service_wait_state $test_FMRI online
 131 if [ $? -ne 0 ]; then
 132         print -- "--DIAG: $assertion: Service $test_FMRI didn't"
 133         print -- "  transition to online mode"
 134         exit $STF_FAIL
 135 fi
 136 
 137 print -- "--INFO: get the services to generate core files into log dir"
 138 PIDS=`service_getpids -s $test_service -i $test_instance -f $service_state`
 139 print -- "--INFO: child pids are: $PIDS"
 140 coreadm -p "$RUNDIR/core.%p" $PIDS
 141 typeset pid1=
 142 typeset pid2=
 143 
 144 echo $PIDS | read pid1 pid2
 145 
 146 if [ -z "$pid2" ]; then
 147         print -- "--DIAG: there should have been 2 child processes"
 148         exit $STF_FAIL
 149 fi
 150 
 151 print -- "--INFO: make the service core dump... use dummy method"
 152 $service_app -s $test_service -i $test_instance \
 153         -m trigger -r "triggerservicesegv 1"
 154 
 155 print -- "--INFO: checking for core file from pid $pid2"
 156 file_wait_exist $RUNDIR/core.$pid2
 157 if [ $? -ne 0 ]; then
 158         print -- "--DIAG: core file for service not found"
 159         exit $STF_FAIL
 160 fi
 161 # blow it away... we actually don't care about the contents
 162 rm -f $RUNDIR/core.$pid2
 163 
 164 print -- "--INFO: Waiting for service's start method"
 165 service_wait_method $test_FMRI start
 166 if [ $? -ne 0 ]; then
 167         print -- "--DIAG: $assertion: didn't issue start method"
 168         exit $STF_FAIL
 169 fi
 170 
 171 print -- "--INFO: verifying that pid $pid1 is not executing"
 172 kill -0 $pid1 2>/dev/null
 173 if [ $? -eq 0 ]; then
 174         print -- "--DIAG: $assertion: startd didn't kill other service process"
 175         exit $STF_FAIL
 176 fi
 177 
 178 print -- "--INFO: Waiting for service to reach online state"
 179 service_wait_state $test_FMRI online
 180 if [ $? -ne 0 ]; then
 181         print -- "--DIAG: $assertion: service $test_FMRI didn't"
 182         print -- "  come online"
 183         exit $STF_FAIL
 184 fi
 185 
 186 print -- "--INFO: Cleaning up service"
 187 cleanup
 188 
 189 exit $STF_PASS